This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# delicious helper | |
def dlify_hash(hash) | |
'<dl>'+"\n"+hash.collect{|k,v| | |
"\t<dd>#{k}</dd><dt>#{v}</dt>" | |
}.join("\n")+"\n"+'</dl>' | |
end | |
# Or, if you're a sick bastard like me and don't care if you've got layout logic monkeypatched into Ruby Core: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FooController < ApplicationController | |
after_filter 'run_some_magic' | |
def run_some_magic | |
StatsMagic.whoa('holy crap') | |
end | |
end | |
class StatsMagic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Remoteling: | |
- redis server, everybody gets a private redis slice | |
- starling FIFO queue server, everybody can push & pop to it | |
- remoteling queue | |
- I can fire off processes that execute remotely from my app | |
- I can set up N resident processes running on the remoteling server | |
- Easy producer/consumer model | |
- Billing? Information gathering when new users show up? (see example A below) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num = 4.0 | |
pi = 0 | |
plus = true | |
den = 1 | |
while den < 100000000 | |
if plus | |
pi = pi + num/den | |
plus = false | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rip lots from activerecord as well as datamapper | |
# ruby's duck typed. a k/v store should be duck typed. therefore why the hell do I care to set the ID to be type of integer if it's just gonna get stuffed in memory somewheres? | |
class User < Thunderbucket::Base | |
has_many :comments | |
belongs_to :user_group | |
attributes :name, :password, :email | |
# - or - | |
attributes true # i can set anything that's not a method to anything, not sure if i wanna actually implement this, could be too dangerous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:loaded_attributes: | |
:object: 18610940 | |
:attributes: | |
- name | |
- last_login_at | |
- last_request_at | |
- updated_at | |
- crypted_password | |
- single_access_token | |
- perishable_token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NOW=`date +%d-%b` | |
USER="root" | |
PASSWORD="lolwat" | |
OUTPUTDIR="/backup/databases/$NOW" | |
MYSQLDUMP="mysqldump" | |
MYSQL="mysql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CONTROLLER | |
if $INVITE_ONLY and (params[:invite_key] != @user.invite_key) then | |
flash.now[:error] = t 'account.invalid_invite' | |
render :action => :new | |
else | |
if @user.save | |
flash[:notice] = t 'account.created' | |
redirect_to account_path | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#hat tip @bear454 | |
require 'rubygems' | |
require 'uri' | |
require 'resolv' | |
def ip_to_color(ip,alpha = false) | |
segments = ip.split('.').collect{|s| s.to_i.to_s(16).rjust(2,'0') } | |
segments.pop unless alpha | |
segments.join('') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Before the Rails request | |
--- | |
- SERVER_NAME | |
- PATH_INFO | |
- HTTP_ACCEPT_ENCODING | |
- HTTP_USER_AGENT | |
- rack.url_scheme | |
- rack.run_once | |
- rack.input | |
- SCRIPT_NAME |
OlderNewer