Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Havens andrewhavens

View GitHub Profile
@andrewhavens
andrewhavens / index.html
Created Apr 17, 2014
broken jQuery file upload example
View index.html
<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 Nov 4, 2011
Buggy event machine code
View websocket_server.rb
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 Nov 28, 2011
auto-registering child classes with instance variables
View sample.rb
# 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 Jan 6, 2012
MacRuby web browser, needs links to open default browser
View AppDelegate.rb
framework "WebKit"
class AppDelegate
attr_accessor :window
def applicationDidFinishLaunching(notification)
load_web_view
end
def load_web_view
@andrewhavens
andrewhavens / gist:1573056
Created Jan 6, 2012
Table with row groups
View gist:1573056
<table class="tablesorter">
<thead>
<tr>
<th>name</th>
</tr>
</thead>
<tbody>
<!-- group 1 -->
<tr class="top">
@andrewhavens
andrewhavens / spec_helper.rb
Created Feb 17, 2012
example rspec helper
View spec_helper.rb
require 'simplecov'
SimpleCov.start
require 'my_gem'
require 'rspec/mocks'
RSpec.configure do |config|
config.mock_framework = :rspec
end
@andrewhavens
andrewhavens / gist:2023640
Created Mar 12, 2012
error installing redis with homebrew
View gist:2023640
$ 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 Jul 10, 2012
An example of a custom Zend Framework route that results in a 301 redirect
View Bootstrap.php
<?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);
}
View gist:3902832
/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)>'
View gist:3902804
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'