I have made the decision to find a new way of posting articles. Tumblr has worked well up till now but there are just a few limitations that are becoming more of a hassle than I care to deal with. With that said I will switching to a different hosted solution. I will also be taking this time to redesign the blog.
All of the articles that are on Tumblr will remain. I am still trying to decide if I want to convert the documents or just start over. Chances are that I will move them over at some point but for now I will just be leaving this site alone. With that said, http://schmidt-happens.com will now be directed at a different source so if you want to keep track of this blog you will need to update your links to use http://schmidt-happens.tumblr.com.
If you’re like me, then you have probably come across this issue before and done something similar in how I used to solve this problem. Let me set the stage. Let’s say that you have a hash of states and abbreviations. The abbreviation for the state is the key and the value is the full name of the state. Now, let’s say you want to find the key that is associated with a particular states full name (this actually happened to me when I was doing a conversion from one system to the other and in the old system people could type whatever they wanted for the state e.g. Texas, texas, tx, TX, Lone-Star State).
The way I used to approach this situation would be to just select the pair where the value matched. This returns an array of arrays for anything that matches. It was a bit crufty though because I was only ever expecting a single result to match.
texas = THE_STATES.select { |kee, value| value == "Texas" }
#=> [["TX", "Texas"]]
# To get the abbreviation
texas.first.first
#=> "TX"
I was writing this and thought “something really smells bad and I think it’s this code”. So I did some digging into the Hash class for Ruby. After looking for something that sounded like it did what I wanted I came across the Hash#invert. Heres what the docs have to say about it:
Returns a new hash created by using hsh‘s values as keys, and the keys as values.
With this information it becomes deadnuts simple to do what I was doing before.
THE_STATES.invert["Texas"]
#=> "TX"
Boom! One line of code. Super simple. Clean. All the things I look for when I want to write some code.
Ok…so that was a few days ago but I’ve been a bit busy with a vacation and all. Let’s not let that shed a shadow on the awesomeness that is this announcement. If you haven’t been following the releases then you have been missing the crazy build up to this milestone. It seemed like every time I fired up my news reader there was an article about a new release candidate coming out (I think there were 8 or 9 total). But we have finally seen the end product released. I am literally giddy with excitement over this new release. I’ve been waiting for some of the new features and changes with this new version and will start a new series of articles that will discuss some of my personal favorites.
I’m going to try and be very disciplined and get a new article out each week. This is a huge change for me as I have been very…uh, let’s just say lax, on my prior releases. Hopefully you will find these articles helpful. If you have questions or topics you would like to see covered please email me at schmidthappensblog [at] gmail [dot] com.
The other day I signed into Twitter using the website (normally I’m using an app) and was intrigued by the way they did their form elements. In an effort to understand what they did and also recreate it myself I wrote up an article that explains how to accomplish this. Check it out and let me know what you think.
Holy crapballs, it’s been a while since my last post. Lots of things have been happening (moved to Texas, new job, new friends, new trouble, new house, blah blah blah) and I am, fingers crossed, finally getting back into a normal schedule again. This is a quick update about a new plugin I just created.
I had the need for a content slider and after reviewing a few of the jQuery plugins that are available, I decided they either had too many options/features, or they were too opinionated about how I should structure my HTML. So I did what any developer would do in that situation, I rolled my own. Check it out and let me know what you think.
Update (Jul 7, 2011): I added a link to the live demo
Hey kids, I know it’s been a while but what can I say…life gets in the way. This is just a quick tip for those of you that like to look through the source of a gem you are using (which if you aren’t why not?). I stumbled across this little ‘gem’ (haha, puns) the other day and I LOVE it.
gem install open_gem
Now you can simply type the following from your command line
gem open <gem_name>
open_gem uses your default EDITOR. What? Your EDITOR variable isn’t set? Don’t fret
export EDITOR=<executable to your editor of choice>
or
gem open <gem_name> -c <executable to your editor of choice>
…or at least not always. This is something that has bothered me since I first became a web professional. When I got my degree as a web developer and started looking for jobs I noticed a trend when looking at job postings:
Required Skills
- PHP
- Javascript
- Adobe Photoshop ®
- Adobe Illustrator ®
etc, etc, etc
Now, to me, the Photoshop® and Illustrator® bits always seemed a bit strange. I was applying for a development job. Why then, am I being asked to know design software?
Over the years I have come to this conclusion: People think that a “web designer” and a “web developer” possess the same skill sets. While this is true in some situations my feeling is that a developer who has learned design skills or vice versa has done it out of necessity. The mentality that web professionals have both skill sets drives most of us to learn something that we don’t have a real passion for. We learn just enough to say “yep, I know Photoshop” or “yep I know PHP”, but in reality you know just enough to get by.
This, to me, is a problem. What’s really strange to me is that you really don’t see this expectation in other industries. Take a look at the construction industry. Imagine seeing a job listing for an architect that listed “interior design” and “color theory” as job skill requirements. You would probably think it was a silly job posting.
As a developer or designer you should be proud to be a master at your craft. I would much rather hire two masters than one jack-of-all-trades. While it may be cheaper to hire just one person there are going to be more disadvantages. In most cases I have seen either the visual design or the application design suffer.
Most of the time this is true because you are asking one person to do the job of two or more. This will likely lead to corners being cut to come in on time/budget. Another side affect is that you will likely have a burnt out employee by the end of the project since they will have to spend so much time switching hats. On the flip side, if you have separate individuals that are masters at their craft you will get a much better result. Mainly because they have one problem to focus on but also because, well, they are “masters” at their craft.
I feel that as web professionals we need to set the expectation that we will no longer be a swiss army knife of skills. It’s exhausting and leads to burn out very quickly. I know all to well from personal experience. Let’s stop diluting our skill sets and be the ninjas we know we want to be.
Are you a developer or designer? Are you an employer? Let me know what you think based on your own personal experiences.
It goes without saying, but I’m gonna say it anyway, when you learn a new language (programming or otherwise) you shouldn’t expect to master it over night. I realize that reading that statement you are probably thinking to yourself “geez, that was obvious” but think about how many times you’ve heard that little voice in the back of your head that says “God, you should know this by now”.
Baby steps.
That’s the key to becoming proficient. Actually, there is a more technical term for this which is accretion, but the main point is that you should attain growth through gradual expansion.
Set a goal of learning/using one new method every two days. Or become familiar with one new library a week/month. Or read and then re-read one chapter of the latest and greatest technical reference for language X each week.
The point is to not get discouraged if it takes you a while to learn something to the point of ninja master. You’ll get there eventually.
Ruby/Rails never ceases to amaze me. Once again while digging around in the source code of Rails I came across Object#returning. Let me introduce you to this little gem.
If you have been writing code for any amount of time then this should look quite familiar to you.
def some_method
some_var = []
some_var << 'foo'
some_var << 'bar'
return some_var
end
I know, that example was really deep but just bare with me (there is a reason for it’s simplicity). This is a very common workflow when writing code. You initialize an object and assign it to some variable.
some_var = []
Then you perform some über secret work.
some_var << 'foo'
some_var << 'bar'
And finally you return the stuffed object to be used somewhere else. Fortunately, the clever lads behind Rails have enhanced the Object class with a method called ‘returning’. This method takes that workflow and simplifies it. Here is an example of the same workflow above but using Object#returning instead.
def some_method
returning some_var = [] do
some_var << 'foo'
some_var << 'bar'
end
end
There you have it. Simple. Clean. Elegant. There is an alternative syntax although I personally don’t think it is as intuitive as the one above. But, because I don’t discriminate, here is the more cryptic example.
def some_method
returning [] do |some_var|
some_var << 'foo'
some_var << 'bar'
end
end
The reason that I feel this style is more cryptic is that it is not immediately clear what you are ‘returning’. At first glance you may be thinking that it is returning an empty array when what it is really returning is the variable ‘some_var’ after the work in the block has been performed. That, of course, is one of the great things about Ruby (and many other languages). You often have several different ways of accomplishing the same goal.
The method Object#returning is being removed in favor of the Object#tap method. I will follow up with a post covering Object#tap and post a link to it in the future. Thanks goes to phiggins for pointing this out.
Twitter. Facebook. Text Messaging.
These services will be the demise of grammar.
No longer will we communicate in clear, concise sentences. Rather, we will begin to communicate in broken, choppy sentences that will mainly consist of abbreviations (OMFGROTFLMAOBBQ) and butchered words. All for the sake of squeezing every last character out of our [160|140|1XX] limits.
I know this to be true. How do I know this? Because over the past few years grammatical genocide has left the services like Twitter and Facebook and spread like a plague to areas that allow an unlimited number of characters. Comments on blog posts. Comments in iTunes. Letters delivered by snail mail (yes, actually paper and pen letters…they do still exist). Emails. Presentations. Magazines.
How long do you think it will take before how we write begins to affect how we speak? The answer is it’s already happening. Think about how often you say things like “WTF?” and “OMG!”. These phrases used to feel odd when your mouth first began to form them. Now they are so common place that you probably don’t even realize you are doing it. Have we as a society become so lazy that we can’t event bring ourselves to actually say “what the fuck?” or “oh my God!”? Are these bytes, these characters so insignificant to us now that we can’t even take the time to give them the time of day?
I believe words are worth the time. I believe there is a way to reverse this trend of butchering our language. Stop trying to use Twitter to convey a thought or message that should belong in a blog post. With services like tumblr anyone can have their own blog. If you can’t convey what you want to say in 140 characters of proper (or close to proper) grammar why not create a blog post and tweet a link to said blog post? You can even add a tagline to the tweet to entice your minions to come and read what you have to say.
Writing comments on something is no different. If you are leaving a comment it means you care enough to “voice” your opinion. Why sell yourself short by writing something that is unintelligible shit? Every time I see something like “Lolxz Diz Video Iz Funny But I Hope Dat Lady Gaga Dnt Luk Like Diz In Da Futre..!!” I want rip my eyes out of my skull and river dance on them.
Some of you will point out that I am not innocent in the butchery of words and you would be right to do so. The important thing is that a) you noticed the mistakes and b) I am making a conscious effort to brake the cycle. Will you join me? Will you make a change?