Text
if (typeof foo === "function") {
   foo = foo();
}

My co-worker showed me this yesterday. “foo” is a paramater passed into a function to do whatever. Itself may or may not be a function. If it is, run it and set the return value to be the value used for whatever, otherwise just use the value. Took me a sec to wrap my mind around it, pretty sure you can’t do something this crazy in other languages. Javascript sure is interesting with its quirks!

Text

Concepts

Bitwise Operators - My coworker Scott taught me about these today. ‘|’ (or), ‘&’ (and), ‘«’ (shift), ‘^’ (xor), etc. They’re done at the hardware level, meaning super efficiency. It’s basically the same as the operators in circuits, except codified / in decimal representation. For example, 3|4 = 011|100 = 111 = 7.

Bitmasks - Imagine you’re conducting a survey on people’s diets (this is probably not a great example) - eats chicken vs doesn’t eat chicken, drinks milk vs doesn’t drink milk, eats beef vs doesn’t eat beef, etc. You could record each person’s every answer as a separate string/boolean, or you could record all their answers as one number. With 1 being ‘eats it’ and 0 being ‘doesn’t’, 100 = eats chicken, doesn’t drink milk, doesn’t eat beef. 101 = eats chicken and beef but doesn’t drink milk. Bitmasking is using bitwise operators to test against conditions. In an ‘if’ statement, I can test if the person drinks milk by performing a bitwise ‘&’ on their answer with 010. If the result is greater than 0, then the person drinks milk. Yes this could be done with other conditional tests but from what I gather, bitmasks / the whole integer representation concept in general are significantly more lightweight, albeit possibly harder to understand.  

& - Another magical Ruby shorthand. This one took me a while to understand, and I have to admit even now I’m a bit shaky on it. Basically if used on a Proc (variable which references a method), it’ll convert it to a block. If used on a block, reverse happens. This article did a good job of explaining it. The only thing I’d add is that in work we use it a lot for mapping. Normally to map you’d do

foos.map { |foo| foo.bar }

which performs ‘bar’ method on every item (foo) in ‘foos’. You can shorthand it to

foos.map &:bar

The & converts the ‘bar’ symbol to a block and calls it on each iteration, doing the same thing as the long(er) version. 

Law of Demeter - A general guideline for loose coupling / making your code more maintainable and safe. Doubt I can explain it better than that article, it’s a pretty easy read.

Technologies

Page Speed - Extension for web developer tools which tells you how to improve page performances

RDebug - Great gem for debugging / stepping through code in Ruby. This article explains pretty well how to use it

A/Bingo - Possibly one of the ugliest sites I’ve ever seen but very neat plugin for Rails A/B testing

Cool Articles

Linux Fundamentals 

Photoshop pushing photo magix further with unblur

Text

I suck at titling

I’ve recently passed the one year mark for programming! Oh how exciting it is to be a noob, a time when if someone asks “How did they make that?!?”, your only response is “magic”. It seems many web entrepreneurs are already super successful at my age, with years of programming and other experience under their belt. That just means I’ve got catching up to do. Lucky for me I’m surrounded by many bright minds and everyday I get to learn a myriad of cool, new things. 

Because I have terrible memory and would like to remember all of said things, I’ve decided to write it all down (in blog-form). Well, not everything. Just the programming-related things that I may forget about in the future and that probably will come in handy (sorry non-programmers, see my Twitter if you actually want to hear about other aspects of my life). 

In this blog I’m going to talk about programming tricks/concepts I recently learned/found cool or difficult and technologies/news I’ve recently discovered. ”Why would I read this rudimentary stuff” you ask? Well, your guess is as good as mine. This mostly serves personal purposes so if you’re reading it, you must be really bored, a good friend of mine, or a novice like me looking to have something explained. I’ll try to explain concepts in layman’s terms, or link to articles that do so if you’re actually here for knowledge, hope I am of help.

Note: I’m just going to blog about things as I learn them so there won’t be much flow or categorization to my posts. Also, I’m very much an amateur writer and programmer so feel free to call me out if anything I say is audaciously flawed or flat out wrong.

Link

We’re both on co-op. We both have a lot of free time. This is the result. 

Video