Skip to content

Instantly share code, notes, and snippets.

@joshsusser
joshsusser / try-bench.rb
Last active August 29, 2018 17:47
benchmarking && vs try
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
end
@joshsusser
joshsusser / mandel.rs
Created March 20, 2018 05:19
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
joshsusser / languages.md
Last active April 2, 2019 22:36
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
joshsusser / dot.gitconfig
Last active April 7, 2017 20:07
git recent - remote branches sorted by recent update
[alias]
recent = "!git fetch --prune && git for-each-ref --sort='-committerdate' refs/remotes/origin/ --format='%(committerdate:iso) %(objectname:short) %(refname:short)'"
@joshsusser
joshsusser / gist:9793740
Created March 26, 2014 21:15
git - list remote branches ordered by recent activity
git for-each-ref --sort=-committerdate refs/remotes/origin/ --format='%(committerdate:short) %(refname:short)'
@joshsusser
joshsusser / gist:9241494
Created February 27, 2014 00:01
nuclear physics limerick
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
joshsusser / brick.md
Last active December 14, 2015 23:29
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
joshsusser / gist:4192298
Created December 3, 2012 02:48
ActiveRecord Migrations cleanup opportunities

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
joshsusser / injections.rb
Created May 9, 2012 16:31
Challenge: implement enumerable methods using #inject instead of #each.
def collect(&block)
inject([]) { |memo, obj| memo << block.call(obj) }
end
def detect(&block)
inject(nil) { |memo, obj| memo ||= obj if block.call(obj) }
end
def reject(&block)
inject([]) { |memo, obj| block.call(obj) ? memo : memo << obj }
@joshsusser
joshsusser / silence_assets.rb
Created April 17, 2012 22:34
put in config/initializers to silence asset logging in Rails development mode
if Rails.env.development?
Rails.application.assets.logger = Logger.new('/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/}
call_without_quiet_assets(env)
ensure