This file contains hidden or 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
Exercise 1.11 | |
(define (recursive-f n) | |
(if (< n 3) | |
n | |
(+ (recursive-f (- n 1)) | |
(* 2 (recursive-f (- n 2))) | |
(* 3 (recursive-f (- n 3)))))) | |
This file contains hidden or 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
Exercise 1.14 | |
Order of growth is O(3n) NOTE: this is my result by I've seen elsewhere different results. | |
Exercise 1.15 | |
p is evaluated 5 times | |
order of growth is O(log n) because the amount of resource needed is constant. | |
This file contains hidden or 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
module ActiveRecord | |
module Acts | |
module TaggableOn | |
module SingletonMethods | |
def find_options_for_tag_counts(options = {}) | |
options.assert_valid_keys :start_at, :end_at, :conditions, :at_least, :at_most, :order, :limit, :on, :id | |
scope = scope(:find) | |
start_at = sanitize_sql(["#{Tagging.table_name}.created_at >= ?", options.delete(:start_at)]) if options[:start_at] | |
end_at = sanitize_sql(["#{Tagging.table_name}.created_at <= ?", options.delete(:end_at)]) if options[:end_at] |
This file contains hidden or 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
import oauth.oauth as oauth | |
import httplib | |
class ZooppaClient(object): | |
# consumer_key, consumer_secret are your api key and secret as strings | |
def __init__(self, consumer_key, consumer_secret): | |
self.consumer = oauth.OAuthConsumer(consumer_key, consumer_secret) | |
self.host = 'localhost' | |
self.port = 3000 | |
if self.port == 80: |
This file contains hidden or 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 oauth | |
OAuth::Consumer.new( | |
consumer_key, | |
consumer_secret, | |
{ | |
:site => 'https://api.login.yahoo.com', | |
:scheme => :query_string, | |
:http_method => :get, | |
:request_token_path => '/oauth/v2/get_request_token', | |
:access_token_path => '/oauth/v2/get_token', |
This file contains hidden or 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 distribution_chart_helper(width,height,sent,click, hist_sent, hist_click) | |
max_val = [sent,click, 1].max | |
hist_max_val = [hist_sent, hist_click, 1].max | |
hist_sent = max_val.to_f * hist_sent / hist_max_val.to_f | |
hist_click = max_val.to_f * hist_click / hist_max_val.to_f | |
data = [sent,click, hist_sent, hist_click].map{|d| [d,0.01].max}.join("|") | |
legend = "sent|clicks" | |
data_labels = (0..1).map{|i| "N*f0*,000000,#{i},-1,11"}.join("|") |
This file contains hidden or 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 User | |
setName: (name) -> | |
@name = name | |
class Programmer | |
user = new User | |
programmer = new Programmer | |
user.setName.apply programmer, ['Oscar'] |
This file contains hidden or 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
while read rev; do | |
git diff $rev | | |
grep foo; | |
done |
This file contains hidden or 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
<form class="my_form"> | |
<a class="my_link"></a> | |
</form> | |
<script type="text/javascript"> | |
$('.my_form').live('ajax:success', | |
// this gets triggered when I click on my_link, I don't want that | |
) | |
$('.my_link').live('ajax:success', |
This file contains hidden or 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 Foo | |
def speak | |
'hello' | |
end | |
end | |
my_proc = Proc.new do |event, file, line, id, binding, classname| | |
printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname | |
while cmd = gets.chomp do | |
if cmd == 'n' |