Skip to content

Instantly share code, notes, and snippets.

View rubiety's full-sized avatar

Ben Hughes rubiety

View GitHub Profile
@rubiety
rubiety / pytorch_cpu_mps_comparison.py
Last active December 20, 2023 06:41
Pytorch CPU vs GPU (Apple Silicon MPS) Performance Comparison (Scaling with Matrix Size)
import torch
import timeit
def compare_cpu_mps(size, dimensions = 2, iterations = 2_500):
a_cpu = torch.rand(size, device='cpu')
b_cpu = torch.rand(tuple((size for n in range(dimensions))), device='cpu')
a_mps = torch.rand(size, device='mps')
b_mps = torch.rand(tuple((size for n in range(dimensions))), device='mps')
print(' - cpu', timeit.timeit(lambda: a_cpu @ b_cpu, number=iterations))
@rubiety
rubiety / gist:821c6f1818752ad63218
Last active August 29, 2015 14:23
Mile Optimization Example
» AwardChartEntry.first_class.between(Airport["SAN"], Airport["ICN"]).order("amount asc").map(&:name)
=> [
[0] "MileagePlus Mainland U.S., Alaska & Canada to North Asia Saver Award in First: 80000 miles one way on own metal",
[1] "Aeroplan Canada & Continental USA to Asia 1 ClassicFlight Award in First: 105000 miles one way",
[2] "MileagePlus Mainland U.S., Alaska & Canada to North Asia Saver Award in First: 120000 miles one way on partner metal",
[3] "Skypass North America to Korea Off Peak Award in First: 160000 miles round trip",
[4] "MileagePlus Mainland U.S., Alaska & Canada to North Asia Standard Award in First: 190000 miles one way on own metal",
[5] "MileagePlus Mainland U.S., Alaska & Canada to North Asia Standard Award in First: 190000 miles one way on partner metal",
[6] "Aeroplan Canada & Continental USA to Asia 1 ClassicFlight Award in First: 210000 miles round trip",
[7] "Skypass North America to Korea Peak Award in First: 240000 miles round trip"

Keybase proof

I hereby claim:

  • I am rubiety on github.
  • I am rubiety (https://keybase.io/rubiety) on keybase.
  • I have a public key whose fingerprint is C2B6 4E10 316C 96DA 6218 C7BF 31B1 B5C8 1528 8AF1

To claim this, I am signing this object:

@rubiety
rubiety / hidden_fields_from_params.rb
Created January 23, 2015 19:23
Dumping hidden fields from nested params hash
def hidden_fields_from_params(hash, prefix = "")
hash.map do |hash_key, hash_value|
if hash_value.is_a?(Hash)
hidden_fields_from_params(hash_value, "#{prefix}[#{hash_key}]")
else
hidden_field_tag("#{prefix}[#{hash_key}]", hash_value)
end
end.join("\n").html_safe
end
@rubiety
rubiety / october_trip.txt
Created June 21, 2014 06:34
October Trip
Routing:
http://www.gcmap.com/mapui?P=YVR-MUC-FRA-BKK-HKG,HKG-BKK-SYD-AKL,AKL-PVG-NRT-SIN-BKK-NRT-ICN-JFK-LAX
Lufthansa First Class, Vancouver to Munich: $10,541
Thai Airways A380 First Class, Frankfurt to Bangkok: $9,610
Thai Airways 747 First Class, Bangkok to Hong Kong: $776
Thai Airways 747 (A380?) First Class, Bangkok to Sydney: $2,989
Air New Zealand Dreamliner Business Class, Auckland to Shanghai: $2,500
ANA Business Class, Shanghai to Tokyo: $1,158
ANA Dreamliner Business Class, Tokyo to Singapore: $3,253
@rubiety
rubiety / usage.coffee
Last active January 1, 2016 16:39
Collection-bound select list with Backbone Marionette
options = new Backbone.Collection([{id: 1, name: "Blue"}, {id: 2, name: "Green"}])
view = new SelectListView({ collection: options })
view.render()
@rubiety
rubiety / 2013_flight_roster.txt
Last active December 31, 2015 21:39
2013 Flight Roster: 155 flight legs | 231,674 miles
Date OR DT Distance
2013-01-25 SAN DEN 853
2013-01-25 DEN STL 770
2013-01-26 STL ORD 258
2013-01-28 SAN ORD 1723
2013-01-28 ORD STL 258
2013-01-28 STL IAH 667
2013-01-28 IAH SAN 1303
2013-02-01 SAN DEN 853
2013-02-01 DEN BNA 1013
@rubiety
rubiety / mileage_runs.txt
Last active October 13, 2015 20:57
January Mileage Runs
* [JAN25] SAN-DEN-STL, STL-ORD-SAN: 4699 for $133.20 (2.83 CPM)
* [JAN28] SAN-ORD-STL-IAH-SAN: 4193 for $127.20 (3.03 CPM)
* [FEB01] SAN-DEN-BNA, BNA-IAH-SAN: 3826 for $140.20 (3.66 CPM)
* [FEB05] SAN-SFO-EWR-PHL, PHL-EWR-SFO-SAN: 7130 (7130 PQM) for $218.80 (3.07 CPM)
* [FEB08] SAN-ORD-STL-SFO-SAN: 4458 for $128.70 (2.89 CPM)
* [FEB11] SAN-IAH-ORD-MCI, MCI-ORD-SFO-SAN: 5574 for $145.30 (2.61 CPM)
* [FEB17] SAN-EWR-ZFV, ZFV-EWR-SAN: 5350 (4850 PQM) for $140.70 (2.63 CPM)
* [FEB21] SAN-EWR-ZFV, ZFV-EWR-SAN: 5350 (4850 PQM) for $140.70 (2.63 CPM)
* [MAR02] SAN-EWR-ZFV, ZFV-EWR-SAN: 5350 (4850 PQM) for $140.70 (2.63 CPM)
* [MAR04] SAN-EWR-ZFV, ZFV-EWR-SAN: 5350 (4850 PQM) for $140.70 (2.63 CPM)
class Project
def penguin
self.class.where(:something => parent_object.something)
end
end