Skip to content

Instantly share code, notes, and snippets.

View bonkydog's full-sized avatar

Brian Jenkins bonkydog

  • Nubank
  • SF Bay Area
View GitHub Profile
@bonkydog
bonkydog / configure-reader-tags.cljs
Last active December 17, 2015 04:09
Make ClojureScript's reader and writer properly namespace records. This is handy for sending records back and forth in EDN.
;; for (defrecord Design [id name]) in namespace tektite.model.design
(cljs.reader/register-tag-parser! "tektite.model.design.Design" tektite.model.design/map->Design)
(extend-protocol IPrintWithWriter
tektite.model.design/Design
(-pr-writer [coll writer opts]
(let [pr-pair (fn [keyval] (pr-sequential-writer writer pr-writer "" " " "" opts keyval))]
(pr-sequential-writer writer pr-pair "#tektite.model.design.Design{" ", " "}" opts coll))))
@bonkydog
bonkydog / gist:5548539
Last active December 17, 2015 04:09
Force clojure.tools.logging to use a specific logging package By default, clojure.tools.logging picks the logging package it prefers from whatever is available in your classpath. Found this solution at http://corfield.org/blog/post.cfm/real-world-clojure-logging Thanks, Sean!
(alter-var-root
(var clojure.tools.logging/*logger-factory*)
(constantly (clojure.tools.logging.impl/log4j-factory)))
@bonkydog
bonkydog / profiles.clj
Created May 9, 2013 13:47
big lein search pages
{:user
{:search-page-size 100000}}
(ns tektite.client.action
(:require
[tektite.client.util :refer [log]]
[tektite.client.view :as view]
[tektite.client.route :as route]
)
(:require-macros
[tektite.client.macro :as macro]
))
@bonkydog
bonkydog / condp-router.cljs
Last active December 16, 2015 23:59
condp example
(condp re-matches fragment
#"^#$" (home-page)
#"^#designs$" (design-index)
#"^#designs/(.*)$" :>> #(design-edit (get % 1))
(undefined-route fragment))
@bonkydog
bonkydog / modernize_ruby_hash.rb
Created November 17, 2012 01:00
modernize ruby hash syntax
'{:type=>"Product", :client_id=>nil}'.gsub(/:(\w+)\s*=>\s*([^,)}]*)/, '\1: \2')
@bonkydog
bonkydog / escape_xpath_single_quotes.rb
Created November 13, 2012 06:13
escape single quotes for xpath in ruby
def escape_single_quotes_for_xpath(string)
if string =~ /'/
%[concat('] + string.gsub(/'/, %[', "'", ']) + %[')] # horribly, this is how you escape single quotes in XPath.
else
%['#{string}']
end
end
@bonkydog
bonkydog / sinon_jasmine_fixtures.js.coffee
Created November 1, 2012 16:22
Bypass Sinon XHR mocking to load Jasmine Fixtures
beforeEach ->
sinon.FakeXMLHttpRequest.addFilter (httpMethod, url) ->
(httpMethod.match(/get/i) && url.match(/^\/?jasmine/)) != null
@bonkydog
bonkydog / jasmine_fixtures.rb
Created October 29, 2012 21:24
jasmine fixture generation
module JasmineFixtures
extend ActiveSupport::Concern
# Saves the markup to a fixture file using the given name
def save_fixture(name)
response.should be_success
fixture_path = File.join(Rails.root, '/spec/javascripts/fixtures')
fixture_file = File.join(fixture_path, name)
fixture = case name
when /\.html$/
@bonkydog
bonkydog / gist:3936435
Created October 23, 2012 03:11
recursive doall
(defn doall-recur [s]
(if (seq? s)
(doall (map doall-recur
s))
s))