Skip to content

Instantly share code, notes, and snippets.

View nuclearsandwich's full-sized avatar

Steven! Ragnarök nuclearsandwich

View GitHub Profile
@nuclearsandwich
nuclearsandwich / christmas.py
Created December 25, 2010 18:39
The Python program I used to make sure my brother's grades allowed him to get his Christmas present.
View christmas.py
print("Welcome Jeremy, we've been waiting for you.")
print("We're going to find out if you've been naughty or nice.")
print("Enter your grades one line at a time, then put DONE")
cipher = "Orrn#wr#wkh#ohiw#ri#wkh#Dufdgh#Fdelqhw"
grades = []
grade = input()
@nuclearsandwich
nuclearsandwich / mysqldump_pre_commit_hook.bash
Created April 6, 2011 00:30
A pre-commit hook for git which dumps and adds a mysql database to the repository just before commit.
View mysqldump_pre_commit_hook.bash
#!/bin/bash
# Pre-commit hook to make a mysql dump right before committing and add it to the commit.
#
## Change the following values to suit your local setup.
# The name of a database user with read access to the database.
DBUSER=root
# The password associated with the above user. Leave commented if none.
#DBPASS=seekrit
# The database associated with this repository.
DBNAME=dplay
@nuclearsandwich
nuclearsandwich / recurse.bash
Created April 20, 2011 05:48
An Archlinux script to refresh Identicurse.
View recurse.bash
#!/bin/bash
# reCurse
# =======
# Identicurse is awesome. Using the Git development branch is fun!
# But sometimes it crashes! o...o
# When that happens I feel obligated to file a bug report.
# But before I file a bug report, I should pull the latest HEAD from master to
# check if the bug is still present.
# It can get old fast... real fast.
# So I made that process easier for Archlinux folken.
@nuclearsandwich
nuclearsandwich / snidely_poll.rb
Created June 28, 2011 06:53
Which of these would you want to use forever?
View snidely_poll.rb
# Which ones. Pick one number and one letter. Reply back to
# @nuclearsandwich on identi.ca or @_nuclearsammich on Twitter.
# 1) .snidelyrc
# 2) .snidely
# 3) Snidefile
# 4) Snidely
# 5) Snidefile
# A)
Snidely.render do |configs|
@nuclearsandwich
nuclearsandwich / a_look_at_case_expressions.rb
Created July 28, 2011 19:28
A Look at Case Expressions in Ruby
View a_look_at_case_expressions.rb
# A Look at Case Expressions in Ruby
# ==================================
#
# *Side note: Playing with docco as a formatting tool for this article. Excuse
# the lines with solitary* `:parabreak` *symbols, they're to make paragraphs on the
# right hand side.*
#
# Ruby, like many languages has a case-when construct for more refined
# conditional execution than if-then-else can provide. Technically all case
# constructs could be written as if-then-else-if-then...else but you wouldn't
@nuclearsandwich
nuclearsandwich / html.rb
Created August 31, 2011 21:08
Hacktastic HTML DSL
View html.rb
# Only working example so far HTML.new { html { title { "Hello" } } }
# Soon attributes will be working.
class HTML
def initialize &content
@html = ""
instance_eval &content
end
def method_missing tag, *attrs, &content
@nuclearsandwich
nuclearsandwich / grr_active_record.rb
Created September 9, 2011 19:26
ActiveRecord's untraceable monkey patch on Enumerable#find(*args)
View grr_active_record.rb
# A has_many relation exists between a Twitter account and mentions.
# An instance of the collection of mentions is of class Array, rather than any kind of ActiveRecord relation. So one would assume that standard Enumerable methods work. But...
pry(Api)> cd Account::Twitter.last
pry(#<Api::Account::Twitter:0x10748de58>):1> mentions.class
=> Array < Object # Regular old array.
pry(#<Api::Account::Twitter:0x10748de58>):1> mentions.method :find
=> Array (Enumerable)#find(*arg1) # Looks like #find was defined in Enumerable and so should be Enumerable's find (hint: It isn't)
pry(#<Api::Account::Twitter:0x10748de58>):1> mentions.find { true } # This should return the first element in the Array.
ActiveRecord::RecordNotFound: Couldn't find Aji::Mention without an ID
from /Users/steven/.rvm/gems/ruby-1.9.2-p290@api/gems/activerecord-3.0.10/lib/active_record/relation/finder_methods.rb:287:in `find_with_ids'
View gist:1306138
Routing Error
No route matches {:action=>"show", :controller=>"programs", :user_id=>nil, :id=>#<Program _id: BSON::ObjectId('4ea2132db7e9fe27ce000001'), author_username: "nuclearsandwich", slug: "test", source_code: "Shoes.app do\n stack do\n 3.times do\n para \"Hello World!\", :font => \"TakaoGothic\"\n end\nend\n", title: "test">}
@nuclearsandwich
nuclearsandwich / hacket-stack
Created October 24, 2011 19:24
Hackety Hack crashed while I was fiddling with Shoes
View hacket-stack
Process: hacketyhack-bin [16501]
Path: /Applications/Hackety Hack.app/Contents/MacOS/./hacketyhack-bin
Identifier: org.hackety.hacketyhack
Version: 0.r1321 (???)
Build Info: Shoes-1200000~1
Code Type: X86-64 (Native)
Parent Process: bash [16499]
Date/Time: 2011-10-23 18:54:53.863 -0700
OS Version: Mac OS X 10.6.7 (10J4139)
@nuclearsandwich
nuclearsandwich / gist:1333254
Created November 2, 2011 09:32
NOWBOX Gemfile
View gist:1333254
gem 'rake'
gem 'thor' # Better command line utility than rake.
gem 'foreman' # Local process monitor.
gem 'grape', :git => 'git://github.com/intridea/grape.git'
gem 'sinatra', :require => 'sinatra/base'
gem 'thin' # Heroku recommends the Thin web server.
gem 'resque', :require => [ 'resque', 'resque/failure/redis' ]
gem 'typhoeus' # Better, Faster HTTP API for Faraday connections
gem 'hiredis' # Fast C Interface to Redis.
gem 'redis', :require => [ 'redis/connection/hiredis', 'redis' ]