Skip to content

Instantly share code, notes, and snippets.

View nottombrown's full-sized avatar

Tom B Brown nottombrown

View GitHub Profile
# A "put it in a dictionary" Q-learning agent
import gym
import numpy as np
env = gym.make('FrozenLake-v0')
env.monitor.start('recordings', force=True)
# Initialize Q matrix to zeros
Q = np.zeros((env.observation_space.n, env.action_space.n))
@nottombrown
nottombrown / nottombrown_pub.asc
Last active August 29, 2015 14:25
Tom Brown's public PGP key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: Mailvelope v0.13.1
Comment: Tom Brown's public key - https://www.mailvelope.com
xsFNBFWwA9UBEACsVDSAwJ3xBxRwLGn7FE1ABen2+74OSz6+aqjLVvoBoTxw
L5DBnirOoWiOr/RSoRGUQfw80mfZpXdOWeUfh6i3h6G6pRcXa5USXD3pQmOM
K5K6KJGG2d6CjIlKczDQVrvx6AVtzlF+ezNffWciFWWDDWClguwntVxMehhG
0vSyllzYQcEOkgCx/Cz1ptqQFgzyJI0eInIRJg+912oXsxzDAy5qzht1JVge
J5aeGxr2R8BJiaTMVlCqaMcfJnzzGRuefBhruQGYLdxyUJd6fRjiZUTjZ9UM
k77m9Ezsao/sZQJgpuuf1DZTlHoE72bEi8Xt1JQdUz8fGPTIO39M5kNXW54o
for family in UIFont.familyNames(){
println(family)
for fontName in UIFont.fontNamesForFamilyName("\(family)") {
println(" \(fontName)")
}
}
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
extension Optional {
func try<U>(f: (T) -> U) -> Optional<U> {
if let unwrapped = self {
return f(unwrapped)
} else {
return nil
}
}
}
// CHEFS!!!
import Darwin
var peeps = [
"Tom",
"Chris",
"Connie",
"Rob",
"Yeti",
]

Hi there, There's no downside to opening connections on initialization or after forking, even if you don't use the connections often. Aside from reducing the chance for connection errors during the request loop, you'll also speed up your request loop by not spending time establishing new connections. I definitely recommend making this change if you can. For Resque, there's unfortunately no way around the fact that every job is run inside a forked process and can't inherit or share any connections. You'll have to open a new Redis connection for every Resque job that uses Redis. The best way to do this inside the "after_fork" Resque hook. If you use ActiveRecord, it's likely that you're already establishing a new connection inside this hook. Here's what our after_fork hook looks like, in our config/initializers/resque.rb file:

Resque.after_fork do
  tries = 0
  begin
    $redis.client.reconnect
    ActiveRecord::Base.establish_connection
  rescue
@nottombrown
nottombrown / solution.csv
Created January 3, 2014 04:52
Solution to the Grouper Cuttlefish Challenge
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
f_gender f_age f_height f_shoe_size* f_number_of_pets* f_platinum_albums* f_weekly_workouts* f_number_of_siblings* f_pokemon_collected* f_facebook_friends_count f_facebook_photos_count m_gender m_age m_height m_shoe_size* m_number_of_pets* m_platinum_albums* m_weekly_workouts* m_number_of_siblings* m_pokemon_collected* m_facebook_friends_count m_facebook_photos_count became_friends
female 27 67 5 7.5 7.5 8 7 7.5 333 457 male 25 72 5.5 8 7.5 8 7.5 7.5 884 601 FALSE
female 23 68 6.5 8 7.5 8 7.5 7 1346 412 male 25 72 6.5 7.5 8 7.5 7.5 7.5 831 491 TRUE
female 25 68 5.5 8 7.5 7.5 8 7 284 229 male 26 69 5.5 7.5 7 8 7.5 7 427 230 TRUE
female 23 67 6.5 7.5 7.5 8 7 7 1418 230 male 26 74 6 7.5 6.5 7 7.5 7.5 2137 205 FALSE
female 29 69 5.5 7.5 7.5 7.5 8.5 7.5 705 135 male 30 71 6 8 7.5 8 7.5 7.5 454 263 TRUE
female 28 67 7 8 6.5 7.5 7.5 7.5 1881 230 male 34 75 6 7.5 7.5 7.5 8 7.5 71 15 FALSE
female 28 66 5.5 7.5 7.5 8 7.5 7.5 785 407 male 30 74 7.5 8.5 7.5 8.5 8.5 7.5 1829 439 FALSE
female 24 69 5 7 7.5 7.5 7.5 7.5 633
@nottombrown
nottombrown / sample.rb
Created August 15, 2013 03:05
Monkeypatch sample functionality into ActiveRecord
class ActiveRecord::Base
def self.sample(count=nil)
all_ids = (1..self.count).to_a
if count
ids = all_ids.sample(count)
self.where(id: ids)
else
id = all_ids.to_a.sample
self.find(id)
def e(s, v=[:+, :-, :*, :/])v.empty? ? s.to_i : s.split(v[0].to_s).map{|y| e(y, v[1..-1])}.reduce(v[0])end
p e('2') # 2
p e('2 * 12') # 24
p e('1-10+4*2') # -1
p e('1+50/2*3') # 76