Skip to content

Instantly share code, notes, and snippets.

View jasonnoble's full-sized avatar

Jason Noble jasonnoble

View GitHub Profile
We needed a HTML file that had form
fields to submit a user registration.
Requirements were PHP.
So, to start with, I created a Rails app.
Then generated a scaffold with:
rails generate scaffold Registration
first_name:string middle_name:string
last_name:string address:string city:string
@jasonnoble
jasonnoble / URL Request
Created October 14, 2012 03:47
Problems with autocomplete
http://localhost:3000/zipcode/autocomplete_zipcode_zipcode?term=900
Returns:
[{"id":"38037","label":"90001","value":"90001"},{"id":"38038","label":"90002","value":"90002"},{"id":"38039","label":"90003","value":"90003"},{"id":"38040","label":"90004","value":"90004"},{"id":"38041","label":"90005","value":"90005"},{"id":"38042","label":"90006","value":"90006"},{"id":"38043","label":"90007","value":"90007"},{"id":"38044","label":"90008","value":"90008"},{"id":"38045","label":"90009","value":"90009"},{"id":"38046","label":"90010","value":"90010"}]
Then I select 90010 from the drop down list.
This shows 90010 in the autocomplete field. I need the id field (38046) submitted with the form as zipcode_id.
@jasonnoble
jasonnoble / gist:4012352
Created November 4, 2012 15:48
Boolean types with sqlite
# Test to verify my comment on http://stackoverflow.com/questions/13211811/rails-3-and-sqlite-communications-concerning-boolians/13213314#comment18003546_13213314
$ rails new sqlite_boolean_test
$ rails generate scaffold User name:string approved:boolean
$ rake db:migrate
$ rails console
>> u = User.create(:name => "Bob", :approved => false)
>> u.approved?
=> false
>> u.update_attribute(:approved, true)
@jasonnoble
jasonnoble / gist:5810878
Created June 19, 2013 00:54
Homework output
There are 60 seconds in a minute
There are 60 minutes in an hour
There are 24 hours in a day
There are 7 days in a week
That means there are:
3600 seconds in an hour,
86400 seconds in an day,
604800 seconds in a week
That means when you turn 20, you've been alive for 628992000 seconds,
and if you make it to 100, you will have lived 3144960000 seconds. Make them count!
class Horse
def speak
"Neighhhhh"
end
end
@jasonnoble
jasonnoble / gist:7619598
Created November 23, 2013 20:35
Use of Debt Factory
2.0.0-p247 :001 > debt = FactoryGirl.create(:debt)
(0.1ms) begin transaction
SQL (17.9ms) INSERT INTO "debts" ("balance", "created_at", "debt_type", "interest_rate", "min_payment", "name", "open_date", "priority", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) [["balance", #<BigDecimal:7feff511be70,'0.8462E4',9(45)>], ["created_at", Sat, 23 Nov 2013 20:31:57 UTC +00:00], ["debt_type", 1], ["interest_rate", #<BigDecimal:7feff511bb00,'0.11E2',9(45)>], ["min_payment", #<BigDecimal:7feff511b790,'0.16924E3',18(45)>], ["name", "My Debt #1"], ["open_date", Mon, 23 Nov 2009], ["priority", 1], ["updated_at", Sat, 23 Nov 2013 20:31:57 UTC +00:00]]
(2.1ms) commit transaction
=> #<Debt id: 3, name: "My Debt #1", balance: #<BigDecimal:7feff511be70,'0.8462E4',9(45)>, interest_rate: #<BigDecimal:7feff511bb00,'0.11E2',9(45)>, debt_type: 1, min_payment: #<BigDecimal:7feff511b790,'0.16924E3',18(45)>, open_date: "2009-11-23", priority: 1, created_at: "2013-11-23 20:31:57", updated_at: "2013-11-23 20:31:57">
2.0.0
@jasonnoble
jasonnoble / gist:8797940
Created February 4, 2014 03:58
Dog Class
class Dog
def speak
"Bark"
end
end
@jasonnoble
jasonnoble / keybase.md
Created March 18, 2014 15:49
keybase.md

Keybase proof

I hereby claim:

  • I am jasonnoble on github.
  • I am jasonnoble (https://keybase.io/jasonnoble) on keybase.
  • I have a public key whose fingerprint is 79D9 33A8 A13D FC1C D05B 518E 1D63 EF2F 6062 9857

To claim this, I am signing this object:

@jasonnoble
jasonnoble / gist:e2f99e29ca6e3ec4ada8
Created May 25, 2014 05:18
Output of Device.ancestors (Ruby 2.1.2 / Rails 4.1.1)
2.1.2 :001 > puts Device.ancestors
Device
#<Module:0x007f81dac8e390>
ActiveRecord::Base
ActiveRecord::Store
ActiveRecord::Serialization
ActiveModel::Serializers::Xml
ActiveModel::Serializers::JSON
ActiveModel::Serialization
ActiveRecord::Reflection
class Cat
def speak
puts "Meow"
end
end