Skip to content

Instantly share code, notes, and snippets.

@hby
hby / multi-vs-table.clj
Last active August 29, 2015 13:57
Comparing multimethod performance with table lookup
; As I was reading about multimethods I began to wonder if they
; would be a reasonable way to organize code that would normally
; do a table lookup based on some data in order to get at something
; (like a function in the Clojure case) to use to continue to process
; the data. There are times that I like to set up a table with functioanlity
; that can be keyed into in lieu of explicit conditional code. But that's
; beside the point. I wondered if there would be a significant difference
; in performance. If my memory is correct, Richard O'Keefe in The Craft of
; Prolog instilled in me that the only way to know these things is to
; benchmark them. I'm glad I did. I was a little surprised.
(ns haglure.core
(:require [net.cgrand.enlive-html :as html]))
(def layout
(html/html-resource "test.html"))
(defn scope [n]
(:data-scope (:attrs n)))
(def scopes (html/select layout [(html/attr? :data-scope)]))
@hby
hby / output of bundle exec rails s
Created August 7, 2014 04:50
rails server error
[ hby@Guardian ~/dev/MetaBahn/gits/cwb-rails-2 (git::dgm-works-with-frontend) ] bundle exec rails s
=> Booting Thin
=> Rails 4.1.2 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/Users/hby/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.2/lib/rails/application/configuration.rb:105:in `database_configuration': Cannot load `Rails.application.database_configuration`: (RuntimeError)
Could not load database configuration. No such file -
from /Users/hby/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.2/lib/active_record/railtie.rb:128:in `block (2 levels) in <class:Railtie>'
@hby
hby / shell session
Created August 2, 2015 19:04
planck try #1
[ hby@Guardian ~/dev/ClojureScript/mac-command-line/planck-demo ] ls
script.cljs unsorted.txt
[ hby@Guardian ~/dev/ClojureScript/mac-command-line/planck-demo ] cat script.cljs
#! /Users/hby/bin/planck
(->>
(slurp "unsorted.txt")
(re-seq #"\w+")
sort
(#(interleave %1 (cycle "\n")))
@hby
hby / explore.clj
Last active November 1, 2015 14:12
For safely exploring potentially large structures in the repl
(declare explore-map)
(declare explore-vector)
(declare explore-seq)
(defn explore
"Safely explore possibly large map/vector structures in the repl.
morv - map or vector or seq
threshold - if count is under threshold, recursively explore
peekn - if over threshold, recursivley explore peekn entries
and summarize rest"
[morv threshold peekn]