Skip to content

Instantly share code, notes, and snippets.

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

Samuel Cochran sj26

🤹‍♂️
View GitHub Profile
@gstamp
gstamp / gist:4be38062f500f67e70f8
Last active August 29, 2015 14:04
TPPI Server Info

Welcome to TPPI!

You're probably here because you've been invite to play on the TPPI minecraft server. This server is currently running at an undisclosed location through the power of the NBN.

To play you'll need to do the following:

  • Have your account explicitly whitelisted - please send through your exact login name to sj26.
  • Install a copy of Feed the Beast (http://www.feed-the-beast.com/).

Installation

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}" }
@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'}
@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
@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.
@ndbroadbent
ndbroadbent / .gitattributes
Created January 11, 2012 08:35 — forked from tpope/.gitattributes
Fewer conflicts in your Rails apps
Gemfile.lock merge=bundleinstall
db/schema.rb merge=railsschema
@sj26
sj26 / php_postgresql.rb
Created February 22, 2012 12:21
Homebrew formula for PHP PostgreSQL extensions
require 'formula'
require 'net/http'
# This is an odd formula which adapts itself to whatever version of PHP
# is installed with the current version of OS X to install the missing
# PostgreSQL extension.
class PhpPostgresql < Formula
homepage 'http://www.php.net/'
# author: Samuel Cochran <sj26@sj26.com>
@sj26
sj26 / rspec_with_translations.rb
Created March 14, 2012 03:42
Temporarily swap in I18n translations for a context
module RSpecWithTranslations
def with_translations *args, &block
translations = args.extract_options!
args = args.presence || ["with translations"]
context *args do
around do |example|
begin
old, I18n.backend = I18n.backend, I18n::Backend::KeyValue.new(translations)
example.call
@funny-falcon
funny-falcon / perf_and_gc.diff
Created May 4, 2012 08:47
Ruby-1.9.3-p194 performance patch
diff --git a/common.mk b/common.mk
index eb89a2b..59cdfe4 100644
--- a/common.mk
+++ b/common.mk
@@ -630,7 +630,8 @@ file.$(OBJEXT): {$(VPATH)}file.c $(RUBY_H_INCLUDES) {$(VPATH)}io.h \
gc.$(OBJEXT): {$(VPATH)}gc.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h \
{$(VPATH)}regex.h $(ENCODING_H_INCLUDES) $(VM_CORE_H_INCLUDES) \
{$(VPATH)}gc.h {$(VPATH)}io.h {$(VPATH)}eval_intern.h {$(VPATH)}util.h \
- {$(VPATH)}debug.h {$(VPATH)}internal.h {$(VPATH)}constant.h
+ {$(VPATH)}debug.h {$(VPATH)}internal.h {$(VPATH)}constant.h \