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
(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 / 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:

@dchelimsky
dchelimsky / output.txt
Created March 16, 2012 15:28
RSpec is not the reason your rails test suite is slow
[david: compare]$ # at this point we have a stock rails app with no minitest tests and one pending rspec example
[david: compare]$
[david: compare]$ time rake test
Run options:
# Running tests:
Finished tests in 0.030419s, 0.0000 tests/s, 0.0000 assertions/s.
(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
RSpec::Core::FilterManager
#include
merges inclusions
overrides previous inclusions with (via merge)
deletes matching opposites
with :locations
clears previous inclusions
does nothing when :locations previously set
with :line_numbers
clears previous inclusions