Skip to content

Instantly share code, notes, and snippets.

View dpaluy's full-sized avatar

David Paluy dpaluy

  • Majestic Labs
  • Austin, TX
  • X @dpaluy
View GitHub Profile
@dpaluy
dpaluy / chron.rb
Created July 4, 2012 08:00
Download 12 years stock history data from: http://markets.chron.com/chron/markets
require 'fileutils'
require 'open-uri'
class Chron
def initialize(symbol)
@symbol = symbol
end
def grab_year(year)
url = "http://markets.chron.com/chron/action/gethistoricaldata?Month=12&Symbol=#{@symbol}&Range=12&Year=#{year}"
@dpaluy
dpaluy / erb2haml.rb
Created July 4, 2012 20:55
Convert Erb to Haml
class ToHaml
def initialize(path)
@path = path
end
def convert!
Dir["#{@path}/**/*.erb"].each do |file|
`html2haml -rx #{file} #{file.gsub(/\.erb$/, '.haml')}`
end
end
@dpaluy
dpaluy / git.sh
Last active June 26, 2020 05:34
Remove trailing whitespace of all files recursively
# Git repository-specific solution
# Source: http://unix.stackexchange.com/questions/36233/how-to-skip-file-in-sed-if-it-contains-regex/36240#36240
git grep -I --name-only -z -e '' | xargs -0 sed -i -e 's/[ \t]\+\(\r\?\)$/\1/'
@dpaluy
dpaluy / recipes.rb
Created September 25, 2012 09:44
Capistrano recipes
#############################################################
# Capistrano recipes
#############################################################
task :uname do
run "uname -a"
end
# Usage: wait_for_process_to_end('delayed_job')
#
def wait_for_process_to_end(process_name)
@dpaluy
dpaluy / benchmark.rb
Created November 26, 2012 07:37
Simple benchmark test
#!/usr/bin/env ruby
require 'benchmark'
Benchmark.bm do|b|
b.report("+= ") do
a = ""
500_000.times { a += "." }
end
b.report("<< ") do
@dpaluy
dpaluy / fast_load.patch
Created November 26, 2012 13:45
Fast Load Patch for ruby
diff --git a/load.c b/load.c
index b0e6f16..4c98dbb 100644
--- a/load.c
+++ b/load.c
@@ -69,6 +69,17 @@
return GET_VM()->loading_table;
}
+/* This searches `load_path` for a value such that
+ name == "#{load_path[i]}/#{feature}"
@dpaluy
dpaluy / gist:4369788
Created December 24, 2012 16:12
Don't subclass Struct classes
# Don't subclass Struct classes
# instead of:
class Wheel < Struct.new(:rim, :tire)
#...
end
#use
Wheel2 = Struct.new(:rim, :tire) do
# ...
@dpaluy
dpaluy / debugging.rb
Last active December 11, 2015 20:08
Debuggin Ruby
GC.enable_stats if defined?(GC) && GC.respond_to?(:enable_stats)
GC.start # clean up heap
# dump it, including class names of heap objects
GC.dump_file_and_line_info(filename: "heap.dump", include_class_names: true)
stat_string = "allocated: #{GC.allocated_size/1024}K total in #{GC.num_allocations} allocations, GC calls: #{GC.collections}, GC time: #{GC.time / 1000} msec"
@dpaluy
dpaluy / setup_pahntomjs.sh
Created February 10, 2013 09:00
PhantomJS setup on Ubuntu
# Download http://phantomjs.org/download.html phantomjs version
# extract tar file
tar xjvf phantomjs-1.8.1-linux-x86_64.tar.bz2
# move to /opt
sudo mv phantomjs-1.8.1-linux-x86_64 /opt/
# create simlink
sudo ln -s /opt/phantomjs-1.8.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
@dpaluy
dpaluy / linkedin.rb
Created March 5, 2013 20:14
Crawling LinkedIn
require 'rubygems'
require 'mechanize'
require 'nokogiri'
@linkedin_username = "username"
@linkedin_password = "password"
agent = Mechanize.new
agent.user_agent_alias = "Mac Safari"
agent.follow_meta_refresh = true