Skip to content

Instantly share code, notes, and snippets.

require 'ruby-prof'
def profile_as(name)
if ENV['PROFILE']
RubyProf.start
yield
result = RubyProf.stop
@mikeauclair
mikeauclair / output.txt
Created January 4, 2017 22:36
Promise union type
± ./node_modules/.bin/flow check 039efe8|add_more_types*
test.js:18
18: getQQ().then(function(val){
^^^^ property `then`. Property not found in
18: getQQ().then(function(val){
^^^^^^^ Array
Found 1 error
describe('example', function() {
beforeEach(function(){
var scheduler = this.scheduler = new Rx.TestScheduler();
this.userEmails = this.scheduler.createHotObservable(
Rx.ReactiveTest.onNext(
210,
{email: 'bob@bob.com'}
),

Keybase proof

I hereby claim:

  • I am mikeauclair on github.
  • I am mikeauclair (https://keybase.io/mikeauclair) on keybase.
  • I have a public key whose fingerprint is 783C 1A28 9EE3 A88F BE4C 0FFB E2C7 0FC4 D157 FFB3

To claim this, I am signing this object:

#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
@mikeauclair
mikeauclair / gist:de976a2baeb182bdee61
Last active August 29, 2015 14:21
Post-punk, mod revival, UK New Wave

1977

  • The Clash - The Clash
  • Elvis Costello - My Aim Is True
  • The Jam - In the City
  • The Jam - This Is the Modern World
  • Wire - Pink Flag

1978

  • The Clash - Give 'Em Enough Rope
  • Elvis Costello & The Attractions - My Aim Is True
@mikeauclair
mikeauclair / person.scm
Created January 18, 2014 19:54
Closures are poor man's objects. Objects are poor man's closures.
(define person (lambda (first last)
(define setFirst (lambda (value) (set! first (list-ref value 0))))
(define setLast (lambda (value) (set! last (list-ref value 0))))
(lambda (method . args)
(case method
('first
(if (null? args)
first
(setFirst args)
)
@mikeauclair
mikeauclair / ProfilingGuide.md
Last active August 7, 2019 16:19
Profiling

Easy steps for CPU profiling a Rails app

  1. add ruby-prof to your gemfile (https://github.com/ruby-prof/ruby-prof)
  2. grab kcachegrind or qcachegrind (brew install qcachegrind graphviz on os x)
  3. plop development_profiler.rb in lib in your app
  4. wrap your questionable code in a prof block
  5. open the file in qcachegrind (It'll live in tmp/performance in your app)
class Account
#blahblah
def external_management
if appdirect?
@external_management ||= OpenStruct.new(:user_url => 'blah', :accont_url => 'blah')
end
end
#blahblah
end
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection