Skip to content

Instantly share code, notes, and snippets.

Xavier Shay xaviershay

Block or report user

Report or block xaviershay

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@xaviershay
xaviershay / service_service.rb
Created Sep 16, 2012 — forked from tobias/service_service.rb
A TorqueBox service that consumes from a queue.
View service_service.rb
class ServiceService
def initialize(options)
@queue = TorqueBox::Messaging::Queue.new( '/queues/service_request' )
@running = true
end
def start()
Thread.new do
while @running
View vegan-with-an-iphone.md

Moral questions for veganism

Hypothetically, you are a vegan with an iPhone.

Your choice to become a vegan was because you determined it to be morally correct.

Your moral evaluation is based primarily on two considerations

  • That factory farming is harming the environment
  • That treating animals inhumanely is, well, inhumane
View atomic.rb
module ActiveRecord
class Base
def atomic &block
transaction {
lock!
yield
}
end
end
end
View page.rb
Refactor this code: URL Matching Edition
--
So I have Pages, in a nested set so that each page has parent. That allows me to have urls like:
/foo/bar
where the Page with permalink 'foo' has a child with the permalink 'bar'. In my routes.rb I have a general catch-all route as my last route.
map.page '/*tree', :controller => 'pages', :action => 'show'
View gist:49265
function parse_git_dirty {
git diff --quiet || echo " *"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1$(parse_git_dirty))/"
}
export PS1='\w $(parse_git_branch)\$ '
View gist:41148
// Original
(function($) {
$.stuff = function(bitoftext) {
$.stuff.report = function() { console.log(bitoftext) };
}
$.stuff.report = function() {
throw("Constructor not called!");
}
View fizzbuzz_midi.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'midiator'
# Upped the tempo, reveals new curiosities
midi = MIDIator::Interface.new
midi.use("dls_synth")
#midi.autodetect_driver
View with.rb
# DRY temporary variables that require single use only, without assignment... seems
# useful for configuration files perhaps? urgh.
class Object
def with(object)
yield(object)
end
end
@reports = []
You can’t perform that action at this time.