Skip to content

Instantly share code, notes, and snippets.

View wmw's full-sized avatar

William Warnecke wmw

  • California
  • X @ww
View GitHub Profile
@wmw
wmw / to_hash.rb
Created February 2, 2011 23:54
Implementing a to_hash function for a class in ruby.
class Balls
def initialize()
@name = 'blah'
@caption = 'blah'
end
def to_hash
hash = self.instance_variables.inject({}) do |a, e|
hash = {e[1..-1] => self.instance_variable_get(e)}
module ExternalRelations
class Linkage
def initialize(relation, caller, opts)
opts = opts.clone
@key = (opts.delete(:id) || :id)
@caller = caller
@target = relation.to_s.singularize.camelize.constantize.scoped.where(:"#{@caller.class.to_s.downcase}_id" => @caller.send(@key))
end
def <<(new_link_target)
@wmw
wmw / pylog.py
Created September 11, 2013 17:52
logging python stuff
#!/usr/bin/python
import logging
import logging.handlers
import json
#
# http://docs.python.org/2/howto/logging-cookbook.html#implementing-structured-logging
#
@wmw
wmw / twitch.bat
Created October 13, 2013 21:15
livestreamer with stream name
cd c:\program files (x86)\livestreamer
set /p streamName=What stream?:
livestreamer.exe -url twitch.tv/%streamName% best
import sys
import getopt
import re
class Field:
def __init__(self, key, desc, typeinfo):
self.key = key
self.desc = desc
self.typeinfo = typeinfo