Skip to main content

Posts

Showing posts with the label Rails

Programming is a Craft (And that's a good thing)

Programming is a craft. You are building something. The modern languages have given the programmer great ownership of the craft. Before it was more like an assembly and one programmer was responsible for one cog in a big machine and few programmers, the elite, saw the whole machine, understood the whole craft. But now with languages like Ruby and Python, the massive power at the hands of the programmer bring the whole thing back to a craft. It is something you do with your hands. It is creative, like writing and while not physical or tactile, it is built piece by piece. The connection is deep and actually obscured by the way programming is taught. Because programming originated from a mathematical discipline and math has mostly lost its craft origins and now is taught more as an intellectual pursuit, it is often forgotten that math is but a tool itself. Not an end goal. Math is used to do things with it. Calculous to measure trajectories of objects. Geometry is essential for architec...

Great Technical Books on Programming

We are in the middle of a computer programming languages explosion. In the last few years, a slew of programming languages have come into their own, others have been revived with new expressions and a whole bunch of them have been born anew. Also a new modality has appeared of the polyglot programmer, that is a programmer that works in multiple languages. This last change is the most significant. Because for a long time programming was dominated by a very few select group of languages: C, C++, Java and C#. All of which are related. And dominated by a tool set like Visual Studio with C# and Visual Basic. Now that is no longer the case and things are for the better. Recently I taught myself how to program and want to highlight a few books that are good reads. Most books in programming fall into a trap, that is they don't teach programming at all, but instead teach only the programming language. That's like teaching someone the rules to America Football and expecting them to a...

Ruby Idioms part 1

Ruby is like a language in that it has phrases that are used, and ones that work better than others. The most common rubyism is a ||= b where a is set to b if it is not nil , false or undefined . It basically means if a  has a value move on but if it doesn't set it to b . Simple enough. But an even more powerful one but less well known is the index feature one. Arrays, hashes and even more importantly strings have this function too. In hashes it's the normal way to get a value by sending it its key. So: hashy = {:key1 =>  :value1, :key2 => {:subkey1 => :subvalue1}} doing hashy[:key1] will spit out :value1  But it's really useful for strings too. stringy = "Friends, Romans, countrymen, lend me your ears;" stringy['lend me your ears'] #=> "lend me your ears" You can also chain this calls which leads to some weird things. stringy['lend me your ears'].upcase['EARS']   #=>  "EARS" I just u...

How to pass a Rails or Sinatra variable into JQuery.

A few days back I got a code challenge for a cool job position. For whatever reason the test was very light on Rails very heavy on JQuery, which I didn't know much about frankly. So in less than 24 hours I had to not only learn enough of it but also make it work into a modal window widget. I got it done, but it wasn't elegant at all. I clobbered it even if it worked. The first challenge was to get information into webpage from a Rails application, I chose JSON and thought it'd be easy-peasy, but transferring a JSON object is a cross-domain script violation and most browsers won't let it pass. So I learned about JSONp which wraps the JSON object in a JQuery call-back. Lacking the easy Ruby ways of determining what things are, at first I'd no idea what the JSONP object was and just had my Rails app send JSON. Once I figured what it was, it was trivial to get Rails to do it. All I had to do was add: :callback => params[:callback]  to the format property in the con...