Skip to content

Instantly share code, notes, and snippets.

@henrik
henrik / hash_deep_diff.rb
Created July 14, 2009 08:38
Recursively diff two Ruby hashes.
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {
@micahbrich
micahbrich / generate_and_deploy_assets.rb
Created November 16, 2009 15:25 — forked from aeden/generate_and_deploy_assets.rb
capistrano recipe for moving public files to s3
desc "Generate and deploy assets"
task :deploy_assets, :roles => :app do
# get the previous timestamp
old_timestamp = File.read("config/deploy_timestamp").to_i rescue 0
# generate timestamp into config/deploy_timestamp
timestamp = Time.now.to_i
File.open("config/deploy_timestamp", 'w') do |f|
f.write(timestamp)
end
@tritonrc
tritonrc / ldap_admin.rb
Created January 17, 2011 19:55
Simple Sinatra based LDAP admin tool
require 'rubygems'
require 'sinatra'
require 'net-ldap'
require 'digest/sha1'
require 'base64'
require 'haml'
LDAP_HOST = 'localhost'
ADMIN_DN = 'cn=admin,dc=company,dc=com'
@yuya-takeyama
yuya-takeyama / binarytree.rb
Created February 5, 2011 14:32
Binary Tree implemented in Ruby.
module BinaryTree
class Node
attr_reader :word, :count, :left, :right
include Enumerable
def initialize(word)
@word, @count = word, 1
end
@olivere
olivere / gist:877805
Created March 19, 2011 21:10
em-http-request with capturing and passing cookies on redirects
# Gemfile
source "http://rubygems.org"
gem 'eventmachine', '~>1.0.0.beta.3'
gem 'em-synchrony', '~>0.3.0.beta.1'
gem 'em-http-request', '~>1.0.0.beta3'
gem 'addressable', :require => 'addressable/uri'
# Capturing and passing cookies on redirects
require "rubygems"
@flying-sheep
flying-sheep / fix_jar_mime.sh
Created September 29, 2011 14:41
A bug exists for ages in Kubuntu (and afaik only there) that can be fixed by removing a superfluous file and rebuilding the MIME DB.
#!/bin/bash
ROOT_UID=0
FIX_JAR_MIME="rm -vf /usr/share/mime/packages/sun-java*-jre.xml
update-mime-database /usr/share/mime"
if [ "$UID" -ne "$ROOT_UID" ]; then
kdesudo -c "$FIX_JAR_MIME"
kbuildsycoca4 #only possible if run as underprivileged
else
"$FIX_JAR_MIME"
cd ~/
git clone git://github.com/ariya/phantomjs.git && cd phantomjs
qmake-qt4 && make
sudo cp bin/phantomjs /usr/local/bin/
@moondev
moondev / shotty.js
Created February 20, 2012 23:28
shotty.js
//create new webpage object
var page = new WebPage();
//load the page
page.open('http://espn.go.com/nfl', function (status) {
//fire callback to take screenshot after load complete
page.render('espn.png');
//finish
phantom.exit();
});
@moondev
moondev / shotty2.js
Created February 21, 2012 17:46
shotty2.js
var page = new WebPage();
page.open('http://espn.go.com/nfl/', function (status) {
//once page loaded, include jQuery from cdn
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
//once jQuery loaded, run some code
//inserts our custom text into the page
page.evaluate(function(){$("h2").html('Many NFL Players Scared that Chad Moon Will Enter League');});
//take screenshot and exit
page.render('espn.png');
@moondev
moondev / browserstuff.sh
Created February 21, 2012 17:57
browserstuff
sudo apt-get install flashplugin-nonfree msttcorefonts