Skip to content

Instantly share code, notes, and snippets.

Chris Hapgood cch1

Block or report user

Report or block cch1

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cch1
cch1 / test_helpers.clj
Last active Dec 31, 2015
feedback streams
View test_helpers.clj
(ns test-helpers
(:import [java.io InputStream OutputStream IOException])
(:require [clojure.java.io :as io]))
(defn- swap-!
"Atomically swaps the value of atom to be:
(apply f current-value-of-atom args). Note that f may be called
multiple times, and thus should be free of side effects. Returns
the value prior to the update."
[a f & args]
View pick-and-rename.clj
(let [undefined-value (atom :undefined-value)]
(defn pick-and-rename [col pick-map]
(apply assoc
{}
(flatten
(filter (fn [[k v]]
(not (= v undefined-value)))
(map (fn [[k v]]
[v (get col k undefined-value)])
pick-map))))))
@cch1
cch1 / mocking-ex.clj
Created Feb 6, 2012 — forked from mwmitchell/mocking-ex.clj
with metaconstants
View mocking-ex.clj
(facts "/locations/:id/rates should limit the rate response count by the :limit param"
(let [params [:check_in (gen-check-in)
:check_out (gen-check-out)
:guests 1
:rooms 1
:limit ...limit...]]
(apply location-rate-request (:tid location-one) params) => truthy
(provided
(apij.models.hotel-search/search
(contains {:params (contains {:limit apij.views.rates.common/max-hotels})}))
View gist:1051772
;;(require 'copterj.git-version) ;; Pick up DRY'd version numbers
(require 'clojure.contrib.io) ;; Needed to locate newrelic
(let [java-agent (str "-javaagent:" (clojure.contrib.io/pwd) "/lib/newrelic.jar")]
(defproject apij ~(copterj.git-version/git-describe)
:description "Hotelicopter's API"
:dependencies
[[com.hotelicopter/copterj "1.0.0-SNAPSHOT"]
@cch1
cch1 / Emacs.md
Created May 6, 2011
Setting up Emacs daemon on OS X
View Emacs.md

Setting up Emacs daemon on OS X

Tired of waiting for emacs to start on OS X? This step by step guide will teach you how to install the latest version of emacs and configure it to start in the background (daemon mode) and use emacsclient as your main editor.

Install Homebrew

First you'll need to install the [Homebrew package manager][brew] if yo haven't already. It is amazing.

@cch1
cch1 / deploy.rb
Created Oct 19, 2010
Post-Migration version
View deploy.rb
# Please install the Engine Yard Capistrano gem
# gem install eycap --source http://gems.engineyard.com
require "eycap/recipes"
require 'new_relic/recipes'
# The following code has been lifted from config.rb
AppConfig = begin
require 'ostruct'
require 'yaml'
View Let-respond-to-do-the-heavy-action-cache-lifting.patch
From 36f25bf11b9e61b6361c829534dea2de0cf08acd Mon Sep 17 00:00:00 2001
From: Chris Hapgood <cch1@hapgoods.com>
Date: Mon, 11 Oct 2010 09:42:05 -0400
Subject: [PATCH] Let respond_to do the heavy action cache lifting
In determining the best content type for a response, let respond_to consider
available content types using existing logic. Work hard to ensure that
cached content has an extension to indicate its content type.
---
.../lib/action_controller/caching/actions.rb | 73 ++++++++++----------
View microseconds_benchmark.rb
require 'benchmark'
ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
FAST_ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(?:\.(\d+))?\z/
COUNT = 1000000
SRAND = 1455677931
DATETIME_STRING = "2010-01-12 12:34:56.%6.6i"
Benchmark.bm do |bench|
f = bench.report("Fast") do
View coerce_empty_strings.rb
# Recursively coerce empty string values in hash -particularly
# useful for HTTP POSTed forms.
# Values are coerced based on the rules mapping of params_hash keys to coerced values.
# See http://dev.rubyonrails.org/ticket/5694 for background
def self.coerce_empty_strings(params_hash, rules = {})
return unless params_hash
params_hash.each_pair do |k,v|
# AR::Base.extract_callstack_for_multiparameter_attributes can't handle nil values
unless k.include?('(')
params_hash[k] = rules[k.to_sym] if v.kind_of?(String) && v.empty?
@cch1
cch1 / scoped_associations.rb
Created Mar 31, 2009
Monkey patch for scoped associations
View scoped_associations.rb
module ActiveRecord
class Reflection::AssociationReflection
# Return a named scope instead of the bare ActiveRecord::Base subclass.
def klass_with_scope
k = klass_without_scope
options[:scope].nil? ? k : k.send(options[:scope])
end
alias_method_chain :klass, :scope
end
You can’t perform that action at this time.