Skip to content

Instantly share code, notes, and snippets.

View neilmiddleton's full-sized avatar
🏠
Working from home

Neil Middleton neilmiddleton

🏠
Working from home
View GitHub Profile
def stream(url, timeout)
http.stream do |chunk|
buffer << chunk
yield buffer
end
end
stream url, 20 do |buffer|
while line = buffer.slice!(/.+\n/)
end
EventMachine.run do
EventMachine::PeriodicTimer.new(15) { out << "\0" }
http = EventMachine::HttpRequest.new(url, keepalive: true, connection_timeout: 0, inactivity_timeout: 0).get
buffer = ""
http.stream do |chunk|
buffer << chunk
while line = buffer.slice!(/.+\n/)
puts line
end
$ h pg:index_usage -a bisley-production
<%
require 'cgi'
require 'uri'
begin
uri = URI.parse(ENV["DATABASE_URL"])
rescue URI::InvalidURIError
raise "Invalid DATABASE_URL"
end

Neil is the English Samurai at Heroku working as part of the Support Engineering team. Based in the UK working remotely Neil helps look after the 3 million + applications Heroku run on a daily basis whilst struggling to remember all their names.

@neilmiddleton
neilmiddleton / gist:5712976
Last active December 18, 2015 02:39
Unicorn config
worker_processes ENV["RAILS_ENV"] == 'production' ? 3 : 1
timeout 30
worker_processes ENV.fetch("WORKER_CONCURRENCY", 1).to_i
timeout ENV.fetch("UNICORN_TIMEOUT", 30).to_i

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discussions around concrete examples, not handy-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@neilmiddleton
neilmiddleton / gist:5109447
Created March 7, 2013 16:38
class variables
class Person
attr gender
def male?
@gender == 'male'
end
end
@neilmiddleton
neilmiddleton / gist:5100375
Last active December 14, 2015 14:28
read_only
module ActiveRecord
class Base
def read_only?
ENV["AR_READ_ONLY"] ||= false
end
def before_destroy
raise ActiveRecord::ReadOnlyRecord if read_only?
end
@neilmiddleton
neilmiddleton / heavy.rb
Created February 22, 2013 18:35
Nik's problem, but better
def heavy_decimal_count(a,b)
(a..b).select do |number|
chars = number.to_s.split('').collect{|x| x.to_i}
get_avg(chars) > 7
end
end
def get_avg(arr)
arr.inject{|sum,x| sum + x }.to_f / arr.size
end