You're viewing all posts tagged with tech

The trouble with bash colored prompts munging your control-r bash history searches

Basically, you just want to be very careful properly escaping and ending color sequences in your bash prompt.  If you mess them up, when you try to use spiffy bash tricks that mess with your current line, such as control-r to search through your bash history and then left of right arrow to edit that line, you’ll get a partially overwritten line that is impossible to read or edit properly.

 1 2 3 4 5 6 7 8 9 10 11 

#Just be careful. Safest to properly end color sequence, so instead of this
#export PS1=”\[\033[01;32m\]\u\[\033[00m\]\[\033[01;31m\]\$(git_br)\[\033[01;32m\]\[\033[00m\]:\[\033[01;36m\]\$(git_pwd)\[\033[00m\]\$ “
 
#do this
USER_GREEN=’\[\e[01;32m\]’
#NO_COLOR=’\[\e[00m\]’
REPO_RED=’\[\e[01;31m\]’
PATH_BLUE=’\[\e[01;36m\]’
END_COLOR=‘\e[m’
 
PS1=”${USER_GREEN}\u${END_COLOR}${REPO_RED}\$(git_br)${END_COLOR}:${PATH_BLUE}\$(git_pwd)${END_COLOR}$ “

Posted via web from a timocracy of one | Comment »

Call a custom jar from ruby in jruby

 1 2 3 4 5 6 7 8 9 

#javac HelloWorld.java && jar cvf HelloWorld.jar HelloWorld.class
require ‘java’
require ‘HelloWorld.jar’
import ‘HelloWorld’
 
puts HelloWorld.new.hello
#=> “Hello cruel world”
 
#jruby hello_world.rb

Posted via email from a timocracy of one | Comment »

Tagging a git release with current branch name and date

Either add this to your .git/config

[alias]  datetag = !git tag `git name-rev --name-only HEAD`-`date \"+%Y%m%d%H%M\"`

or run it in your project folder to add it to the config for that project:

git config alias.datetag '!git tag `git name-rev --name-only HEAD`-`date "+%Y%m%d%H%M"`'

Posted via web from a timocracy of one | Comment »

Setting RAILS_ENV on Dreamhost when running Passenger

It may depend on which server you are on, but mine has mod_env
enabled, so it’s a simple matter of setting the ENV[‘RAILS_ROOT’] in
an .htacess file
 
SetEnv RAILS_ENV staging

Posted via email from a timocracy of one | Comment »

http://g.raphaeljs.com/

http://g.raphaeljs.com/

A sweet javascript charting/graphing library. Soon there may be no
need for flash/flex every again?

Posted via email from a timocracy of one | Comment »

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