Skip to content

Instantly share code, notes, and snippets.

@jjb
jjb / sleep.coffee
Created January 18, 2018 17:40
Sleep in coffeescript
sleep = (ms)->
date = new Date()
loop
break if (new Date())-date > ms
# from https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep
# as foretold in a million passionate comments by programmers 'round the world,
# using this in business logic in javascript is a bad idea. but it sometimes comes in
# handy when trying to experiment with something in dev (like if you want to simulate
# a timeout)
@jjb
jjb / rails-timezones.md
Last active January 12, 2018 00:24
How to access the list of all timezones which are recognized by Rails

Time.find_zone! uses these two methods to look up strings:

  • ActiveSupport::TimeZone[time_zone]
  • TZInfo::Timezone.get(time_zone)

The lists they reference are these:

  • ActiveSupport::TimeZone.all.map(&:tzinfo).map(&:canonical_identifier) (150)
  • TZInfo::Timezone.all_identifiers (606)
@jjb
jjb / config.ru
Created October 17, 2017 20:52
How to log file descriptor count in a rails or rack application
require_relative 'config/environment'
class FileDescriptorLogger
def initialize(app)
@app = app
end
def call(env)
if 1000==rand(1001)
unclosed_files = 0
pg_dump --schema-only --no-privileges --no-owner DBNAME | awk 'RS="";/CREATE TABLE[^;]*;/' > DBNAME.sql
`gem install redis`
$: << '/app/vendor/bundle/ruby/2.4.0/gems/redis-3.3.3/lib'
require 'redis'
@jjb
jjb / file.md
Last active March 16, 2017 22:19 — forked from wam/gist:a86c51eaad03689a14fcd0d58e6cca0c
converting img tags to ruby image_tag helper

intro

Goal is to convert

<img src="<%= ENV["IMAGE_URL"] %>/icons/app-ui-logo-white.png" id="topbar-logo" alt="Freedom logo">

to

sudo port selfupdate
sudo port install ruby32 # will include readline
sudo port select --set ruby ruby32
### >>> OPEN A NEW TERMINAL!!! <<<
### otherwise, the configuration won't point to the correct version of readline, no matter what you do.
### not sure if this is "through" the ruby binary, or something else in the environment
### i just saved you 17 hours of your life, you're welcome
curl -OL https://github.com/thoughtbot/gitsh/releases/download/v0.14/gitsh-0.14.tar.gz
@jjb
jjb / file.md
Last active September 13, 2021 17:46
Trying to figure out performance impact of RUBY_GC_HEAP_GROWTH_FACTOR
function alert {
if (( $? == 0 )) then
unicornleap > /dev/null &
say -v trinoids 'successfully done'
else
say -v bad 'failed'
fi
}
➔ time sudo port install phantomjs
---> Fetching archive for phantomjs
---> Attempting to fetch phantomjs-2.0.0_0.darwin_14.x86_64.tbz2 from http://packages.macports.org/phantomjs
---> Attempting to fetch phantomjs-2.0.0_0.darwin_14.x86_64.tbz2.rmd160 from http://packages.macports.org/phantomjs
---> Installing phantomjs @2.0.0_0
---> Activating phantomjs @2.0.0_0
---> Cleaning phantomjs
---> Updating database of binaries
---> Scanning binaries for linking errors
---> No broken files found.