Skip to content

Instantly share code, notes, and snippets.

class Params < Hash
def initialize(qs)
parse_query_string!(qs)
end
def parse_query_string!(qs)
pairs = qs.split('&')
pairs.each do |pair|
key, value = *pair.split('=')
self[key] = value
# the hash
hash = Hash.new {|h,k| h[k] = 0}
# populate the hash
File.open('email').each do |line|
line.split(/\s+/).each do |word|
hash[word] += 1
end
end
class LuckyArray < Array
def self.from_string(str)
new str.split('').map(&:to_i)
end
def front_half
slice 0, length/2
end
def back_half
def triangle(a, b, c)
Triangle.new(a, b, c).type
end
class Triangle
def initialize(a, b, c)
@sides = *a, b, c
end
attr_reader :sides
def triangle(a, b, c)
sides = *a, b, c
if sides.uniq.length == 1
:equilateral
elsif sides.uniq.length == 2
:isosceles
else
:scalene
end
text = (1..10_000).inject('') do |str, num|
str << "#{num} ".gsub(/0/,' ')
end
total = text.split(' ').map(&:to_i).inject(:+)
puts total
remove Lock = Caps_Lock
keysym Caps_Lock = Control_L
add Control = Control_L
keycode 107 = Menu
$('#audio').on 'pause', ->
$('#to')
.val @currentTime.toFixed(2)
.trigger 'update'
class Object
def isnt?(*args)
arr = args.first.is_a?(Array) ? args.first : args
!arr.include? self
end
end
class Numeric
def percent
self.to_f / 100
end
end