Skip to content

Instantly share code, notes, and snippets.

@jamesjtong
jamesjtong / gist:6706909
Last active December 23, 2015 22:59
fizzbuzz
#regular fizzbuzz
def fizzbuzz(max)
(1..max).each do |number|
if number % 3 == 0 && number % 5 == 0
puts "FizzBuzz"
elsif number % 3 == 0
puts "Fizz"
elsif number % 5 == 0
puts "Buzz"
else
@jamesjtong
jamesjtong / gist:6728365
Last active December 24, 2015 02:09
normalize phone num
# Download this file:
# https://gist.github.com/scottcreynolds/ac1b5c8d96de0c91bf7c/download
# Run it from your terminal with:
# ruby ruby_phone_format.rb
# (Just make sure you are in the right directory)
# ======================================
# Ignore All This Code
# ======================================
@jamesjtong
jamesjtong / gist:6769622
Created September 30, 2013 20:21
lab 1
movie = {
action: ["Die Hard", "Fight Club"],
fantasy: ["Harry Potter", "Lord of the Rings", "Pokemon"] ,
comedy: ["Scary Movie", "Scary Movie 2", "Grown Ups"] ,
thriller: ["Freddy Kreuger", "Scream", "Texas Chainsaw Massacrew"],
romance: ["The Notebook"]
}
recipes = {
chicken_marsala: ["mushrooms","chicken","white wine", "marsala wine"],
@jamesjtong
jamesjtong / gist:6770032
Last active December 24, 2015 08:19
day6 more_labs assignment
#Apple picker
# Instructions
# Create a method, apple_picker, that will pick all the apples out of an array. Implement it with collect and then implement it with select. Write a sentence about how select differs from collect.
def apple_picker(arr)
arr.select {|fruit| fruit == "apple"}
end
def apple_picker(arr)
arr.collect {|fruit| fruit if fruit == "apple"}.compact
end
@jamesjtong
jamesjtong / gist:6773203
Created October 1, 2013 02:42
nba_finals_game7 hashquetball with only the 5 best players on each team
nba_finals_game7 = {
miami_heat: {
colors:["white","red"],
players: {
lebron_james: {name: "King James", number: "#6", shoe_size: 18, stats: {points: 45, rebounds: 12, assists: 4, steals: 2, blocks: 0, slam_dunks: 10}},
dwyane_wade: {name: "Flash", number: "#3", shoe_size: 15, stats: {points: 23, rebounds: 10, assists: 1, steals: 1, blocks: 0, slam_dunks: 0}},
chris_bosh: {name: "Bosh", number: "#1", shoe_size: 20, stats: {points: 0, rebounds: 7, assists: 2, steals: 1, blocks: 1, slam_dunks: 0}},
shane_battier: {name: "Shane Battier", number: "#31", shoe_size: 18, stats: {points: 18, rebounds: 4, assists: 1, steals: 1, blocks: 2, slam_dunks: 5}},
mario_chalmers: {name: "Jeremy Lin Killer aka Mario Chalmers", number: "#15", shoe_size: 15, stats: {points: 14, rebounds: 0, assists: 2, steals: 2, blocks: 0, slam_dunks: 0}}
@jamesjtong
jamesjtong / gist:6773225
Created October 1, 2013 02:45
all labs besides hasquetball
movie = {
action: ["Die Hard", "Fight Club"],
fantasy: ["Harry Potter", "Lord of the Rings", "Pokemon"] ,
comedy: ["Scary Movie", "Scary Movie 2", "Grown Ups"] ,
thriller: ["Freddy Kreuger", "Scream", "Texas Chainsaw Massacrew"],
romance: ["The Notebook"]
}
recipes = {
chicken_marsala: ["mushrooms","chicken","white wine", "marsala wine"],
require 'json'
require 'rest_client'
reddit_hash = JSON.parse(RestClient.get('http://reddit.com/.json'))
filtered_data = reddit_hash["data"]["children"].select do |indiv_post|
indiv_post["data"]["over_18"] == false
end
output = "<html><head></head><body><ul>"
class Anagram
attr_accessor :word
def initialize(word)
@word = word
end
def match(array)
array.select {|item| item.downcase.split("").sort == self.word.downcase.split("").sort}
end
end
class SecretHandshake
attr_accessor :commands
def initialize(code)
@commands = code_convert_to_commands(code)
end
def code_convert_to_commands(code)
total_commands = []
total_commands << "wink" if code.chars.last == "1"
total_commands << "double blink" if code.chars[-2] == "1"
class SecretHandshake
attr_accessor :commands
def initialize(code)
@commands = code_convert_to_commands(code)
end
def code_convert_to_commands(code)
total_commands = []
total_commands << "wink" if code.chars.last == "1"
total_commands << "double blink" if code.chars[-2] == "1"