Skip to content

Instantly share code, notes, and snippets.

View hoffm's full-sized avatar
☀️
twib.nyc

Michael Hoffman hoffm

☀️
twib.nyc
View GitHub Profile
There, now you got it.
@hoffm
hoffm / check_table_column_collisions.rb
Created May 6, 2014 17:45
This gist contains a script that will check for collisions between the database table names and column names associated with ActiveRecord models. This type of collision was just revealed to be a security risk in this advisory: https://groups.google.com/forum/#!topic/rubyonrails-security/8CVoclw-Xkk
def check
ActiveRecord::Base.send(:subclasses).each do |klass|
if klass.column_names.include?(klass.table_name)
raise "#{klass.to_s}'s table name collides with column #{klass.table_name}"
end
end
puts "All Clear."
end
@hoffm
hoffm / example_food52_order.rb
Last active August 29, 2015 14:04
Example Food52 Order
{
:email=>"michael@food52.com",
:items=>
[
{
:qty=>2,
:title=>"Vintage Jam Serving Spoon",
:price=>1500,
:id=>253,
:url=>"http://food52.dev/provisions/products/143-vintage-jam-serving-spoon",
### Keybase proof
I hereby claim:
* I am hoffm on github.
* I am hoffm (https://keybase.io/hoffm) on keybase.
* I have a public key whose fingerprint is 3431 91FF 4C06 135F 33FC 1E8A 1828 FE50 861D 0EBF
To claim this, I am signing this object:
Domain Name: TANE.US
Domain ID: D6470007-US
Sponsoring Registrar: GODADDY.COM, INC.
Sponsoring Registrar IANA ID: 146
Registrar URL (registration services): whois.godaddy.com
Domain Status: clientDeleteProhibited
Domain Status: clientRenewProhibited
Domain Status: clientTransferProhibited
Domain Status: clientUpdateProhibited
Variant: TANE.US

Treated as Singular

1
1.0
1.00
```

All fractions of the form `n`/`m` where `n` and `m` are numbers, e.g.
@hoffm
hoffm / String Contsants
Created October 19, 2012 17:00
Oddness of '<<' and String constants
1.8.7-p370 :008 > MICHAEL = "michael"
=> "michael"
1.8.7-p370 :009 > a = MICHAEL
=> "michael"
1.8.7-p370 :010 > a << " hoffman"
=> "michael hoffman"
1.8.7-p370 :011 > a
=> "michael hoffman"
1.8.7-p370 :012 > MICHAEL
=> "michael hoffman"
@hoffm
hoffm / gist:5207153
Last active December 15, 2015 05:09
1.9.3-p385 :020 > title = Recipe.find(12934).title
 => "The River Café's Strawberry Sorbet" 
1.9.3-p385 :021 > title.encode('ISO-8859-1', 'utf-8')
 => "The River Caf\xC3\xA9's Strawberry Sorbet" 
1.9.3-p385 :022 > puts _
The River Café's Strawberry Sorbet
 => nil 
@hoffm
hoffm / status.rb
Created August 14, 2013 13:28
Definition of #status for VendorOrderFulfillment.
def status
if self.reverted then
"Reverted"
elsif !self.ship_date then
"Open"
elsif (self.tracking_numbers.length == 0 and !self.shipping_cost_micros) then
"Processing (awaiting)"
else
self.ship_date > Date.today ?
"Processing" :
@hoffm
hoffm / NULLquiz.sql
Created September 11, 2013 16:32
What the relationship between the output of line 1 and the output of line 2?
SELECT COUNT(*) FROM `shipments` WHERE (status != 'delivered')
SELECT COUNT(*) FROM `shipments` WHERE (status IS NULL OR status != 'delivered')