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
a = [1,2,3,4,4] | |
def mode(a) | |
h = {()} # what are these parentheses? | |
a.length.times do |i| | |
# Code block? | |
end | |
end |
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
############## views/products/_trending.html.erb ############### | |
<% @products.each do |product| %> | |
<div class="product"> | |
<%= link_to (image_tag product.thumbnail), product %> | |
<div class="product-overlay-details"> | |
<%= product.name %>... | |
</div> | |
</div> | |
<% end %> |
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
#!/usr/bin/env ruby | |
# Print the vaportrail of a ruby file in a git repo, i.e., | |
# the complexity level at each commit. | |
# | |
# Requires: >= bash ?.? | |
# >= git 1.7.1 | |
# >= ruby 1.9.2 | |
# >= flog 2.5.0 | |
# |
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
require 'httparty' | |
require 'json' | |
class Campfire | |
include HTTParty | |
base_uri 'https://YOUR_DOMAIN.campfirenow.com' | |
basic_auth 'YOUR_API_KEY', 'X' # yes, that is a literal X string. it's needed to satisfy basic_auth(), but campfire ignores it. | |
headers 'Content-Type' => 'application/json' | |
def self.speak(message) |
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
require "hpricot" # need hpricot and open-uri | |
require "open-uri" | |
require "date" | |
current_date = Date.civil(2007, 6, 16) | |
while (current_date != Date.today) | |
puts [current_date, fetch_number_of_assaults(current_date)].join(":") | |
current_date = current_date.next | |
end |
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
require "hpricot" # need hpricot and open-uri | |
require "open-uri" | |
require "date" | |
current_date = Date.civil(2007, 6, 16) | |
while (current_date != Date.today) | |
puts "#{ current_date }:#{ fetch_number_of_assaults(current_date) }" | |
current_date = current_date.next | |
end |
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
(define (cbrt-iter guess x) | |
(if (good-enough? guess x) | |
guess | |
(cbrt-iter (improve guess x) | |
x))) | |
(define (improve guess x) | |
(/ (+ (/ x (* guess guess)) (* 2 guess)) 3)) | |
(define (good-enough? guess x) |
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
(define (good-enough? guess x) | |
(< (abs (- (square guess) x)) 0.001)) | |
;; The good-enough? test used in computing square roots will not be | |
;; very effective for finding the square roots of very small numbers. Explain. | |
;; | |
;; good-enough? is not effective for small numbers because the square | |
;; of a small number minus the number quickly becomes less than 0.001. | |
(sqrt 0.00001) |
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
;; What happens when Alyssa uses new-if is that all of new-if's | |
;; "arguments" are evaluated and then given to new-if, as opposed | |
;; to the special form of "if" where the "else" clause is only | |
;; evaluated if the predicate is false. Since there is a | |
;; recursive call in the "else" clause, the call never returns. |
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
;; SICP 1.5 | |
;; Given: | |
;; | |
;; (define (p) (p)) | |
;; | |
;; (define (test x y) | |
;; (if (= x 0) | |
;; 0 | |
;; y)) |
NewerOlder