Skip to content

Instantly share code, notes, and snippets.

View andrewhavens's full-sized avatar

Andrew Havens andrewhavens

View GitHub Profile
@andrewhavens
andrewhavens / index.html
Created April 17, 2014 18:37
broken jQuery file upload example
<h1>Upload Documents</h1>
<form action="/documents" enctype="multipart/form-data" id="fileupload" method="post">
<input type="file" name="document[attachment][]" multiple="multiple">
<table>
<tbody id="files" class="files"></tbody>
</table>
</form>
<!-- jQuery 1.8.3 already included -->
@andrewhavens
andrewhavens / websocket_server.rb
Created November 4, 2011 03:07
Buggy event machine code
require 'rubygems' # I'm getting this error when I try to run this file:
require 'em-websocket' # websocket_server.rb:62: syntax error, unexpected $end, expecting keyword_end
require 'json'
class ChatMessage
attr_accessor :type, :username, :message
def initialize(msg_json)
msg = JSON.parse(msg_json)
@andrewhavens
andrewhavens / sample.rb
Created November 28, 2011 15:50
auto-registering child classes with instance variables
# This is all mostly working except for the "on_message" class method.
# It needs to set the regex and block as a variable that can be accessed later from an instance of the class.
class MyExtension < ExtensionBase
on_message '/join (.+)' do |username|
# this will be a callback function used later
end
end
@andrewhavens
andrewhavens / AppDelegate.rb
Created January 6, 2012 21:13
MacRuby web browser, needs links to open default browser
framework "WebKit"
class AppDelegate
attr_accessor :window
def applicationDidFinishLaunching(notification)
load_web_view
end
def load_web_view
@andrewhavens
andrewhavens / gist:1573056
Created January 6, 2012 23:51
Table with row groups
<table class="tablesorter">
<thead>
<tr>
<th>name</th>
</tr>
</thead>
<tbody>
<!-- group 1 -->
<tr class="top">
@andrewhavens
andrewhavens / spec_helper.rb
Created February 17, 2012 21:11
example rspec helper
require 'simplecov'
SimpleCov.start
require 'my_gem'
require 'rspec/mocks'
RSpec.configure do |config|
config.mock_framework = :rspec
end
@andrewhavens
andrewhavens / gist:2023640
Created March 12, 2012 17:54
error installing redis with homebrew
$ brew install -v redis
==> Downloading http://redis.googlecode.com/files/redis-2.4.8.tar.gz
File already downloaded in /Users/andrew/Library/Caches/Homebrew
/usr/bin/tar xf /Users/andrew/Library/Caches/Homebrew/redis-2.4.8.tar.gz
==> make -C src
make -C src
MAKE hiredis
CC ae.o
CC anet.o
CC redis-benchmark.o
@andrewhavens
andrewhavens / Bootstrap.php
Created July 10, 2012 15:20
An example of a custom Zend Framework route that results in a 301 redirect
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initCustomRoutes()
{
$router = Zend_Controller_Front::getInstance()->getRouter();
$route = new Mylib_Controller_Router_Route_Redirect('old/route/*', array('controller'=>'content', 'action'=>'index'));
$router->addRoute('old_route', $route);
}
@andrewhavens
andrewhavens / gist:3902832
Created October 16, 2012 23:48
thin error
/Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-websocket-0.4.6/lib/faye/adapters/thin.rb:26:in `<top (required)>': cannot load such file -- thin/connection (LoadError)
from /Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-websocket-0.4.6/lib/faye/websocket.rb:66:in `require'
from /Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-websocket-0.4.6/lib/faye/websocket.rb:66:in `load_adapter'
from /Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-websocket-0.4.6/lib/faye/websocket.rb:214:in `block in <top (required)>'
from /Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-websocket-0.4.6/lib/faye/websocket.rb:212:in `each'
from /Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-websocket-0.4.6/lib/faye/websocket.rb:212:in `<top (required)>'
from /Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye.rb:7:in `require'
from /Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye.rb:7:in `<top (required)>'
@andrewhavens
andrewhavens / gist:3902804
Created October 16, 2012 23:44
faye error
2012-10-16 16:42:22 [ERROR] [Faye::RackAdapter] undefined method `call' for nil:NilClass
Backtrace:
/Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/adapters/rack_adapter.rb:121:in `block in handle_request'
/Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/protocol/server.rb:46:in `call'
/Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/protocol/server.rb:46:in `block in process'
/Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/protocol/server.rb:58:in `call'
/Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/protocol/server.rb:58:in `block (3 levels) in process'
/Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/protocol/extensible.rb:23:in `call'
/Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/protocol/extensible.rb:23:in `pipe_through_extensions'
/Users/andrew/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/protocol/server.rb:55:in `block (2 levels) in process'