Skip to content

Instantly share code, notes, and snippets.

times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.015 000.015: --- VIM STARTING ---
000.132 000.117: Allocated generic buffers
000.599 000.467: locale set
000.606 000.007: window checked
001.068 000.462: inits 1
001.076 000.008: parsing arguments
@jessieay
jessieay / gist:11057713
Created April 18, 2014 18:23
The X of X List
Xerox
Groupon
Kleenex
namespace :ckeditor do
desc 'Create nondigest versions of all ckeditor digest assets'
task :create_nondigest_assets do
fingerprint = /\-([0-9a-f]{32})\./
for file in Dir['public/assets/ckeditor/**/*']
next unless file =~ fingerprint
nondigest = file.sub(fingerprint, '.')
filename = nondigest.sub('public/assets/', '').sub(/.gz$/, '')
@jessieay
jessieay / Nums in Words
Created June 14, 2012 03:40
Ugly ugly version of all integers up to 1000 in words
module InWords
def in_words
num_array = self.to_s.split('')
ones_place = {"0" => "", "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five", "6" => "six",
"7" => "seven", "8" => "eight", "9" => "nine"}
final_digit_in_words = ones_place[num_array[-1]]
tens_place = {"0" => "", "1" => "", "2" => "twenty", "3" => "thirty", "4" => "forty", "5" => "fifty", "6" => "sixty", "7" => "seventy", "8" => "eighty",
"9" => "ninety"}
@jessieay
jessieay / Factorial basic
Created June 14, 2012 03:47
I am learning recursion
class Fixnum
def factorial
if self < 0
raise "You can't take the factorial of a negative number."
elsif
self == 0
1
else
self * (self-1).factorial
end
@jessieay
jessieay / Fibonacci efficient
Created June 14, 2012 05:24
Fibonacci super efficiently
class Integer
def fibonacci(arr=[0,1])
arr[self] ||= (self-1).fibonacci(arr) + (self-2).fibonacci(arr)
# if arr[self].nil?
# arr[self] = (self-1).fibonacci(arr) + (self-2).fibonacci(arr)
# end
# arr[self]
@jessieay
jessieay / Fibonacci v2
Created June 14, 2012 19:04
Fibonacci, a little prettier this time
class Integer
def fibonacci
first = 0
last = 1
(self-1).times do
current = first + last
first = last
last = current
end
return last
module InWords
def magic
ones_array = %w{ not_called one two three four five six seven eight nine ten}
tens_array = %w{ not_called not_called twenty thirty forty fifty sixty seventy eighty ninety}
teens_array = [ "" ] + %w{ one two three four five six seven eight nine ten eleven twelve
thirteen fourteen fifteen sixteen seventeen eighteen nineteen}
# if self == 0
# return "zero"
# end
@jessieay
jessieay / My First Instance Variables
Created June 15, 2012 16:51
Baby's first instance variables
def Calculator
def add(num1,num2)
@num1= num1
@num2 = num2
output("sum", num1 + num2)
end
def subtract(num1,num2)
@num1= num1
@jessieay
jessieay / Dict - o - nary
Created June 16, 2012 00:00
Dictionaryyyyyy
class Dictionary
attr_accessor :this_dictionary
def initialize
this_dictionary = {}
@this_dictionary = this_dictionary
end
def entries