Skip to content

Instantly share code, notes, and snippets.

@polycarpou
polycarpou / binary.handshake.rb
Created October 8, 2013 23:37
day 12 binary handshake to do
# # Binary Secret Handshake
# > There are 10 types of people in the world: Those who understand binary, and those who don't.
# You and your fellow flatirons are of those in the "know" when it comes to binary decide to come up with a secret "handshake".
# ```
# 1 = wink
# 10 = double blink
# 100 = close your eyes
@polycarpou
polycarpou / jukebox.rb
Created October 7, 2013 15:46
Day 9 Debugger
require_relative 'song_library.rb'
def jukebox(command)
if command.downcase == "list"
list_library
else
parse_command(command)
end
end
@polycarpou
polycarpou / anagram.rb
Last active December 24, 2015 21:48
Day 11 anagram todo
class Anagram
def initialize(test_word)
@test_word = test_word
end
def match(dictionary)
out = dictionary.select do |x|
@test_word.split("").sort == x.split("").sort
end
end
end
@polycarpou
polycarpou / reddit_hash.rb
Created October 3, 2013 02:03
Goes through the Reddit website and outputs an html site which gets rid of some posts. The nsfw filter is not quite finished yet.
require 'json'
require 'rest_client'
reddit_hash = JSON.parse(RestClient.get('http://reddit.com/.json'))
reddit_hash["data"]["children"][2]["data"]["over_18"]
str = ""
reddit_sfw_hash = reddit_hash["data"]["children"].delete_if {|x| x["data"]["over_18"] == true}
@polycarpou
polycarpou / pigeon_organizer.rb
Created October 3, 2013 01:21
unoptimised working pigeon organizer program
########################
# NYC PIGEON ORGANIZER #
########################
# Start with the following collected data on NYC pigeons.
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
:grey => ["Theo", "Peter Jr.", "Ms .K"],
@polycarpou
polycarpou / hashes.rb
Created October 1, 2013 05:25
reverse words and hash examples
movie_collection = {
comedy: ["The Hangover", "Forest Gump"],
action: ["Saving Private Ryan", "Pulp Fiction", "The Matrix"],
cartoon: ["Finding Nemo", "WallE", "Toy Story"]
}
recipes = {
macaroni_and_cheese: ["macaroni", "cheese"],
pj_sandwich: ["peanut butter", "jelly", "bread"],
salad: ["lettuce", "tomato", "cucumbers", "feta cheese"]
def apple_picker(arr)
apples_only = arr.collect do |x|
if x == "apple"
x
else
next
end
end
apples_only.delete(nil)
apples_only
def take_a_number(current_line, new_person)
current_line << new_person
current_line.length
end
def now_serving(current_line)
puts "Currently serving #{current_line.first}"
current_line.shift
end
@polycarpou
polycarpou / holiday_supplies.rb
Created October 1, 2013 05:18
holiday supplies
holiday_supplies = {
:winter => {
:christmas => ["Lights", "Wreath"],
:new_years => ["Party Hats"]
},
:summer => {
:forth_of_july => ["Fireworks", "BBQ"]
},
:fall => {
:thanksgiving => ["Turkey"]
@polycarpou
polycarpou / hasketball.rb
Created October 1, 2013 05:15
Hasketball question without the bonus
# Hashketball Nests
#
# Great news! You're going to an NBA game! The only catch is that you've been
# volunteered to keep stats at the game.
#
# Using Nested Hashes, define a game, with two teams, their players, and the players stats:
#
# The game has two teams.
#
# A team has: