Skip to content

Instantly share code, notes, and snippets.

View bvandgrift's full-sized avatar

Ben Vandgrift bvandgrift

View GitHub Profile
@bvandgrift
bvandgrift / deploy.sh
Created October 20, 2012 16:27
deploy script for pushing compiled nanoc to github pages. see http://bvandgrift.github.com/nanoc-pages-demo
#!/usr/bin/env bash
if [[ -z $1 ]]; then
echo "usage: deploy \"commit message\""
else
echo "Deploying with commit message: $1"
cd output
git add .
git commit -am "$1"
@bvandgrift
bvandgrift / ben's 8 lb guiness chili
Created November 25, 2013 14:14
a chili recipe. made with guiness, and 8lbs of the primary ingredients
From the Dawn of Time it came.
You'll need a spice grinder, a skillet, and either a dutch oven or a really
large sauce pan with a lid. Or maybe a small stock pot.
First the Chili Powder:
makes 1/2 cup -- needless to say, you should be grinding the chilis and cumin fresh.
Grind the following dried chilis:
@bvandgrift
bvandgrift / player.rb
Created March 7, 2014 02:46
1st pass solution to bloc.io/ruby_warrior/9
class Player
MAX_HEALTH = 20
DYING_HEALTH = 10
def me
@game[:me]
end
@bvandgrift
bvandgrift / let-placement.clj
Created January 7, 2016 18:24
placing your peek inside of a dosync avoids potential thread conflict (from Clojure Applied forum)
;; response to: https://forums.pragprog.com/forums/352/topics/13835
;; this is a quick demonstration of the pitfalls in querying for a ref
;; outside of the accompanying transaction in which you plan on changing it.
(import '(java.util.concurrent Executors))
;; start list
(def slist (ref #{}))
Verifying that +bvandgrift is my blockchain ID. https://onename.com/bvandgrift
@bvandgrift
bvandgrift / attribute_requirements.rb
Created February 28, 2016 03:46
a terrible way to determine whether attrs on an ActiveRecord model are optional or required when using grape.
module AttributeRequirements
extend ActiveSupport::Concern
SQL_TYPE_MATCHERS = {
/^character varying/ => String,
/^text/ => String,
/^enum/ => String,
/^timestamp/ => DateTime,
/^integer/ => Integer,
@bvandgrift
bvandgrift / partials.js
Created March 31, 2016 18:46
fiddling around with the `arguments` construct in .js
// takes a fn and a number of arguments to append to the
// fn's argument list
var rPartial = function(fn, extras) {
var postArgs = [].slice.call(arguments).slice(1);
return function(vars) {
var preArgs = [].slice.call(arguments);
var allArgs = preArgs.concat(postArgs);
return fn.call(fn.this, ...allArgs);
};
@bvandgrift
bvandgrift / unicat.js
Last active August 5, 2016 23:11
return an array of unique elements from an arbitrary list of arrays
// why not let set and spread do all the work?
// arbitrary number of arrays, unique
function unicat(...arrays) {
let collector = [];
arrays.forEach((a) => {collector = collector.concat(a);});
return Array.from(new Set(collector).values());
}
// O(n), i think, if concat() is implemented sanely.
@bvandgrift
bvandgrift / lists.rb
Created September 1, 2016 20:51
for jason, closures
## off the top of my head, syntax problems are an exercise for the reader
list = [:a, 'list', 3, 1.15, {b: 'yes, really'}]
# a simple list comprehension.
list.each do |thing|
puts thing.class # or some triviality
end
# functions take blocks, by default -- a block is a closure over
@bvandgrift
bvandgrift / keybase.md
Created November 15, 2016 00:48
keybase verification

Keybase proof

I hereby claim:

  • I am bvandgrift on github.
  • I am bvandgrift (https://keybase.io/bvandgrift) on keybase.
  • I have a public key ASAf4orFDrtbzOXVMO64S8C44-wKfuSIdKy5-VCmHth31wo

To claim this, I am signing this object: