Skip to content

Instantly share code, notes, and snippets.

@bcamarda
bcamarda / Scope
Created June 15, 2012 16:16
Explanation of scope
# VARIABLE SCOPE
=Begin
$example A global variable
@example An instance variable
example A local variable
Example A constant
@@example A class variable
@bcamarda
bcamarda / rps.rb
Created June 18, 2012 23:18
RPS Winner
def game(pair)
raise WrongNumberOfPlayersError unless pair.length == 2
strategy = pair[0][1].downcase + pair[1][1].downcase
if ["rs", "sp", "pr"].include?(strategy)
#return "#{pair[0]} wins since #{pair[0][1]} > #{pair[1][1]}}"
return pair[0]
elsif ["sr", "ps", "rp"].include?(strategy)
#return "#{pair[1]} wins since #{pair[1][1]} > #{pair[0][1]}}"
return pair[1]
@bcamarda
bcamarda / pig_latin.rb
Created June 21, 2012 00:21
Pig Latin
def translate(string)
vowel = ["a", "e", "i", "o", "u", "y"]
if ((vowel.include? string[0]) == false) && ((vowel.include? string[1]) == false) && ((vowel.include? string[2]) == false)
string = string[3..-1] + string[0..2] + "ay"
elsif ((vowel.include? string[0]) == false) && ((vowel.include? string[1]) == false)
string = string[2..-1] + string[0..1] + "ay"
elsif (vowel.include? string[0]) == true
string = string + "ay"
elsif string[0..1] == "qu"
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Apprentice">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://codeclasschat.herokuapp.com/helpers.js"></script>
@bcamarda
bcamarda / sudoku.rb
Created June 26, 2012 19:31
Sudoku Solver - Not solving all yet
# module SudokuSolver
class Gameboard
attr_reader :board, :rows, :columns, :quadrants, :before_array, :after_array
def initialize(initial_values)
@board = []
@rows = []
@columns = []
@quadrants = []
generate_cells(initial_values)
@bcamarda
bcamarda / in_words.js
Created June 27, 2012 03:15
Numbers in Words in JS
var inWords = function(number){
var numberHash = {
0:"", 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", 20: "twenty", 30: "thirty", 40: "forty", 50: "fifty", 60: "sixty", 70: "seventy", 80: "eighty", 90: "ninety"
};
if(number <= 20){
return numberHash[number];
}
@bcamarda
bcamarda / everlane.rb
Created June 30, 2012 23:31
Everlane Problem
def everlane(string)
new_string = string.gsub(/[bcdefghij]/, "a").gsub(/[MKP]/, "Q")
test_array = []
array = new_string.split(//)
status = "VALID"
array.length.times do
current_letter = array.pop
case current_letter
when "a"
@bcamarda
bcamarda / sender_bots.rb
Created July 12, 2012 19:34
sinatra integration for craigslist crawler
require 'sinatra'
get '/' do
erb :index
end
get '/history' do
erb :history
end
@bcamarda
bcamarda / index.erb
Created July 12, 2012 19:35
index for sinatra app for craigslist crawler
<!DOCTYPE html>
<html>
<head>
<h1>Senderbots Craigslist Crawler</h1>
<h3><p>Instructions: Go to Craigslist and create your search, in any category. Copy the URL and paste it below.</p></h3>
<script src= "/bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap.css"/>
@bcamarda
bcamarda / history.erb
Created July 12, 2012 19:35
history for sinatra app for senderbots
<!DOCTYPE html>
<html>
<head>
<h1>Senderbots Craigslist Crawler</h1>
<h3><p>History</p></h3>
</head>
<body>
</body>