Skip to content

Instantly share code, notes, and snippets.

View sj26's full-sized avatar
🤹‍♂️

Samuel Cochran sj26

🤹‍♂️
View GitHub Profile
class Object
def returning obj
yield obj
obj
end
def tap
returning(self) { yield self }
end
def tapp
tap { puts "#{File.basename caller[4]}: #{self.inspect}" }
@tpope
tpope / .gitattributes
Created October 24, 2010 20:38
Fewer conflicts in your Rails apps
Gemfile.lock merge=bundlelock
db/schema.rb merge=railsschema
@notahat
notahat / factorial.rb
Created November 16, 2010 05:34
Ruby 1.9 lambda calculus fun
alias λ lambda
λ {|f| λ {|x| f[λ {|y| x[x][y] } ] }[λ {|x| f[λ {|y| x[x][y] }] }] }[λ {|f| λ {|n| n == 0 ? 1 : n * f[n-1] } }][6]
@sj26
sj26 / upcdb.py
Created March 16, 2011 06:47
Python 3 command line interface to http://upcdatabase.com
#!/usr/bin/env python3
import os, sys
import xmlrpc.client
rpc_key = '...' # replace with your RPC Key from http://upcdatabase.com/user
server = xmlrpc.client.ServerProxy('http://www.upcdatabase.com/xmlrpc')
lookup_keys = {12: 'upc', 13: 'ean'}
@kares
kares / jquery.parseparams.js
Created May 5, 2011 11:28
jQuery.parseParams - parse query string paramaters into an object
/**
* $.parseParams - parse query string paramaters into an object.
*/
(function($) {
var re = /([^&=]+)=?([^&]*)/g;
var decodeRE = /\+/g; // Regex for replacing addition symbol with a space
var decode = function (str) {return decodeURIComponent( str.replace(decodeRE, " ") );};
$.parseParams = function(query) {
var params = {}, e;
while ( e = re.exec(query) ) {
@sj26
sj26 / gist:1046117
Created June 25, 2011 03:48
String dedent/redent
class String
def dedent
indent = lines.reject(&:empty?).map { |line| line.index(/\S/) }.compact.min
gsub /^ {1,#{indent.to_i}}/, ''
end unless method_defined? :dedent
def redent prefix
prefix = " " * prefix if prefix.is_a? Numeric
dedent.gsub! /^(?=[ \t]*\S+)/, prefix
end unless method_defined? :redent
@technoweenie
technoweenie / gist:1072829
Created July 8, 2011 21:12
.netrc file so you can push/pull to https git repos without entering your creds all the time
machine github.com
login technoweenie
password SECRET
machine api.github.com
login technoweenie
password SECRET
@rtgibbons
rtgibbons / macvim.rb
Created September 17, 2011 01:44
Alloy's MacVim (File Browser)
require 'formula'
class Macvim < Formula
homepage 'http://code.google.com/p/macvim/'
version '7.3-61'
head 'https://github.com/alloy/macvim.git', :branch => 'split-browser'
def options
[
# Building custom icons fails for many users, so off by default.
@nanki
nanki / ffi-ruby.rb
Created November 3, 2011 13:59
FFI bridge to libruby.
require 'ffi'
module FFI::Ruby
class Value
class << self
extend ::FFI::Library
ffi_lib 'ruby'
attach_function :rb_obj_id, [:pointer], :pointer
attach_function :rb_num2long, [:pointer], :long
@paulirish
paulirish / data-markdown.user.js
Last active February 6, 2024 10:41
*[data-markdown] - use markdown, sometimes, in your HTML
// ==UserScript==
// @name Use Markdown, sometimes, in your HTML.
// @author Paul Irish <http://paulirish.com/>
// @link http://git.io/data-markdown
// @match *
// ==/UserScript==
// If you're not using this as a userscript just delete from this line up. It's cool, homey.