Skip to content

Instantly share code, notes, and snippets.

Justin Weiss justinweiss

Block or report user

Report or block justinweiss

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
justinweiss / npm-publish-fork
Last active Sep 6, 2019
Publish a version of an npm package to your own scope, without (permanently) changing package.json
View npm-publish-fork
#!/usr/bin/env ruby
require "json"
require "optparse"
$options = {}
def system!(*args)
puts "> #{args.join(" ")}"
system(*args) || raise("Error running #{args.join(" ")}: #{$?} ")
justinweiss / tiny_object_model.rb
Last active Nov 11, 2016
Sample code from my "Metaprogramming? Not Good Enough!" RubyConf 2016 talk.
View tiny_object_model.rb
# We'll start by inheriting from a BasicObject, with our two properties: state and behavior.
class TinyObject < BasicObject
attr_accessor :state
attr_accessor :behavior
# `add_method`, for adding a method implementation to a behavior / class's state.
behavior_add_method = lambda do |behavior, method_name, method|
behavior.state[:methods][method_name] = method
View gist:ee29cef4aa8a3dfaa742
### Keybase proof
I hereby claim:
* I am justinweiss on github.
* I am justinweiss ( on keybase.
* I have a public key whose fingerprint is 6FF0 E872 CACA 2A9A 8942 95E3 08F4 4018 35C2 8D55
To claim this, I am signing this object:
justinweiss / settings.rb
Created May 27, 2014
Simple settings for Rails
View settings.rb
require 'yaml'
require 'erb'
require 'ostruct'
class Settings < OpenStruct
def initialize(config_file_base_name)
super(YAML.load("config", "#{config_file_base_name}.yml"))).result)[Rails.env])
View filterable.rb
# Call scopes directly from your URL params:
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with the same name as the keys in <tt>filtering_params</tt>
# with their associated values. Most useful for calling named scopes from
View gist:8046343
module HashExtensions
def string_merge(other, separator = " ")
merge(other) {|key, old, new| old.to_s + separator + new.to_s}
justinweiss / DefaultKeyBinding.dict
Created May 19, 2011
Extra emacs keybindings in cocoa.
View DefaultKeyBinding.dict
/* Picked up from Help search on Key Bindings. Good stuff -shane */
/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
View book_spec.rb
def book_with_endorsements(endorsement_count)
book = Factory(:book)
endorsement_count.times do |n|
Factory(:endorsement, :book_id =>
justinweiss / init.el
Created Nov 4, 2008
get git root directory
View init.el
(defun my-git-root ()
(let* ((current-directory (file-name-directory buffer-file-name))
(git-directory (concat current-directory ".git")))
(while (and
(not (file-exists-p git-directory)))
(setq current-directory (file-name-directory (substring current-directory 0 -1)))
(setq git-directory (concat current-directory ".git")))
You can’t perform that action at this time.