Skip to content

Instantly share code, notes, and snippets.

View joegiralt's full-sized avatar
💣
:p

Joseph Giralt joegiralt

💣
:p
View GitHub Profile
@joegiralt
joegiralt / reverse.rb
Created June 17, 2013 22:03
reverse method
# From [Rubeque](http://rubeque.com/problems/reverse-each-word)
# Write a method that takes a sentence and returns it with each word reversed in place.
# ruby
# reverse_each_word.rb
# Write a method that takes a sentence and returns it with each word reversed in place.
# A String has many methods that can be called on it:
# http://www.ruby-doc.org/core-1.9.3/String.html
@joegiralt
joegiralt / rack.rb
Last active December 18, 2015 17:59
How to set up the simplest rails rack.
require 'rack'
class JoeApp #change this name
def call(env)
puts env['PATH_INFO']
puts env['HTTP_ACCEPT']
body = '<a href="http://students.flatironschool.com/students/joegiralt.html"><font color="pink"><h1>Hello Joe!</h1></font></a>'
@joegiralt
joegiralt / crap
Created June 21, 2013 13:34
crap
# def math(range)
# x = 1..range.max
# #x*x = sum
# end
# sum.each do |x|
# x = 1..20
# sum == 0
# end
# end
@joegiralt
joegiralt / mass_assignment.rb
Created July 8, 2013 19:40
quick assignment
require 'fis/test'
class Dog
attr_accessor :name, :species, :colors, :fur_length
def initialize(attributes_hash)
attributes_hash.each do |key, value|
self.send("#{key}=", value)
end
end
@joegiralt
joegiralt / tictactaunt.py
Created July 10, 2013 15:35
old tictactoe program that ai submitted to get into The Flatiron School.
import random
import sys
from time import sleep
print "*********Welcome to Joe's TicTacTAUNT game**********"
tictactoe = [
0, 1, 2,
3, 4, 5,
@joegiralt
joegiralt / Wtf_really.js
Created November 22, 2013 22:46
Little JavaScript WTFs
var a = [20, 10, 5, 1];
// Everyday array
a.sort();
// [1, 10, 20, 5]... WTF?
a == [1, 10, 20, 5];
// false
a === [1, 10, 20, 5];
@joegiralt
joegiralt / us_state_hash.rb
Created December 5, 2013 19:32
a hash of US states in Ruby Hash
states = {
"AL" => "Alabama",
"AK" => "Alaska",
"AS" => "American Samoa",
"AZ" => "Arizona",
"AR" => "Arkansas",
"CA" => "California",
"CO" => "Colorado",
"CT" => "Connecticut",
"DE" => "Delaware",
@joegiralt
joegiralt / build-erlang-r16b_and_elixir0-12-5.sh
Last active August 29, 2015 13:57 — forked from vanhalt/build-erlang-r16b_and_elixir093.sh
Builds Erlang r16b & Elixir 0.12.5
#!/bin/bash
# Pull this file down, make it executable and run it with sudo
# wget https://raw.github.com/gist/5487621/build-erlang-r16b.sh
# chmod u+x build-erlang-r16b.sh
# sudo ./build-erlang-r16b.sh
if [ $(id -u) != "0" ]; then
echo "You must be the superuser to run this script" >&2
exit 1
fi
@joegiralt
joegiralt / gist:191f39262ee379ab91da
Created October 8, 2014 21:40
scribbles magic squares
hash = {}
perfect_sqrs = []
(1..300).each do |num|
perfect_sqrs << (num**2)
end
find_partition = lambda do |elts|
p "ELTS: #{elts}"
if elts.empty?
[[]]
@joegiralt
joegiralt / gist:601d95496c49b4988fa2
Created January 21, 2015 21:38
n choose k Ruby
class Integer
def choose(k)
return 0 if (k > self)
n = self
r = 1
1.upto(k) do |d|
r *= n
r /= d
n -= 1
end