Skip to content

Instantly share code, notes, and snippets.

View jalada's full-sized avatar

David Somers jalada

View GitHub Profile
@jalada
jalada / gist:2909313
Created June 11, 2012 09:34
disk resize
Before:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/data--first-lvol0 1.9T 1.7T 147G 93% /raid
/dev/mapper/data--second-lvol0 1.9T 1.7T 147G 93% /mirror
After:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/data--first-lvol0 3.7T 1.7T 2.0T 47% /raid
/dev/mapper/data--second-lvol0 3.7T 1.7T 2.0T 47% /mirror
@jalada
jalada / gist:2761184
Created May 21, 2012 08:33
rvm --trace rvm list gemsets strings
+ /scripts/cli : __rvm_parse_args() 758 > [[ -n '' ]]
+ /scripts/cli : __rvm_parse_args() 759 > export 'PS4=+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ /scripts/cli : __rvm_parse_args() 759 > PS4='+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ /scripts/cli : __rvm_parse_args() 790 > [[ -z '' ]]
+ /scripts/cli : __rvm_parse_args() 790 > [[ -n '' ]]
+ /scripts/cli : __rvm_parse_args() 792 > [[ 0 -eq 1 ]]
+ /scripts/cli : __rvm_parse_args() 792 > [[ -n '' ]]
+ /scripts/cli : __rvm_parse_args() 13 > [[ -n rvm ]]
+ /scripts/cli : __rvm_parse_args() 15 > rvm_token=rvm
+ /scripts/cli : __rvm_parse_args() 17 > (( 3 > 0 ))
module DNA
def self.points
raw_points = 1000.times.map do |p|
5.times.map do |c|
Random.rand(100)
end
end
raw_points.map{|p| KDTree::Point.new(p)}
end
jalada@aer Development/shaed-temp » nodeunit test/
router_test
✔ Router - translateUrl function - translates a path with a regex
✔ Router - translateUrl function - translates a path to a hardcoded URL
✔ Router - translateUrl function - can translate a regexp involving a query string
✔ Router - translateUrl function - returns false when the regexp doesn't match
✔ Router - translateUrl function - replaces multiple variables
✔ Router - translateUrl function - replaces the same variable across entire destination URL
✔ Router - translateUrl function - returns false if parts of regexp did not match
@jalada
jalada / parse_query_monkeypatch.rb
Created February 21, 2012 15:47
Silently ignore bad cookies
# Monkey-patch cookies method to not raise an error on a
# malformed cookie. This is because the utag cookie set by The Times
# can contain malformed unicode characters.
alert = "WARNING: You are monkey-patching Rack::Utils.parse_query to dump broken cookies. BE CAREFUL!"
puts alert
puts "*" * alert.length
module Rack
response = Typhoeus::Request.get("http://example.com", :params => {"typhoeus" => "rocks"})
if response.success?
puts "Hell yeah! Here's what we got back:"
puts response.body
else
puts "Oh no! Error :("
end
curl -XPUT localhost:9200/_river/my_tweets/_meta -d '
{
"type" : "twitter",
"twitter" : {
"user" : "xxx",
"password" : "yyy",
"filter" : {
"tracks" : "foo,bar,baz"
}
},
@jalada
jalada / gist:1012283
Created June 7, 2011 13:45
Time.parse fails with really old dates?
REE 1.8.7:
ree-1.8.7-2011.03 :001 > require 'time'
=> true
ree-1.8.7-2011.03 :002 > Time.parse "Tue Oct 27 00:00:00 UTC 1896"
ArgumentError: time out of range
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/time.rb:180:in `utc'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/time.rb:180:in `make_time'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/time.rb:243:in `parse'
from (irb):2

This is (sorta) what Capistrano runs:

~$ rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ree' -c 'cd /path/to/project/current; echo $BUNDLE_GEMFILE'
/usr/local/rvm/config/Gemfile

This is what happens if I do it myself:

~$ cd /path/to/project/current
/path/to/project/current$ echo $BUNDLE_GEMFILE

/path/to/project/current/Gemfile

# Gnuplot is quicker than provided display_probs.py:
# gnuplot> set view map
# gnuplot> splot 'filename' matrix with image
def tognuplot(filename, matrix):
f = open(filename, 'w')
for i in xrange(len(matrix)):
f.write(' '.join([ str(x) for x in matrix[i]]) + '\n')
f.close()