Skip to content

Instantly share code, notes, and snippets.

View ggilder's full-sized avatar

Gabriel Gilder ggilder

View GitHub Profile
@ggilder
ggilder / restoreObjcMethodSignature.rb
Created October 19, 2010 04:28
Restore an Objective-C method signature from MacRuby's automatic Ruby-style conversion (such as that passed to method_missing)
# Takes an Objective-C method signature, automatically converted to "Ruby-style" by MacRuby, and restores it.
# Restored method and arguments are returned in an array.
def restoreObjcMethodSignature(method, args)
if ((args.length == 2) && (args[1].is_a? Hash))
method = method+':'+args[1].keys.join(':')
args = [args[0], *args[1].values]
end
[method, args]
end
@ggilder
ggilder / TextMate_scriptmate_fix.rb
Created November 3, 2010 22:35
Fix TextMate's scriptmate.rb to work with Ruby 1.9
# located at /Applications/TextMate.app/Contents/SharedSupport/Support/lib/scriptmate.rb
# change lines 12 - 13:
$KCODE = 'u' if (RUBY_VERSION.to_f < 1.9)
require "jcode" unless "".respond_to? :each_char
# rest of the file is unchanged
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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