Skip to content

Instantly share code, notes, and snippets.

View cmhobbs's full-sized avatar
🍩
Waiting between the walls.

Christopher M. Hobbs cmhobbs

🍩
Waiting between the walls.
View GitHub Profile
require 'rubygems'
require 'sinatra'
require 'redis'
# To use, simply start your Redis server and boot this
# example app with:
# ruby example_note_keeping_app.rb
#
# Point your browser to http://localhost:4567 and enjoy!
#
@tmm1
tmm1 / iterator.rb
Created October 30, 2009 08:28
simple eventmachine async iterator
module EventMachine
# A simple iterator for concurrent asynchronous work.
#
# Unlike ruby's built-in iterators, the end of the current iteration cycle is signaled manually,
# instead of happening automatically after the yielded block finishes executing. For example:
#
# (0..10).each{ |num| }
#
# becomes:
#
@gravis
gravis / resque_schedule_retry_job.rb
Created February 9, 2010 20:24
A resque job with retry on failure, dead simple. Needs resque-schedule plugin. the only caveat is that the first attempt is in the "events" queue, whereas retries are only visible in Delayed tab.
class GetEventResult
@queue = :events
def self.perform(event_id, attempt=0)
event = Event.find(event_id)
Rails.logger.info "Fetching results for event ##{event.id} (#{event.name})..."
begin
results = EventImporter.new(event.datetime.to_date).get_results(event)
rescue OpenURI::HTTPError
@vangberg
vangberg / DWM-ON-OS-X.md
Created February 22, 2010 19:24
dwm on os x [work in progress!]

Installing and configuring dwm on OS X

  1. Install XQuartz (http://xquartz.macosforge.org) which is the development version of the X11.app that ships with OS X, which means it is way more up to date. I have had some weird issues with X11.app v. 2.3-something. XQuartz 2.5.0 fixed that.

  2. Install dwm from Homebrew, brew install dwm. This makes a bunch of necessary tweaks to the DWM configuration.

  3. Add the following script to $PATH, name it dwm-launch and chmod 755:

    cd ~
    

while true

@addamh
addamh / gist:708372
Created November 21, 2010 02:12
ssh debug output for addamh on libernil
OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009
debug1: Reading configuration data /etc/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to libernil.org [69.164.201.146] port 1001.
debug1: Connection established.
debug1: identity file /Users/addam/.ssh/identity type -1
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug2: key_type_from_name: unknown key type 'Proc-Type:'
debug2: key_type_from_name: unknown key type 'DEK-Info:'
debug2: key_type_from_name: unknown key type '-----END'
[05:21][hobbsc@arrakis:~/dev/billing(codereview)]$ bundle install
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.9/lib/bundler/ui.rb:56:in `<class:UI>': uninitialized constant Gem::SilentUI (NameError)
from /usr/local/rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.9/lib/bundler/ui.rb:2:in `<module:Bundler>'
from /usr/local/rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.9/lib/bundler/ui.rb:1:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.9/lib/bundler/cli.rb:16:in `initialize'
from /usr/local/rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.9/lib/bundler/vendor/thor.rb:246:in `new'
from /usr/local/rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.9/lib/bundler/vendor/thor.rb:246:in `dispatch'
from /usr/local/rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.9/lib/bundler/vendor/thor/base.rb:389:in `start'
from /usr/local/rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.9/bin/bundle:13:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p136/b
@cmhobbs
cmhobbs / kvminst.sh
Created March 18, 2011 01:17
hack script to install/setup kvm
#!/usr/bin/env bash
# Quick and dirty KVM setup script.
cat << EOT
THIS SCRIPT SHOULD GET YOU UP AND RUNNING WITH KVM.
HERE'S THE PROCESS:
- UPDATE YOUR SYSTEM
- INSTALL KVM'S REQUIRED PACKAGES
- ADD YOUR USER TO THE NECESSARY GROUPS
# Sort lexicographically, but sorting numbers into their proper position.
# Ruby 1.9 only as the zero-width lookbehind assertions require Oniguruma.
#
class Array
def sort_preserving_numbers
sort_by { |x|
x.split(%r{(?<=\D)(?=\d)|(?<=\d)(?=\D)}).
map { |piece| (piece =~ /\A\d+\z/) ? piece.to_i : piece }
}
end
class ActiveRecord::Base
attr_accessible nil
def update_attributes *args
raise "Don't call #{self.class.name}#update_attributes. " +
"Mass assignment is pure evil."
end
end
@cmhobbs
cmhobbs / uploader.go
Created August 3, 2012 04:21
Handling multipart file uploads with goweb
package main
import (
"code.google.com/p/goweb/goweb"
"io/ioutil"
)
// dummy error struct for pretty json export
type ControllerError struct {
Error error