Skip to content

Instantly share code, notes, and snippets.

def sample_array(size, array, new_array = [])
count = 0
while new_array.size < size
new_array << array[count % array.size]
count += 1
end
return new_array
end
inpatient = @questions["stay_overnight_at_the_hospital_one_or_more_times"]
outpatient = @questions["have_one_or_more_outpatient_hospital_vists"]
emergency = @questions["seek_care_at_the_emergency_room"]
case
when inpatient == 0 && outpatient == 0 && emergency == 0
@draws
when inpatient == 0 && outpatient == 0 && emergency >= 1
top_draws(80)
def blah(input)
if input.class != Array
return [input]
else
return input
end
end
require 'rubygems'
require 'parslet'
class Mini < Parslet::Parser
root(:lines)
rule(:lines) { line.repeat }
rule(:line) { (title | ingredient | step) >> newline.maybe }
<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);
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
user.restaurants << Restaurant.new(:name => params[:name]) unless user.restaurants.inject { |bool, rest| bool ||= true if rest.name == params[:name] }
@dpick
dpick / vigenere
Created March 16, 2011 19:20
Algorithm to decrypt ciphertext created using a vigenere cipher
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|
# 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
#
@dpick
dpick / gist:815767
Created February 8, 2011 03:00
Vendoring Gems
Dir.glob("vendor/*").each { |gem| $LOAD_PATH.unshift "#{gem}/lib" }