If you're using rails and have an integer column in database that you want to increment or decrement, rails provides a nice abstraction for you to use. Normally you'd have do something like this:
update_attributes(:credits => credits + 1)
Then you can call it like:
With the increment and decrement you can do it this way:
@user.decrement(:credits, 2) # decrease credits by 2
It just saves setting up the method and allows you to pass an integer to increment by!
I just discovered a neat method in rails called
uniq_by. ( http://apidock.com/rails/Array/uniq_by )
It allows you to get a unique set of results from an active record
Ruby provides a way to get unique results from an array like so:
a = [1, 2, 3, 3, 4]
a.uniq # results [1, 2, 3, 4]
But if you have an active record relation, the normal
uniq won't work.
Say you have a list of stores and you want to find their location, but
you only want 1 location from each store/company. You can use:
And that will give you a nice unique Array from an AR relation!
Several monts ago, John Nunemaker bloged "Stop Googling". It was
about reading the code in an open source project oppsed to Googleing it.
He was a bit funstrated at someone who Googled, polled friends, and
basically searched everywhere besides the source to look for an answer
for their problem.
Today I found out the hard way how right he was. I was trying to access
the object info passed along to a
delayed_job record. I googled for 30
or 45 minutes trying to find an answer and couldn't get any bites. I
knew the handler field had the info I needed, but it was a string. I
also knew that somehow that info had to be extracted when my job was
processed. Finally on a whim, I looked to the source code. In the
second file I opened, I found a method called
@payload_object ||= deserialize(self['handler'])
I saw object, deserialize, and handler. That's all I needed to know.
It was exactly what I wanted. It took less than a minute. I tried it
out and that was it.
That's when I remembered John's blog. Note to self: if a quick google
search doesn't display the obvious answer...LOOK AT THE
Ever since I started learning Ruby On Rails several years ago, I’ve been
using git. Git is a cool tool you can use for version control, or in
some cases, simple incremental backups. It basically keeps track of
your code and file changes, you commit/save the changes and can revert
back, review history and do all sorts of cool stuff. It additionally
will allow you to setup a remote repository to push changes to. That’s
where this article comes in.
Using git in rails is really a must, but in the static world, FTP mostly
I’m really tired of using FTP. I probably hit Command + Shift + Upload
200 times a day. Sometimes I edit files very quickly and hop from file
directory. How can I remember which files to FTP? It can be as simple
as “git push” and only my changes are updated.
First off, requirements:
- web server with shell access
- web server with git installed
- local machine with a terminal
- local machine with git installed
- local machine to test (if you can’t run your code on your local
machine or local server, it doesn’t make much sense to setup git...it
would be painful to add, commit, push every tiny change)
Take care of the server side first. ssh into your web server and find a
place outside your public folder. For example, a cpanel server is
/home/account_name/public_html. I’d store it in
mkdir account_name.git && cd account_name.git
git init --bare
Now we’ll tell git where to store the actual files:
git config core.worktree /home/account_name/public_html
git config core.bare false
git config receive.denycurrentbranch ignore
Now we have to tell git what to do after we push changes. Create and
open a new file:
In this file place this code:
#tell git to copy over the files
git checkout -f
#change ownership of files so your web server can serve them (I’m logging in as root so it may not be necessary if you logging in as account_name
chown -R account_name:account_name /home/account_name/public_html/*
Note: This file (post-receive) needs to be executable. To be sure:
chmod 755 hooks/post-receive
Navigate to the directory where your website code lives. If you haven’t already setup git:
git add .
git commit -m ‘initial commit’
Now link up the remote repository:
git remote add origin ssh://email@example.com/home/account_name/account_name.git
Now it’s time for the magic:
git push origin master
Your website should now be live. You can now make changes locally, test
and then push. Example:
#...make some changes to your code
# test them (this could be a visual QA test or automated test)
git add .
git commit -m ‘my first changes’
git push #no need for the origin master now
The past weekend I attended a conference for web development/creative
agencies. The topic was how to make your business better and was taught
by some of the best in the industry: LessEverything.
I’m sure everyone got a little something different out of LessMoney, but I’m going
to share the highlights of what I’ve learned. Please feel free to
comment or ask questions below.
First you’ll notice you’re reading this out of my blog which until now
has been a boring bit of news about us. I’ve always been hesitant about
writing technical articles on my blog. My clients don’t care about that
stuff right? Well, it’s almost impossible to market web design to
actual clients. Our clients come from all walks, small local businesses
to large corporate businesses and from all different industries. How
can you possibly market to that wide a range...especially as a small
firm? What LessEverything
does is market to their peers and well...their competition basically.
Firstly, this establishes themselves as an authority in the industry
(they’re well known, respected and liked). And secondly, our industry
is blessed enough to have clients abound that we have to refer out
speciality work. So a design firm may refer work to a development firm
and vice verse. Marketing to your competition still feels backwards to
me, but I’m willing to give it a try. So expect at the least, more
insightful technical, award winning, can’t miss articles from this blog
Next is my website. I’m going to make it better. I’ve been so busy
working on other people’s sites that I’ve neglected my own. But, all
that says is “hey I can afford this guy. (Steven Bristol)” There were
some amazing designers here, like http://turnandface.com/ , http://gauged2.com/, http://www.16toads.com/, just to name
a few (I could actually put everyone’s site here). They explain how
much traction they’ve gotten from their sites. I also want to design my
site in a way that will qualify leads. By making it great, it will
naturally discourage away people looking for a cheap site. But if done
in a clever way, a different way, a less boring way, then then ideal
clients will get that and others will fly under the radar.
Another way to market myself is to create open source projects or design
for open source projects. This is perfect motivation for me to release
a project into open source that I use to track my billable time in my
company. I wrote the rails app after needing a new solution for myself
and it’s a nice simple tool many others could use, add to, and help me
improve my code. And maybe along the way, new relationships will be
created that will lead to new business.
I’m a quiet, soft spoken, easy going, humble type of guy. I have
opinions and preferences, but I keep them to myself. This will need to
change. Clients want to pay for opinions. They need guidance, ideas,
experience and consulting. Consulting means giving advice, and this is
no different in the web industry. From now on, we’ll display a little
Our number one goal as consultants, designers, and developers is to help
a client define success for a website or web app and provide them with
the best path to success with the least risk and least headache. I think
we generally do a pretty good job of this, but we could probably do a
better job of reiterating it to the client.
Business & Contracts
Use LessAccounting. Period.
Just kidding. The joke of the weekend was that LessMoney was really a
rouse to get us all to use LessAccouting (LessEverything’s flagship
Before, I only used contracts for larger projects or on gut feelings.
I’ll now be using a contract for every new project, large or small.
I’ve never had an unhappy client (that I’m aware of), but that day may
come and and I want to make sure I’m protected by a contract for what
was or wasn’t supposed to be delivered. They gave us the contract they
use and I’ll be using it against my own to modify it for my own needs.
I’d never thought of this, but from now on we’ll carry errors and
omission insurance to protect the company against the potential of
frivolous lawsuits. I don’t believe we’ll ever have a legitimate
lawsuit against us because we’re Godly, honest folks that bend over
backwards to please people, but in this country, anyone can sue anyone
for anything and it’s expensive to defend yourself, even when there’s
absolutely no case against you.
This is bad news for my clients, but I’m charging way too little for my
services compared to others. We will likely be raising our fees
sometime in the near future. Our quality of work and way too busy
schedule is proof that the time has come. We also haven’t raised our
rates since we started over 3 years ago.
Fixed Rate or Hourly?
There was no cut and try answer to this, but one thing clear for me was
that I need to move to hourly, or adjust my fixed estimates. At times I
go double over budgets in hours for a project. Fortunately I can afford
to do this because it’s my time instead of having to pay other devs to
do it, but it’s not fun, and also adds unnecessary stress takes time
away from my family. If you’re having a hard time estimating, don’t
feel alone, nearly everyone there struggles with this.
No content no problem
Myself included, many others cited a problem of getting clients to
submit copy/content for the site, which leads to delayed launch, which
leads to delayed payment (you get final payment when you launch the site
right?). This has to change. Some people said they get content up
front before starting a project. Some said they get down payment first,
then wait on content to start the project. Others suggested putting
language in the contract that all copy would need to be submitted x
number of days (10-30) after the site was ready to launch or there would
be a charge for it and they the client was still liable for final
payment regardless. Whether the client is too busy, or is using as a
stall tactic, it isn’t fair and should be thought out by the agency
ahead of time.
When we first kicked the workshop off, we all (only ~20 total allowed to
attend) introduced ourselves, said why we were there and defined success
for our business. It really warmed my heart and inspired me to say that
probably 90% + of us said something along the lines of this: making
more money wasn’t really an an objective, but spending more time with
family, better quality of life, working on more interesting projects,
having less stress, and just learning how to deal with problems was why
they were there, and was their goal. This was really so cool to hear.
As an industry, we all love designing, coding, building, and creating
things. We want to get paid for our hard work to support our families,
many are not just in it for the money only.
These highlights were just the tip of the iceberg. Some of the most
value came from the group discussions and relationships established. I
met some super cool people and already have loose plans to meet up with
some of them and also already have some leads on some new exciting
projects. I highly recommend contacting LessEverything and asking
when/if LessEverything Season #2 is going to
happen.. It’s well worth the time and money to go!