Skip to content

Instantly share code, notes, and snippets.

View ggilder's full-sized avatar

Gabriel Gilder ggilder

View GitHub Profile
class Node
attr_accessor :next, :data
def push(str)
n = Node.new
n.data = str
node = self
next_node = nil
while node.next
@ggilder
ggilder / large_int_subtraction.js
Created April 16, 2012 00:04
Javascript subtracting from large integers
function LargeInt(str){
this.length = 0;
if (str){
Array.prototype.push.apply(this, String(str).split(''));
}
}
LargeInt.prototype = {
splice: Array.prototype.splice,
minus: function(subtrahend){
subtrahend = new LargeInt(subtrahend);
@ggilder
ggilder / blocks.rb
Created January 25, 2012 07:55
MacRuby bug with #method.call and blocks
class Foo
def bar
if block_given?
yield
else
puts "Foo#bar: please give me a block :("
end
end
end
@ggilder
ggilder / stub_method_chain.rb
Created January 17, 2012 23:05
Stub class or instance methods on anything!
class Object
def metaclass
class << self; self; end
end
def self.stub_method_chain chain, &blk
chain = chain.split('.') if chain.is_a? String
metaclass.instance_eval do
define_method chain.first do |*values|
Object.new.tap do |o|
@ggilder
ggilder / gist:1303804
Created October 21, 2011 13:06
fake drag and drop file access in safari
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=Content-type content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<form>
<input type="text" id="fileDrag" placeholder="Drag file here">
</form>
@ggilder
ggilder / gist:1055684
Created June 30, 2011 05:27
Use Sinatra to serve static files from the current directory
ruby -e "require 'rubygems';require 'sinatra';set :port, 9999;set :public, Dir.pwd"
@ggilder
ggilder / jquery.blocking_events.js
Created May 11, 2011 21:50
jQuery blocking events - prevent an event handler from re-triggering until you unblock it
(function($){
$.fn.blockingEvent = function(eventType, eventHandler){
var eventId = '_active_'+eventType;
this.bind(eventType, function(e){
e.preventDefault();
$this = $(this);
if ($this.data(eventId)){
return false;
}
$this.data(eventId, true);
@ggilder
ggilder / MacRuby crash log
Created April 8, 2011 17:40
MacRuby crash log
Process: Rosie [73166]
Path: [REDACTED]/build/Debug/Rosie.app/Contents/MacOS/Rosie
Identifier: com.tractionco.Rosie
Version: 0.1 (0.1)
Code Type: X86-64 (Native)
Parent Process: launchd [163]
Date/Time: 2011-04-08 10:36:27.248 -0700
OS Version: Mac OS X 10.6.7 (10J869)
Report Version: 6
@ggilder
ggilder / .htaccess
Created March 8, 2011 01:40
Using WordPress as a Subversion external
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# Make the admin still accessible from /wp-admin
RewriteCond %{REQUEST_URI} ^/wp-admin/?(.*)
RewriteRule .* wp/wp-admin/$1 [L,R=301]
# Base is the URL path of the home directory
RewriteBase /
RewriteRule ^$ wp/index.php [L]
# Skip real files and directories
@ggilder
ggilder / heroku+sinatra+memcached.txt
Created February 26, 2011 10:58
Random thoughts as I try to get memcached, sinatra, and heroku to play nice
sinatra-memcached doesn't work with heroku
because memcache-client doesn't work with heroku
okay, let's rewrite sinatra-memcached to work with dalli, heroku's recommended memcached client
hmm, dalli isn't working on my local install so i can't really test it
why is it failing to connect to localhost?
hmm, dalli requires memcached 1.4+, let's make sure i'm running that
huh, 1.2.8, that's weird because i just installed memcached
`brew info memcached` says it should be in /usr/local/bin, right...
and yet `which memcached` says /usr/bin. uh... wtf
ok, let's just symlink the new memcached into /usr/bin, why the fuck not