Skip to content

Instantly share code, notes, and snippets.

View robertsosinski's full-sized avatar

Robert Sosinski robertsosinski

View GitHub Profile
@robertsosinski
robertsosinski / gist:278657
Created January 16, 2010 05:21
Quickly get a pruned method list for any object
class Object
def local_methods
parent = self.class.superclass
(parent ? self.methods - parent.instance_methods : self.methods).sort
end
alias_method :m, :local_methods
end
@robertsosinski
robertsosinski / gist:278682
Created January 16, 2010 06:07
Metaprogramming example
class Person
def initialize(options = {})
options.each do |key, value|
self.instance_variable_set(:"@#{key}", value)
self.class.send(:define_method, key) do
self.instance_variable_get(:"@#{key}")
end
self.class.send(:define_method, "#{key}=".intern) do |*args|
@robertsosinski
robertsosinski / .gvimrc
Created January 18, 2010 15:09
MacVim config file
syntax on
"font
color github
set cursorline
set guifont=Monaco:h12
set guioptions-=T
set linespace=1
set vb
@robertsosinski
robertsosinski / github.vim
Created January 19, 2010 22:32
A Github styled MacVim color theme
" Vim color file
"
" Author: Anthony Carapetis <anthony.carapetis@gmail.com>
"
" Note: Based on github's syntax highlighting theme
" Used Brian Mock's darkspectrum as a starting point/template
" Thanks to Ryan Heath for an easy list of some of the colours:
" http://rpheath.com/posts/356-github-theme-for-syntax-gem
hi clear
@robertsosinski
robertsosinski / pair.rb
Created January 23, 2010 04:14
Modification of Bryan Helmkamp's pair script
#!/usr/bin/env ruby
require 'yaml'
PAIR_EMAIL = "paired@developers.local"
AUTHORS = YAML.load(`cat ~/.pair.yml`)
unless File.exists?(".git")
puts "This doesn't look like a git repository."
@robertsosinski
robertsosinski / gist:284421
Created January 23, 2010 04:16
Makes console functions so browsers without firebug will not raise errors
window.console = window.console || {};
["log", "info", "debug", "warn", "error"].forEach(function(level) {
console[level] = console[level] || function(){}
});
@robertsosinski
robertsosinski / jslint.rake
Created January 31, 2010 01:54
JSLint Rake Task
desc "Checks the JavaScript files with JSLint"
task :jslint do
failed_files = []
skipped_files = ["jquery-1.4.js", "jquery-json-2.1.js"]
rhino_path = File.join(RAILS_ROOT, "vendor", "jslint", "js.jar")
jslint_path = File.join(RAILS_ROOT, "vendor", "jslint", "jslint.js")
Dir['public/**/*.js'].reject{|path| skipped_files.include?(path.match(/.*\/(.*)/)[1])}.each do |name|
cmd = "java -jar #{rhino_path} #{jslint_path} #{name}"
@robertsosinski
robertsosinski / Github.tmTheme
Created March 6, 2010 02:36
A Github styled TextMate theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>GitHub</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@robertsosinski
robertsosinski / gist:512261
Created August 7, 2010 00:31
Map-Reduce Example
var rows = ["alice apple", "bob banana", "charlie cherry", "alice date", "bob eggplant"];
var mapped = rows.map(function(row) {
return row.split(" ");
});
var reduced = mapped.reduce(function(hash, pair) {
var key = pair[0],
val = pair[1];
@robertsosinski
robertsosinski / gist:728429
Created December 4, 2010 19:51
Short Stack: A simple ruby stack server.
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
meth, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, [send(meth, *attrs).to_s]]
end