Skip to content

Instantly share code, notes, and snippets.

Avatar

Prasanna Natarajan npras

View GitHub Profile
@npras
npras / my_impl.rb
Created Jul 3, 2012
Re-implementing the iterators
View my_impl.rb
class Array
def my_map(&nameless_fn)
new_arr = []
return Enumerator.new(self, :my_map) unless nameless_fn
self.each do |x|
new_arr << nameless_fn.call(x)
end
new_arr
end
@npras
npras / gist:3038075
Created Jul 3, 2012
Ruby Challenge 2: The Twelve Days of Christmas
View gist:3038075
# challenge 2: http://www.therubygame.com/challenges/2
gifts = "12 Drummers Drumming
11 Pipers Piping
10 Lords-a-Leaping
9 Ladies Dancing
8 Maids-a-Milking
7 Swans-a-Swimming
6 Geese-a-Laying
5 Gold Rings
4 Colly Birds
@npras
npras / gist:3038097
Created Jul 3, 2012
Ruby Challenge 3: Capitalizing words within a string
View gist:3038097
# Challenge 3: http://www.therubygame.com/challenges/3/submissions
str = "The small brown & ginger fox JUMPED OVER the gate"
# output = "The Small Brown & Ginger Fox Jumped Over The Gate"
# Algorithm:
# 1. downcase #{str}
# 2. to_a
# 3. capitalize on each array elements
# 4. merge as str
def Capitalize(str)
@npras
npras / gist:3038191
Created Jul 3, 2012
Ruby Challenge 4: Puns, Palindromes and Parrots
View gist:3038191
# Puns, Palindromes and Parrots
# Challenge 4: http://www.therubygame.com/challenges/4/submissions
#str = "abacdfgdcabaypqqpy" # 324 171 163
#str = "natarajan" # 81 45 42 # "ata"
str = "ghjiiooiijplr"
# desired output "ypqqpy"
def find_longest_palindrome(string)
p = ""
@npras
npras / gist:3038220
Created Jul 3, 2012
Ruby Challenge 5: Roman Numerals
View gist:3038220
# http://www.therubygame.com/challenges/5/submissions
# = 1
# V = 5
# X = 10
# L = 50
# C = 100
# D = 500
# M = 1000
# Sample i/o:
# MCMXCIX gives 1999, MMXII gives 2012
@npras
npras / gist:3038253
Created Jul 3, 2012
Ruby Challenge 6: Morsels and Dimes
View gist:3038253
# http://www.therubygame.com/challenges/6/submissions
module RubyChallenge
extend self
MORSE = {
A: '.-', B: '-...', C: '-.-.', D: '-..', E: '.', F: '..-.', G: '--.',
H: '....', I: '..', J: '.---', K: '-.-', L: '.-..', M: '--', N: '-.',
O: '---', P: '.--.', Q: '--.-', R: '.-.', S: '...', T: '-', U: '..-',
@npras
npras / Gemfile
Created Jul 12, 2012
gemfile of a gem
View Gemfile
source 'https://rubygems.org'
# Specify your gem's dependencies in boomboom.gemspec
gemspec
@npras
npras / gist:3683129
Created Sep 9, 2012
Stubbing out a module
View gist:3683129
# spec/spec_helper_lite.rb
def stub_module(full_name)
full_name.to_s.split(/::/).inject(Object) do |context, name|
begin
context.const_get(name)
rescue NameError
context.const_set(name, Module.new)
end
end
end
View jsbin.ficowica.css
div#container {
border: 2px solid black;
background: #ddd;
width: 485px;
}
p {
background: gray;
padding: 10px;
display: inline-block;
View jsbin.hojek.css
.one {
background: green;
}
.two {
background: red;
}