Skip to content

Instantly share code, notes, and snippets.

View jonsmock's full-sized avatar

Jonathan Smock jonsmock

View GitHub Profile
@jonsmock
jonsmock / fox-goose-beans.clj
Last active July 4, 2017 14:00
Puzzle solutions in core.logic
;; https://en.wikipedia.org/wiki/Fox,_goose_and_bag_of_beans_puzzle
(ns fun.puzzle1
(:require [clojure.core.logic :as l]))
(defn pick-one [el rst col]
(l/conde
[(l/conso el rst col)]
[(l/fresh [not-taken maybe-taken rst-not-taken]
(l/conso not-taken maybe-taken col)
@jonsmock
jonsmock / gist:2784413
Created May 24, 2012 21:43
Trying to use a transform binding instead of a computed property
App.ticketsController = Em.ArrayController.create({
content: Em.A();
});
App.backlogController = Em.ArrayController.create({
contentBinding: Em.Binding.transform(function(value, binding) {
return value.filter(function(item, index, enumerable) {
return (item.get('assigned') == undefined);
});
@jonsmock
jonsmock / gist:2588878
Created May 3, 2012 20:06
Possible solution for place mutation (somewhat functional approach)
# in board initialize
lookup = PlaceLookup.new
lookup.add Buildable.new, Coord.new(3, 4) # coords would be calculated from land hexes
# later
player = Player.new
PlaceLookup.build_at player, Coord.new(3, 4)
PlaceLookup.at Coord.new(3, 4) # => Settlement.new
The PlaceLookup mutates behind the scenes. So potential impl of #build_at is
@jonsmock
jonsmock / gist:1622673
Created January 16, 2012 20:03
backbone sandbox
<html>
<head>
<title>REPL!</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js" type="text/javascript"></script>
<script src="http://documentcloud.github.com/backbone/test/vendor/underscore-1.1.6.js" type="text/javascript"></script>
<script src="http://documentcloud.github.com/backbone/backbone.js" type="text/javascript"></script>
<script src="https://raw.github.com/PaulUithol/Backbone-relational/master/backbone-relational.js" type="text/javascript"></script>
mspec ./core/string/modulo_spec.rb
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.2.0]
...............................................F................................................................
1)
String#% pads with zeros using %E with Inf, -Inf, and NaN FAILED
Expected " -INF"
to equal "-000000INF"
/Users/jonsmock/Projects/mspec/lib/mspec/expectations/expectations.rb:15:in `fail_with'
@jonsmock
jonsmock / 0_the_explanation.txt
Created December 22, 2011 00:57
Oh the conditionals!
This example is not my real app, but it's modeled pretty closely to it.
My mom schedules a couple hundred employees at a local warehouse. In their
system, a worker can earn "points" for being late or missing shifts. Here
we have a sort of summary screen for my mom, who may need to follow up with
new employees or discipline employees with concerning levels of points.
Questions that arise as I code something like this:
- Which objects deserve presenters?
- Should I allow HTML in my presenters?
@jonsmock
jonsmock / etc_hosts
Created September 13, 2011 01:45
3 failures on OSX Lion, running branch 2.0.0pre in the cloned directory
~/Projects/rubinius$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
@jonsmock
jonsmock / comment_weeder_test.rb
Created June 16, 2011 19:22
TDD-ed CSS comment weeder
require 'test/unit'
class CommentWeeder
def initialize
reset
end
def process(char)
@trail += char