Skip to content

Instantly share code, notes, and snippets.

View awesome's full-sized avatar

So Awesome Man awesome

View GitHub Profile
@digitalronin
digitalronin / gitrmall.rb
Created July 22, 2008 13:36
Ruby script to automatically "git rm" deleted files
#!/usr/bin/env ruby
# Ruby script to automatically "git rm" deleted files
DELETED_REXP = /^#\s+deleted:\s+(.*)/
MARKER_LINE = '# Changed but not updated:'
lines = `git status`
found_marker = false
@dougal
dougal / Simple Ruby Class Example.rb
Created November 14, 2008 11:32
Simple Ruby Class Example
class Badger
attr_accessor :name, :size # Creates getter and setter methods.
def initialize(name, size)
@name = name
@size = size
end
# Instance method
# TODO - add dependent option support
def delete_records(records)
klass = @reflection.through_reflection.klass
records.each do |associate|
klass.delete_all(construct_join_attributes(associate))
end
end
@huy
huy / Hash.from_xml
Created February 10, 2011 05:29
Convert xml to hash using Nokogiri
# USAGE: Hash.from_xml(YOUR_XML_STRING)require 'rubygems'
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#123129
7
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
@briancavalier
briancavalier / simple-promise-retry.js
Created February 24, 2011 18:35
A few general patterns for retries using promises
function keepTrying(otherArgs, promise) {
promise = promise||new Promise();
// try doing the important thing
if(success) {
promise.resolve(result);
} else {
setTimeout(function() {
keepTrying(otherArgs, promise);
@erikfried
erikfried / README.markdown
Created March 7, 2011 10:21
shell script to invoke jslint via jsc on Mac OS X

I just realized that there is a rather well hidden javascript interpreter in the mac os x terminal out of the box. /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc See http://www.phpied.com/javascript-shell-scripting/

Then i figured it coud be quite easy to set up a command line util to run jslint from anywhere. Thought i´d share how.

Setup

@RiANOl
RiANOl / gist:1077760
Last active April 13, 2024 06:17
AES128 / AES256 CBC with PKCS7Padding in Ruby
require "openssl"
require "digest"
def aes128_cbc_encrypt(key, data, iv)
key = Digest::MD5.digest(key) if(key.kind_of?(String) && 16 != key.bytesize)
iv = Digest::MD5.digest(iv) if(iv.kind_of?(String) && 16 != iv.bytesize)
aes = OpenSSL::Cipher.new('AES-128-CBC')
aes.encrypt
aes.key = key
aes.iv = iv
@mxcl
mxcl / uninstall_homebrew.sh
Created August 26, 2011 11:25
Uninstall Homebrew
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
@ferblape
ferblape / gist:1189798
Created September 2, 2011 20:22
Fakeweb POST request tests
def test_register_uri_for_post_method_with_parameters
FakeWeb.register_uri(:post, "http://example.com/users", :body => "User list 1", :parameters => {:p1 => 'v1'})
FakeWeb.register_uri(:post, "http://example.com/users", :body => "User list 2", :parameters => :any)
assert_equal 2, FakeWeb::Registry.instance.uri_map.values.first[:post].size
assert FakeWeb.registered_uri?(:post, "http://example.com/users", :parameters => {:p1 => 'v1'})
assert FakeWeb.registered_uri?(:post, "http://example.com/users", :parameters => :any)
end
@tonywok
tonywok / results.md
Created September 15, 2011 01:33
Rails 3.1 Callbacks
s = Test.new(:name => "foo")

# ActiveRecord::Test after_initialize
# ActiveRecord::Test after_initialize, :on => :update
# ActiveRecord::Test after_initialize, :on => :create
# ActiveRecord::TestObserver after_initialize

# ===> #<Test id: nil, name: "foo", created_at: nil, updated_at: nil>