Skip to content

Instantly share code, notes, and snippets.

@pithyless
pithyless / spec_helper.rb
Last active August 29, 2015 13:58
Every time I'm copy+pasting some spec_helper.rb basics.
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.order = "random"
config.fail_fast = true
config.filter_run :focus
config.filter_run_including :focused => true
config.run_all_when_everything_filtered = true
config.alias_example_to :fit, :focused => true
@pithyless
pithyless / todo
Created December 16, 2014 12:44
Reagent quickstart
1. Get lein
lein - http://leiningen.org/
2. `lein new reagent <awesome-project>`
3. Some changes to project.clj from last night's talk:
:dependencies [[org.clojure/clojure "1.7.0-alpha4"]
[org.clojure/clojurescript "0.0-2371"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
[reagent "0.4.3"]
;;; Use experimental fork of DataScript from https://github.com/allgress/datascript to handle undo and per-query subscriptions
(ns reagent-test.core
(:require [reagent.core :as reagent :refer [atom]]
[datascript :as d]
[cljs-uuid-utils :as uuid]))
(enable-console-print!)
(defn bind
([conn q]
@pithyless
pithyless / core.cljs
Last active August 29, 2015 14:20 — forked from luxbock/core.cljs
(ns freactive-datascript.core
(:require [datascript :as d]
[datascript.core :as dc]
[clojure.data :as data]
[freactive.core :as f :refer [IReactive
*invalidate-rx*
*trace-capture*]]))
;;; Playground ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@pithyless
pithyless / template.html
Created January 1, 2012 13:14 — forked from steveklabnik/template.html
I always end up typing out the minimal (for me) html5 stuff. so here it is.
<!doctype html >
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<nav></nav>
</body>
</html>
@pithyless
pithyless / after.rb
Created January 1, 2012 13:17 — forked from steveklabnik/after.rb
dont load rails!
require 'active_record'
require "#{Rails.root}/app/models/user"
describe User do
it "does something sweet"
it "does something cool"
end
@pithyless
pithyless / match_method.rb
Created February 8, 2012 08:37 — forked from avdi/match_method.rb
Defining method_missing and respond_to? in one fell swoop
# Do you ever define #method_missing and forget #respond_to? I sure
# do. It would be nice if we could do them both at the same time.
module MatchMethodMacros
def match_method(matcher, &method_body)
mod = Module.new do
define_method(:method_missing) do |method_name, *args|
if matcher === method_name.to_s
instance_exec(method_name, *args, &method_body)
else
@pithyless
pithyless / group_of_thingies.rb
Created February 8, 2012 08:40 — forked from Peeja/group_of_thingies.rb
Test a block in Ruby
class GroupOfThingies
attr_accessor :thingies
# Use like this:
#
# group_of_thingies = GroupOfThingies.new
# group_of_thingies.each do |thing|
# puts "Check out this awesome thing: #{thing}!"
# end
#
@pithyless
pithyless / gazebo.rb
Created April 1, 2012 16:04
DCI via SimpleDelegator and a hint of metaprogramming
get '/give/me/gazebo/not/gazelle/:min_size' do
pricing = PriceCalculator.new
ParamsExtractor.new(pricing).parse(params)
GazelleFinder.new(pricing).find_all_gazelles
GazelleFilter.new(pricing).remove_sick_gazelles # pricing has access to #gazelles
GazeboBuilder.new(pricing).calculate_size_of_gazebo
GazeboPricer.new(pricing).calculate_final_price # pricing no longer has #gazelles
@pithyless
pithyless / custom_assertions.rb
Created July 23, 2012 12:33
minitest samples
# https://gist.github.com/2032303
module MiniTest::Assertions
def assert_palindrome(string)
assert string == string.reverse, "Expected #{string} to read the same way backwards and forwards"
end
def assert_default(hash, default_value)
assert default_value == hash.default, "Expected #{default_value} to be default value for hash but was #{hash.default.inspect}"
end