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
require 'rubygems' | |
require 'open-uri' | |
require 'hpricot' | |
movie = tt0379786 | |
0.upto(5) do |page| | |
@url = "http://www.imdb.com/title/#{movie}/usercomments?start=#{page * 10}" | |
open(@url) { |f| @response = f.read } |
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
require 'rubygems' | |
require 'sinatra' | |
require 'pony' | |
get '/' do | |
Pony.mail(:to => '[email protected]', | |
:from => ENV['SENDGRID_USERNAME'], | |
:subject => 'xyzpqrst', | |
:body => 'test', | |
:via => :smtp, :via_options => { |
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
factorial = Hash.new do |h,k| | |
if k > 1 | |
h[k] = h[k-1] * k | |
else | |
h[k] = 1 | |
end | |
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
Dir.glob("vendor/*").each { |gem| $LOAD_PATH.unshift "#{gem}/lib" } |
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
# 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 | |
# >= gruff 0.3.6 | |
# |
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
key_length = key_length_guess(ciphertext) | |
dot_values, shift_values = [ ], [ ] | |
1.upto(key_length).each do |start_letter| | |
letter_frequency_array = ciphertext.every_nth_letter(key_length, start_letter).letter_frequencies | |
dot_values << letter_frequency_array.dot_product(ENGLISH_FREQUENCIES) | |
1.upto(ENGLISH_FREQUENCIES.size - 1).each do |i| |
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
user.restaurants << Restaurant.new(:name => params[:name]) unless user.restaurants.inject { |bool, rest| bool ||= true if rest.name == params[:name] } |
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(:each) do | |
@key = "0111111101001001110000101000001100011100000011101111010011101001".split("").map { |i| i.to_i } | |
@text = "0101010101010101010101010101010101010101010101010101010101010101".split("").map { |i| i.to_i } | |
@text_bitfield = BitField.new(@text) | |
@right = @text_bitfield.right | |
@left = @text_bitfield.left | |
@keys = KeySchedule.sub_keys(@key) | |
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
<html> | |
<head> | |
<style type="text/css"> | |
div.ex | |
{ | |
/* for firefox, safari, chrome, etc. */ | |
-webkit-transform: rotate(-15deg); | |
-moz-transform: rotate(-15deg); | |
/* for ie */ | |
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); |
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
require 'rubygems' | |
require 'parslet' | |
class Mini < Parslet::Parser | |
root(:lines) | |
rule(:lines) { line.repeat } | |
rule(:line) { (title | ingredient | step) >> newline.maybe } |
OlderNewer