Skip to content

Instantly share code, notes, and snippets.

joshsusser / try-bench.rb
Last active Aug 29, 2018
benchmarking && vs try
View try-bench.rb
module ActiveSupport
module NewTryable #:nodoc:
def try(*a, &b)
return unless a.empty? || respond_to?(a.first)
return public_send(*a, &b) unless a.empty?
return nil unless block_given?
return instance_eval(&b) if b.arity == 0
yield self
joshsusser /
Created Mar 20, 2018
mandelbrot renderer - my first Rust program
extern crate image;
extern crate num_complex;
use std::fs::File;
use image::{ImageBuffer, Luma};
use num_complex::Complex;
fn main() {
// for a 3 x 2 image: (-2,-1) to (1,1)
joshsusser /
Last active Apr 2, 2019
languages I've been paid to program in
  1. assembler
  2. bash
  3. BASIC
  4. C
  5. C++
  6. Dylan (aka Ralph)
  7. HyperTalk
  8. Java
  9. JavaScript
  10. Lisp
joshsusser / dot.gitconfig
Last active Apr 7, 2017
git recent - remote branches sorted by recent update
View dot.gitconfig
recent = "!git fetch --prune && git for-each-ref --sort='-committerdate' refs/remotes/origin/ --format='%(committerdate:iso) %(objectname:short) %(refname:short)'"
joshsusser / gist:9793740
Created Mar 26, 2014
git - list remote branches ordered by recent activity
View gist:9793740
git for-each-ref --sort=-committerdate refs/remotes/origin/ --format='%(committerdate:short) %(refname:short)'
joshsusser / gist:9241494
Created Feb 27, 2014
nuclear physics limerick
View gist:9241494
the alchemist turned lead to gold
as tales through the ages have told
but alpha decay
meant the gleam didn't stay
so those isotopes never got old
joshsusser /
Last active Dec 14, 2015
I just wrote my representative asking she sponsor legislation requiring anti-theft features on smartphones.

Dear Congresswoman Pelosi,

I am writing about an issue in the interaction of technology, crime, and personal safety. I am a resident of San Francisco and live in the 12th District, so I approach you as my representative.

Here in the Castro, as in many urban areas, we are suffering with a crime wave of smartphone muggings. The standard mugging now involves one mugger grabbing the phone and running off, while one or more accomplices lay in wait to ambush and assault the victim if they give chase. A good friend of mine was mugged this way last week, and the reports of similar muggings keep coming in.

While there are things individuals and the community can do to protect ourselves, I think phone manufacturers and carriers can act far more effectively. The problem is that there is no financial incentive for them to take action. On the contrary, they benefit financially every time a phone is stolen and a replacement must be purchased, or someone who acquires a stolen phone pays for cellular service.

**I would l

joshsusser / gist:4192298
Created Dec 3, 2012
ActiveRecord Migrations cleanup opportunities
View gist:4192298

ActiveRecord Migrations cleanup opportunities

  1. Merge Migration and MigrationProxy code into AR::SchemaMigration
  2. change ActiveRecord::Migrator.schema_migrations_table_name to ActiveRecord::SchemaMigration.table_name
  3. Separate tests for schema dump from structure dump.
joshsusser / injections.rb
Created May 9, 2012
Challenge: implement enumerable methods using #inject instead of #each.
View injections.rb
def collect(&block)
inject([]) { |memo, obj| memo << }
def detect(&block)
inject(nil) { |memo, obj| memo ||= obj if }
def reject(&block)
inject([]) { |memo, obj| ? memo : memo << obj }
joshsusser / silence_assets.rb
Created Apr 17, 2012
put in config/initializers to silence asset logging in Rails development mode
View silence_assets.rb
if Rails.env.development?
Rails.application.assets.logger ='/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'] =~ %r{^/assets/}