Skip to content

Instantly share code, notes, and snippets.

View dchelimsky's full-sized avatar

David Chelimsky dchelimsky

  • Retired
  • Chicago, IL, USA
View GitHub Profile
@dchelimsky
dchelimsky / exercise_specs.clj
Created August 30, 2019 21:18
exercise specs
(ns exercise-specs
(:require [clojure.test :as t :refer [deftest is]]
[clojure.string :as str]
[clojure.spec.alpha :as s]
[clojure.tools.namespace.find :as namespace.find]
[clojure.tools.namespace.parse :as namespace.parse]
[clojure.java.io :as io])
(:import (java.io PushbackReader)))
(def ^:dynamic *num-tests* 10)
@dchelimsky
dchelimsky / keybase.md
Created August 9, 2017 15:34
keybase.md

Keybase proof

I hereby claim:

  • I am dchelimsky on github.
  • I am dchelimsky (https://keybase.io/dchelimsky) on keybase.
  • I have a public key ASB3AiFZ1XwvHdnlZ8iycD-sWJxNiNTnP0P9QAtUD03Hngo

To claim this, I am signing this object:

diff --git a/src/semantic_csv/core.clj b/src/semantic_csv/core.clj
index bfb3972..6f780cb 100644
--- a/src/semantic_csv/core.clj
+++ b/src/semantic_csv/core.clj
@@ -213,6 +213,19 @@
;; pipeline.
+;; input - lazy seq of rows
+;; out - map of col-names to casting-fns
(ns multi-arity-v-varargs.core
(:require [criterium.core :refer [quick-bench]])
(:gen-class))
(defn varargs [arg1 & [arg2 arg3]]
42)
(defn multi-arity
([arg1] 42)
([arg1 arg2] 42)
@dchelimsky
dchelimsky / strftime-date-datetime.rb
Created June 18, 2014 01:44
strftime for Time and DateTime
DateTime.new(2014,1,2,3,4,5.678).strftime("%L")
# => "678"
Time.new(2014,1,2,3,4,5.678).strftime("%L")
# => "677"
(defn chainable?
([words]
((complement not-any?) #(chainable? % (clojure.set/difference words %)) words))
([word others]
(letfn [(levenshtein [str1 str2]
(cond (empty? str1) (count str2)
(empty? str2) (count str1)
:else
(let [cost (if (= (first str1) (first str2)) 0 1)]
(min (inc (levenshtein (rest str1) str2))
@dchelimsky
dchelimsky / composer.rb
Last active December 24, 2015 13:49
Prototype higher order function to compose lambdas in Ruby. Result of working with Matt Wynne on a means of wrapping filters in Cucumber (Ruby).
require 'wrong/adapters/rspec'
# (apply comp fns) in clojure
module Composer
def compose((*rest, last))
last ||= ->(x){x}
rest_reversed = rest.reverse_each
lambda do |*args|
@dchelimsky
dchelimsky / decomplected.rb
Last active December 23, 2015 16:39
Proof of concept (absolute hack - do not use this for anything but experimentation) of ideas discussed in http://blog.davidchelimsky.net/slides/a-rubyist-in-clojure-land at slide #52
class RSpec::Core::ExampleGroup
class << self
alias it describe
alias wrapped_example example
def example(&block)
wrapped_example { assert &block }
end
end
end
@dchelimsky
dchelimsky / restart_process_spec.rb
Last active December 21, 2015 15:29
Another approach to spec'ing message expectations without caring about return values, as described in http://tatey.com/2013/08/24/dont-care-about-the-return-value-of-outgoing-commands/
describe Task::RestartProcesses do
describe '#run_with_error' do
let(:client) { double('HerokuClient').as_null_object }
let(:logger) { double('Logger').as_null_ojbect }
let(:task) { Task::RestartProcesses.new logger: logger }
before do
# Inject Dependencies
task.client = client
2.0.0-p0 :002 > require 'date'
=> true
2.0.0-p0 :003 > DateTime.parse('2013-01-01') == '2013-01-01'
=> false
2.0.0-p0 :004 > require 'active_support/core_ext.rb'
=> true
2.0.0-p0 :005 > DateTime.parse('2013-01-01') == '2013-01-01'
=> true