command to delete a lot of unnecessary git branches
Assuming you have a lot of branches, and you only want to keep devel and master:
thread abort on exception
It might be useful to enable this while working with threads ( at least in early development phases ):
recursively replace with ack-grep and a little help from ruby and xargs
ack-grep is a great tool for finding files containing some strings. It’s easy to combine it’s power, with the in-place editing capabilities of ruby. Here’s how we’d replace the string alert with # alert in all the files within a directory:
What’s important to notice here, is that we’re using the l switch for ack, which means “give me only the name of the files containing that string”, and we’re piping each file to ruby’s in place editing. If you’d like to create a backup of the file, run the command like this:
This way, you’d also have the old file, in case your replace did not go so well.
rails listen/notify with postgres
Example of using listen/notify functionality, taken from here
Under ruby 1.9, async_exec is just an alias for exec. Example notify call:
javascript arguments array
It may be useful to know that each javascript function has access to a variable/property called arguments. It will hold all the arguments that the function was called with. An example where this may prove useful:
- imagine you’re doing a variable number of ajax requests in the same time, and you need to do something with the results, after they’ve all finished. I’m using the Deferred and Promise objects from jQuery, which I’m resolving once I’ve parsed the response of the server. Typically, the then function would take as many parameters as there were requests … and to write .then (data) it would only pass the first result to the then function. And … this is where arguments comes into play.
get shredded split
Fitness posts may pop here from time to time.
150lbs ( ~68 kg )
35% protein = 113g
10-15% carbs = 38g
55-60% fat = 100g
doing a request with basic auth
1
2
3
4
5
6
7
8
require "net/http"
url = URI.parse('http://localhost:3000/users/1.json')
req = Net::HTTP::Get.new(url.path)
req.basic_auth 'user', 'pass'
resp = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
puts resp
Using underscore js in an erb template
This allows for mustache style templates, interpolation done with and logic with