Showing posts tagged tech

Avoiding some of the negative trade-offs in the template pattern with ruby’s dynamicism?

So my buddy Tammer’s recent post about the Gang of Four’s Template Pattern reminded me of some code I saw recently. A start-up’s greenfield project had it’s authorization done in a pretty clean way using the template pattern. Basically every object determined what could be done to it, something like this:

After continuing this approach to fully cover CRUD you make a straight-forward set of accessors that can be used to easily enforce permissions in the controller in a programmatic way (this project was using on of the inherited resourceful-controller plugins, so that was a big plus). The developer who implemented this commented that the trade-off for this simplicity was having to look in each individual model file to figure out what a user can do overall. I figured I liked everything about this scheme except that trade-off, and since ruby is so dynamic, why settle for almost. Why not just reopen each class in the authorization file and add the methods. You still get the simplicity and encapsulation of having the model able to determine it’s own permissions, based on it’s state and methods, and there is still one place to look to review/change the permissions for the whole project:

Thoughts?

Posted via web from a timocracy of one | Comment »

My Favorite bash Tips and Tricks

which produces the same result. However, brace expansion becomes quite useful when the brace-enclosed list occurs immediately before, after or inside another string:

$ echo {one,two,red,blue}fish  onefish twofish redfish bluefish    $ echo fish{one,two,red,blue}  fishone fishtwo fishred fishblue    $ echo fi{one,two,red,blue}sh  fionesh fitwosh firedsh fibluesh  

Notice that there are no spaces inside the brackets or between the brackets and the adjoining strings. If you include spaces, it breaks things:

$ echo {one, two, red, blue }fish  {one, two, red, blue }fish    $ echo "{one,two,red,blue} fish"  {one,two,red,blue} fish  

However, you can use spaces if they’re enclosed in quotes outside the braces or within an item in the comma-separated list:

$ echo {"one ","two ","red ","blue "}fish  one fish two fish red fish blue fish    $ echo {one,two,red,blue}" fish"  one fish two fish red fish blue fish  

You also can nest braces, but you must use some caution here too:

$ echo {{1,2,3},1,2,3}  1 2 3 1 2 3    $ echo {{1,2,3}1,2,3}  11 21 31 2 3  

Now, after all these examples, you might be thinking to yourself, “Gee, those are great parlor tricks, but why should I care about brace expansion?”

Brace expansion becomes useful when you need to make a backup of a file. This is why it’s my favorite shell trick. I use it almost every day when I need to make a backup of a config file before changing it. For example, if I’m making a change to my Apache configuration, I can do the following and save some typing:

$ cp /etc/httpd/conf/httpd.conf{,.bak}  

Notice that there is no character between the opening brace and the first comma. It’s perfectly acceptable to do this and is useful when adding characters to an existing filename or when one argument is a substring of the other. Then, if I need to see what changes I made later in the day, I use the diff command and reverse the order of the strings inside the braces:

$ diff /etc/httpd/conf/httpd.conf{.bak,}  1050a1051  > # I added this comment earlier  

Brace expansion is pretty cool when used as pseudo-globbing.

Posted via web from a personal timocracy | Comment »

SSD degradation due to software development usage - via @brynary

http://macperformanceguide.com/Storage-SSD-Reconditioning.html

“Six months of experience with the Intel X25-M solid state drive (SSD)
on the Mac Pro revealed the severe degradation of write speed to
roughly 1/4 of the original speed, with unpredictable pauses. This
behavior was induced by intense usage of the SSD for software
development, an inappropriate use for an SSD, because over time it
involves the creation and deletion of untold millions of small files.”

Posted via email from a personal timocracy | Comment »

interesting new ruby, redis-based background job/queueing choice from the github guys

http://github.com/blog/543-new-resque-web-ui
http://github.com/defunkt/resque

Yet another queuing system, but I do like the look of the included
Sinatra mini-app for managing it. And isn’t redis all the hot thing
now? Or is that a negative?

Posted via email from a personal timocracy | Comment »

Maybe hiding initialize in your abstract parent class is too much abstraction?

Or the wrong one. It just seems like over-inheriting is definitely one of the bigger maintainability nightmares I have had; and pulling the constructor entirely into the parent…. Well it better be exactly the parent, and cleanly done.

It’s like those overly abstracted resource_controllers. They seem like a great idea, but once you start deviating at all, you spend more code and more time thinking about how to write that code to get out of the straight-jacket over over-inheritance than you would have had in the first place.

I’m starting to feel that while abstract constructors *can* be done right they are often are a smell. Compare these three approaches and let me know what you think:

No JS or in a feedreader? Read the code in the gist

A pretty good overview of ruby’s Structs

http://blog.rubybestpractices.com/posts/rklemme/017-Struct.html#

including the oft under-documented passing of a block to new

Mislav’s git shortcuts for resolving conflicts

Using posterous to manage crossposting and tumblr to manage feed aggregation

I am late to this game, but shortly after deciding to switch my blog over to Tumblr, I discovered the joys of Posterous. As you probably know, Posterous is a microblogging service primarily aimed at posting via email. This may sound awkward at first, but to be honest, it seems a lot less awkward than logging in and using some textarea on a html form. I do most of my (non-coding) writing in an email client anyways, why not do my blog posts in one too. This lets me edit to my hearts content, save as a draft, easily post from my iphone, etc.

The real value-add (please don’t hurt me for the business speak) for me, though, is Posterous’s cross-posting capabilities. I have four addresses set-up in my contact list: post@posterous.com to post to all of my networks, twitter+tumblr+flickr@posterous, for my tech postings and facebook+twitter+flickr@posterous.com for my non-tech postings, and posterous@posterous.com for things that should not be cross-posted. I can just include flickr in all of them, because Posterous is smart about different email content, so it will only post to flickr if there is an image included (obviously?).

The second piece of this is Posterous’ main competitor, Tumblr. I am currently using Tumblr for my tech blog. Tumblr has a better aggregation focus than posterous, aiming less at being the piece designed to cross-post, and more aimed at pulling your content in. Therefore, in Tumblr I have added rss feeds for my Google Reader shared items, my Instapaper starred items, my delicious (okay, not really, but only because that has become completely supplemented by the previous two), and a Flickr feed for any items tagged ‘tumblr’. I may drop the Flickr tag, since I can handle that via Posterous, but I suspect I will have a use for items that get added to Flickr straight off my camera, etc.

I’ll try this set-up for a while any perhaps do a follow-up with how it works for me. If I don’t, it’s working perfectly. ;)

Update Beware linebreak differences between gmail, posterous, and tumblr. When I diagnose them I’ll post about it.