Skip to content

Instantly share code, notes, and snippets.

View timuruski's full-sized avatar
🏳️‍⚧️
Protect Trans Rights

Tim Uruski timuruski

🏳️‍⚧️
Protect Trans Rights
View GitHub Profile
@timuruski
timuruski / helper-stubbing-blues.rb
Created August 12, 2011 03:48
Sinatra sings the helper stubbing blues
require 'sinatra/base'
require 'rack/test'
class MyApp < Sinatra::Base
disable :show_exceptions
helpers do
def msg
"hello world"
end
@timuruski
timuruski / toh.rb
Created August 16, 2011 19:02
Gold star for anyone who can figure out what toh means
plugins= get_plugins()
toh= plugins.is_logged_in(authDevice._id.to_s)
if toh
to= toh["to"]
foreign_id= toh["foreign_id"]
username= to + ":" + foreign_id
authUser= AuthUser.find_by_username(username)
# ...
end
@timuruski
timuruski / build-a-hash.rb
Created August 16, 2011 20:40
There has to to be a better way to build a hash.
def get_providers()
plugins= get_plugins()
ary= plugins.get_providers()
h= {}
h["providers"] = ary
h
end
# Why not do this?
def get_providers
describe "#GET /3.x/auth/:to/callback" do
it "creates a callback-request" do
any_instance_of(API::Authentication::Service::CallbackRequest) do |callback|
# Smell a refactor? I do.
mock(callback).code=('foo')
mock(callback).state=('bar')
mock(callback).error_description=('')
mock(callback).to=('facebook')
end
@timuruski
timuruski / hack-1.md
Created August 22, 2011 21:46
Hack Night project

Basic Hack-Night Arbiter

  • User can start a hack-night with a list of emails
  • Emails are sent to users with URL to provide availability
  • Users can mark their availabilities per night for 2-week window
  • Once all availabilities are provided, a series of overlapping nights is presented

Advanced topics might include deciding on a topic, each hack could have a silly name to make it memorable after large amounts of drinking.

Requirements

$ cd ~/workspace/tmp/
$ git clone git://gist.github.com/1163698.git gist-1163698
> ...
$ cd gist-1163698/
$ git remote add brett git://gist.github.com/1168323.git gist-1168323
$ git remote add steve git://gist.github.com/1168327.git
$ git fetch brett
> ...
> From git://gist.github.com/1168323
> * [new branch] master -> brett/master
class Externalsource
include MongoMapper::Document
one :media_asset, :as => :icon
end
class List
include MongoMapper::Document
one :media_asset, :as => :icon
end
@timuruski
timuruski / creds.rb
Created August 30, 2011 23:32
Are we clear?
def get_creds(a)
creds= Creds.new
creds.level_of_access= nil
if a
# ...
end
creds
end
@timuruski
timuruski / generate_token.rb
Created August 31, 2011 21:01
A concise way to generate random values until a unique one is found.
class Device
include MongoMapper::Document
key :token, :unique => true, :default = lambda { generate_token }
def self.generate_token
token = ActiveSupport::SecureRandom.hex until token_available?(token)
token
end
@timuruski
timuruski / string_construction.rb
Created September 2, 2011 15:43
Strategy for handling user-submitted formatting strings.
class Post
def initialize(category, slug)
@category = category
@slug = slug
end
# Ghetto but descriptive
def generate_url_sub(template)
template.sub('$category', @category.to_s).sub('$slug', @slug.to_s)
end