Skip to content

Instantly share code, notes, and snippets.

@kmandreza
kmandreza / Delivering Punchlines Effectively.md
Created January 10, 2012 05:53
Part 2 of Hunger Academy Application

Jokes are delivered with the intent of entertainment and with the desired effect of laughter. Punchlines are typically used to end a sentence with humor. An easy way to create a joke is to think of a subject and a scenario where the subject executes an unexpected and related action. To deliver punchlines effectively, the action should associate with the subject's opposite.

Let's use the subject, "a good mother" to practice creating a joke with an effective punchline. We will keep in mind that the subject, "a good mother" should execute an action associated with its opposite. To me, the opposite of "a good mother" is "a bad father." Now think of an action a bad father would do. Since mothers and fathers are sometimes found in marriage, the scenario of the joke I will make is the introduction to a marriage proposal. Here is the joke and punchline I came up with:

Boyfriend: "I think you would make a good wife because I can tell you would make a good mother."
Girlfriend: "Of course I would make a good

@kmandreza
kmandreza / gist:2950269
Created June 18, 2012 19:36
Dictionary
Creating a dictionary class
[This exercise was adapted from TestFirst.org.]
Create a Dictionary class. When you create a new dictionary (such as one for English), it should be an empty hash. Then, you should be able to add words and their definition by calling a method and passing in a hash as an argument. You should also be able to list all of the words and their definitions in alphabetical order with another method. Finally, you should be able to search the dictionary by passing in the first few letters of a word and returning all of the words that start with those letters, along with their definitions.
class Dictionary
attr_accessor :entries
@kmandreza
kmandreza / gist:2951823
Created June 19, 2012 01:35
JSTwitter.rb
require 'jumpstart_auth'
class JSTwitter
attr_reader :client
def initialize
puts "Initializing"
@client = JumpstartAuth.twitter
end
@kmandreza
kmandreza / gist:2952007
Created June 19, 2012 02:41
Book Class
def title_case(string)
first_word = true
stop_words = ["a", "an", "the", "and"]
words = string.split
words.each do |word|
is_stop_word = stop_words.include?(word)
is_i = word == "i"
if (first_word || !is_stop_word || is_i)
word[0] = word[0].upcase
@kmandreza
kmandreza / gist:2952036
Created June 19, 2012 02:51
Family Love
family = ["Javier","Darjeeling","Chai"]
family.each do |i|
   puts "I love you, " + i
end
in JS
var family = ["Javier","Darjeeling","Chai"];
for (var i = 0; i < family.length; i++) {
@kmandreza
kmandreza / in_words_ultimate.rb
Created June 19, 2012 21:55 — forked from michaelrkn/in_words_ultimate.rb
numbers in words ultimate edition
class Integer
def in_words
if self < 20
{0 => "\b", 1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", 6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten", 11 => "eleven", 12 => "twelve", 13 => "thirteen", 14 => "fourteen", 15 => "fifteen", 16 => "sixteen", 17 => "seventeen", 18 => "eighteen", 19 => "nineteen"}[self]
elsif self < 100
"#{{20 => "twenty", 30 => "thirty", 40 => "forty", 50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty", 90 => "ninety"}[self - (self % 10)]} #{(self % 10).in_words}"
elsif self < 1_000
"#{(self / 100).in_words} hundred #{(self % 100).in_words}"
else
{10 ** 12 => "trillion", 10 ** 9 => "billion", 10 ** 6 => "million", 10 ** 3 => "thousand"}.each do |number, word|
require 'docopt'
class Todo
def initialize
puts "Generating 'To Do' list"
@file = File.open("todo_list.txt", 'w+')
puts "'To Do' list generated"
end
require 'docopt'
class Task
def initialize(contents)
end
end
class Todo
@kmandreza
kmandreza / evolution.rb
Created June 24, 2012 05:40
Evolution....
#TO CREATE A NEW CLASS
module EvolutionarySkills
def breed_rapidly(howrapid)
puts cross_mate.*(howrapid)
end
end
class SomeNewAnimal < String
include EvolutionarySkills
@kmandreza
kmandreza / gist:2985424
Created June 24, 2012 23:09
Refactored ToDo
doc = "Usage: example.rb [options] <arguments>...
Options:
-h --help show this help message and exit
add add task to the end of the list
prepend add task to the beginning of list"
require 'docopt'
if __FILE__ == $0