Skip to content

Instantly share code, notes, and snippets.

View kastner's full-sized avatar
🕳️
actively choosing...

Erik Kastner kastner

🕳️
actively choosing...
View GitHub Profile
<ol class="latest_uploads">
<%= render :partial => "composition", :collection => @playlist.listings.compositions %>
</ol>
class WebHook < ActiveRecord::Base
class << self
# Pushes a job onto a queue
def visit!(visit)
JobQueue.new(:events).push({
:type => 'visit',
:visit_id => visit.id,
:user_id => visit.user_id,
testapp
@kastner
kastner / 0what.md
Created August 26, 2009 21:18 — forked from defunkt/0what.md

Poor Man's Deploy

  • Start a Sinatra server on port 4000
  • GET / to that server triggers a git pull and mod_rails restart
  • Hit port 4000 locally after pushing

Why?

# Lo-fi client for the Facebook API. E.g.:
#
# fb = FacebookClient.new(:api_key => 'api-key', :secret => 'secret')
# fb.call 'users.getInfo', :session_key => 'session-key', :uids => 'user-id', :fields => 'birthday'
#
# by Scott Raymond <[email protected]>
# Public Domain.
#
class FacebookClient
def initialize(default_params={})
module Harmony
# Allows accessing config variables from harmony.yml like so:
# Harmony[:domain] => harmonyapp.com
def self.[](key)
unless @config
raw_config = File.read(Rails.root + "/config/harmony.yml")
@config = YAML.load(raw_config)[Rails.env].symbolize_keys
end
@config[key]
end
@kastner
kastner / gist:256876
Created December 15, 2009 11:49 — forked from evan/gist:256524
class Class
def memoize(*methods)
methods.each do |method_name|
safe_method_name = method_name.to_s.gsub(/(\!|\?)/, '_')
class_eval("
alias :'#{safe_method_name}_without_memo' :'#{method_name}'
def #{method_name}
if defined?(@#{safe_method_name})
@#{safe_method_name}
# This is how you can get a user's location using MacRuby and CoreLocation
framework 'CoreLocation'
def locationManager(manager, didUpdateToLocation: new_location, fromLocation: old_location)
puts "location: #{new_location.description}"
exit
end
loc = CLLocationManager.alloc.init
loc.delegate = self
def test_something_for_real
flunk <<-ABBOT_AND_COSTELLO
hey buddy, you should probably rename this file and start testing for real.
For Rael?
No real...
What's real? Rael?
Rael? You mean Rails?
Who's talking about Rails, all I want to know is if the test is for Rael...
ABBOT_AND_COSTELLO
end
# sometimes you really _do_ want a global...
# alternately, stick it as a method on a Module somewhere, App.logger or whatever, but it's still just as much of a smell.
# replace STDERR with your filename of choice.
$logger = Logger.new(STDERR)
$logger.formatter = proc { |severity, datetime, progname, msg|
"#{severity} - #{progname} - [#{datetime.strftime("%d/%m/%Y %H:%M:%S")}] #{msg}\n"
}
run(Rack::Builder.new {