Skip to content

Instantly share code, notes, and snippets.

View geopet's full-sized avatar
😍
Coding with my dog

Geoff Petrie geopet

😍
Coding with my dog
View GitHub Profile
@geopet
geopet / fizzbuzz.php
Created September 7, 2012 02:43
PHP FizzBuzz
<?php
$x = 100;
for ( $i = 1; $i <= $x; $i++ )
{
if ( ( $i % 5 == 0 ) && ( $i % 3 == 0 ) )
{
echo "fizzbuzz\n";
@geopet
geopet / fizzbuzz.py
Created September 7, 2012 03:01
Python FizzBuzz
for i in range(1, 101):
if i % 5 == 0 and i % 3 == 0:
print "fizzbuzz"
elif i % 5 == 0:
print "fizz"
elif i % 3 == 0:
print "buzz"
else:
print i
@geopet
geopet / gist:3747712
Created September 19, 2012 04:39
Ruby FizzBuzz
for i in 1..100
if i % 5 == 0 and i % 3 == 0
puts "fizzbuzz"
elsif i % 5 == 0
puts "fizz"
elsif i % 3 == 0
puts "buzz"
else
puts i
end
@geopet
geopet / gist:3780236
Created September 25, 2012 06:05
A better ruby fizzbuzz
100.times do |i|
if i % 5 === 0 and i % 3 === 0
puts 'fizzbuzz'
elsif i % 5 === 0
puts 'fizz'
elsif i % 3 === 0
puts 'buzz'
else
puts i
@geopet
geopet / gist:3969710
Created October 28, 2012 20:08
In no particular order
rogues = %w[Avdi Chuck David James Josh]
rogues.shuffle!
rogues.each { |rogue| puts "Thank you, #{rogue}!" }
@geopet
geopet / problem13.js
Created February 16, 2013 04:01
A little JS gist to solve a Euler problem. As always, could be refined.
// Euler input
var numberString = "37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 74324986199524741059474233309513058123726617309629 91942213363574161572522430563301811072406154908250 23067588207539346171171980310421047513778063246676 89261670696623633820136378418383684178734361726757 28112879812849979408065481931592621691275889832738 44274228917432520321923589422876796487670272189318 47451445736001306439091167216856844588711603153276 70386486105843025439939619828917593665686757934951 62176457141856560629502157223196586755079324193331 64906352462741904929101432445813822663347944758178 92575867718337217661963751590579239728245598838407 58203565325359399008402633568948830189458628227828 80181199384826282014278194139940567587151170094390 35398664372827112653829987240784473053190104293586 86515506006295864861532075273371959191420517255829 71693888707715466499115593487603532921714970056938 54370070576826684624621495650076471787294438377604 53282654108756828443
@geopet
geopet / array.php
Created February 22, 2013 18:32
Quick example in elegance using PHP and Ruby. PHP forces us to use the bang to check for not. Ruby has `unless` which allows, in my opinion, a more fluid way to write code.
<?php
$my_array = array('apple', 'pear', 'cherry')
// If I want to find out if a value is in an array with PHP I do this:
if (in_array('apple', $my_array)) {
echo 'Apple is in the array!'; // => Apple is in the array!
}
@geopet
geopet / 1_9_3_result.md
Last active December 18, 2015 12:29
Weather Underground API Debugging

Ruby MRI 1.9.3 Results

[gpetrie] $ ruby -v
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-darwin11.4.2]

[gpetrie] $ ruby wunderground.rb
Current temperature in Cedar Rapids is: 77.0
@geopet
geopet / README.md
Last active December 18, 2015 16:49
Please read the README to understand the purpose of this gist.

This gist shows the current state of a rails app I'm working on. I'm attempting to figure out the routing so that when a user submits a zipcode into the form on app/views/forecast/index.html.erb they get the same experience as if they had done http://localhost:3000/forecast/87120.

There are two main issues that I believe I am misunderstanding.

  1. How can I make the default param with forecast routing be :zip instead of :id? (Is it possible for me to just use resources :forecast in the routes.rb file?)

  2. How do I properly redirect things when I know that the params[:zip].blank? is not true so that the show method/action of the forecast controller is sent the message.

I understand that I can just change my controller to behave with a params[:id] instead of params[:zip], but I feel that there is a piece I'm missing here, and it still doesn't help me with my redirect after form submission on the index.html.erb page.

rbenv-deps:
pkg.installed:
- pkgs:
- bash
- git
- openssl
- make
- curl
ruby-2.0.0-p247: