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
`exiftool /Users/james/Desktop/james.psd`.split("\n").collect{|a| | |
[ | |
(array = a.split(':')).first.strip, | |
(array.shift && array).join(':').strip | |
] | |
} |
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
def verifed_facebook_autheticity(signature, params) | |
Digest::MD5.hexdigest((params.keys.sort.collect {|key| "#{key}=#{params[key]}"} << APP_CONFIG[:facebook_api_secret]).to_s).strip == signature | |
end |
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
# .gitattributes | |
*.pbxproj -crlf -diff -merge | |
# .gitignore | |
# xcode noise | |
build/* | |
*.pbxuser |
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> | |
<head> | |
<script src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script> | |
</head> | |
<body> |
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
def facebook_postback | |
if params[:session] && params[:session] != 'loggedout' && eval("params[:session] = #{params[:session].gsub(/\\"/, '"').gsub(/:/, ' => ')}") | |
access_denied unless verifed_facebook_autheticity(params[:session][:sig], {'expires' => params[:session][:expires], 'session_key' => params[:session][:session_key], 'ss' => params[:session][:secret], 'user' => params[:session][:uid]}) | |
session = Facebooker::Session.create(APP_CONFIG[:facebook_api_key], APP_CONFIG[:facebook_api_secret]) | |
facebook_user = Facebooker::User.new(params[:session][:uid], session) | |
begin | |
if logged_in? | |
link_facebook_account(facebook_user) | |
else | |
create_facebook_user(facebook_user) |
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 Circuit | |
def initialize(resistors) | |
@resistors = resistors | |
@final_node = 0 | |
@resistors.each do |(source, destination, resistance)| | |
@final_node = [@final_node, source, destination].max | |
end |
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 Polynomial | |
def initialize(coefficients) | |
@coefficients = coefficients.reverse # reverse so the index equates to the exponent of each coefficient | |
raise ArgumentError, 'Need at least 2 coefficients' if coefficients.size < 2 | |
end | |
def to_s | |
# Build an array of sprintfs, LIFO to get most significant order | |
@coefficients.inject([]) {|builder, coefficient| ["%+ix^%i" % [coefficient, builder.size]] + builder}.to_s. | |
gsub(/(\+0x\^\d+|x\^0|\^1\d{0})/, ''). # Clean out 0x^y, x^0, ^1 | |
gsub(/\d{0}1x/, 'x'). # Replace 1x with just x |
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 Hash | |
def symbolize_keys | |
inject({}) do |options, (key, value)| | |
options[(key.to_sym rescue key) || key] = value | |
options | |
end | |
end | |
def recursive_symbolize_keys | |
inject({}){|result, (key, value)| | |
new_key = case key |
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 Maze | |
Cardinals = Proc.new{|(x,y)| [[x-1,y],[x,y+1],[x+1,y],[x,y-1]].select{|c| c.min >= 0}} | |
MazeSeperator, MazeStart, MazeWall, MazeEnd, MazeOOB = "\n", 'A', '#', 'B', nil | |
Infinity = 1.0/0 | |
X, Y = 0, 1 | |
def initialize(maze) | |
raise ArgumentError, 'No end point' unless maze.include? MazeEnd | |
raise ArgumentError, 'No start point' unless maze.include? MazeStart |
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
# flushed out | |
has_a_braintree_customer do | |
attribute_map :firstname => :first_name, :lastname => :last_name | |
end | |
has_a_subscription do | |
plans {:mild => {:price => 0}, :medium => {:price => 500}, :spicy => {:price => 1000}} | |
default_plan :mild # default: plan with lowest price | |
billing_frequency 30.days, :grace_period => 5.days # default: 30.days, :grace_period => 5.days |
OlderNewer