Skip to content

Instantly share code, notes, and snippets.

View bokmann's full-sized avatar

David Bock bokmann

View GitHub Profile
@bokmann
bokmann / gist:1912350
Created February 26, 2012 02:38
Another example for Mel...
# Mel, Here is another gist for you, perhaps slightly better than the last.
# First, the migrations are exactly the same, but this improves the left-right
# situation slightly.
# kit.rb
class Kit < ActiveRecord::Base
has_many :peer_kit_relations,
:class_name => "KitRelation",
:foreign_key => :left_kit_id
@bokmann
bokmann / gist:1915372
Created February 26, 2012 08:48
Mel's solution
# Mel,
#
# Sorry, I read too much of a previous problem I had into your question and
# probably spun you off in the wrong direction. Jim's comment points you in
# the right direction, but its only going to get you so far because of a
# limitation in combining polymorphism and HasManyThrough. You will run into
# this error trying to do what you want to do:
#
# http://rubydoc.info/github/rails/rails/master/ActiveRecord/HasManyThroughAssociationPolymorphicSourceError
#
@bokmann
bokmann / ActiveRepository.rb
Created March 27, 2012 16:15
ActiveRepository Strawman
# MOTIVATION: As rails apps are growing, people are noticing the drawbacks
# of the ActiveRecord pattern. Several apps I have seen, and several
# developers I have spoken to are looking towards other patterns for object
# persistence. The major drawback with ActiveRecord is that the notion
# of the domain object is conflated with what it means to store/retrieve
# it in any given format (like sql, json, key/value, etc).
#
# This is an attempt to codify the Repository pattern in a way that would
# feel comfortable to beginner and seasoned Ruby developers alike.
#
@bokmann
bokmann / ruby-noise-addendum.rm
Created June 1, 2012 03:34
FM Synthesis with portaudio and ruby noise
# FM Synthesis code I wrote whole dorking out with
# https://github.com/awwaiid/ruby-noise
# first, lets define some variables we can use
harmonic_ratio = 1.5 # overtones involving the perfect 5th
#harmonic_ratio = 1.33 # overtones involving the perfect 4th
#harmonic_ratio = 1.25 # overtones involving the major 3rd
#harmonic_ratio = 1.2 # overtones involving the minor 3rd
# harmonic ratios close to these values introduce a wobble
# characteristic of analog synthesizers. Diverge much
@bokmann
bokmann / gist:4137509
Created November 23, 2012 22:07
Chocolate Rum Pecan Pie
Chocolate Rum Pecan Pie
I've been experimenting with pecan pies for a long time; ever since an old colleague (Steve Smith)
challenged me to make one. The one on the back of the karo syrup jars is passable, but the
additions of chocolate and rum to this recipe turn it from on overly sweet kids favorite into
something tasting more like a fine chocolate liquor truffle.
Ingredients:
Your favorite no-frills pie crust
6 oz. semi-sweet chocolate

#Dave's Hallucinogenic Molé sauce

Molé sauce is an amazingly complex concoction. If you're going to make this, I suggest starting the way I did - learning the tastes from several different restaurants, then researching online various recipes, regional differences, and so on. Molé is kind-of the Mexican version of 'curry', in that there's no one recipe, no one common set of ingredients, but it typically consists of a thick spicy sauce based on regionally available spices and served with a stewed meat, typically over rice and/or with tortillas.

Calling a molé a 'sauce' is a bit of a simplification. Most of the time, I wouldn't want a true sauce to be this heavy, and completely dominate a dish. This is more like a 'spice and chili pepper stew'.

This recipe is probably best identified as a molé Poblano, but its not tracable to any one specific recipe. I took many different recipes, studied the ratios of various ingredients, made substitutions I thought appropriate (using honey when several recipes called

#!/bin/bash
# CentOS rbenv system wide installation script
# Forked from https://gist.github.com/1237417
# Installs rbenv system wide on CentOS 5/6, also allows single user installs.
# Install pre-requirements
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel \
make bzip2 autoconf automake libtool bison iconv-devel git-core
@bokmann
bokmann / JRuby Awesome Performance
Last active August 31, 2023 07:32
brief summary of massive performance improvements with JRuby
# Thee will be more information here when I share the entire problem space I'm working on, but
# in short, this is preview material for my second talk in a series called "What Computer Scientists Know".
# The first talk is on recursion, and goes through several examples., leading up to a problem based
# on a simple puzzle that initial estimates based on performance of a previous puzzle would take years
# to solve on modern computers with the techniques shown in Ruby. That sets the stage for improving the
# performance of that problem with threading, concurrency, and related tuning.
#
# The second talk is on threading and concurrency, touching on algorithmic performance as well.
# Using some knowledge of the problem (board symmetry, illegal moves, etc), we reduce the problem space
# to about .5% of what we initially thought it was. Still, the initial single threaded solution took more
@bokmann
bokmann / zlorpian
Last active December 25, 2015 13:39
a programming puzzle for learning how to contemplate counting in different bases.
Good afternoon fellow space travelers, thanks for coming along on this mission. We still have about a week
before we arrive at New Zlorpia, so please return your stasis tubes to their original upright position and
prepare for your mission briefing.
We are going to be negotiating a trade agreement with the Zlorpians for their supply of Farkle seeds. They
have a much different way of counting than we do, and I'm concerned that if we don't have a good way to
work with their number system, we'll be at a disadvantage in negotiations. Let me explain:
The zlorpians have a single arm that comes out of their forehead, with a hand that has 3 fingers. As a
result, our base-10 way of counting (based on our ten fingers) is as alien to them as their way is to us.
@bokmann
bokmann / triangle_peg.rb
Last active June 14, 2016 18:57
An example from "What Computer Scientists Know: Thinking Recursively, Part 2. In this example we are going to explore how we use our newfound knowledge of recursion to search through all the solutions of a simple puzzle using recursive backtracking.
# This is a programming chellenge from David Bock's series
# "What Computer Scientists Know". This is a problem that can
# be used to discuss a bunch of computer science topics, but
# as I'm providing most of the skeleton of the solution, the
# point of this exercise is to demonstrate 'recursive backtracking'.
# http://en.wikipedia.org/wiki/Backtracking
# this problem is based on the classic 'triange peg game', a common
# sight in roadside diners in America, in particular, Cracker