Skip to content

Instantly share code, notes, and snippets.

@coreyhaines
coreyhaines / .rspec
Last active April 11, 2024 00:19
Active Record Spec Helper - Loading just active record
--colour
-I app
@coreyhaines
coreyhaines / churn script
Created February 16, 2011 19:04
Bash script to generate churn counts in git repo
churn number and file name
git log --all -M -C --name-only | grep -E '^(app|lib)/' | sort | uniq -c | sort | awk 'BEGIN {print "count,file"} {print $1 "," $2}'
churn number and file name w/ limiting to last n commits
git log --all -n 5000 -M -C --name-only | grep -E '^spec/models' | sort | uniq -c | sort | awk 'BEGIN {print "count,file"} {print $1 "," $2}'
graph of churn number and frequency
git log --all -M -C --name-only | grep -E '^(app|lib)/' | sort | uniq -c | sort | awk '{print $1}' | uniq -c | sort | awk 'BEGIN { print "frequency,churn_count"} { print $1,$2}'
@coreyhaines
coreyhaines / Editable.elm
Last active August 25, 2022 05:11
type Editable
module Editable exposing (..)
type Editable ofType
= NotEditing { value : ofType }
| Editing { originalValue : ofType, buffer : ofType }
value : Editable ofType -> ofType
value editable =
def foo
p self
end
p self
foo
@coreyhaines
coreyhaines / my stats
Created December 8, 2011 21:08
Sample of my old custom stats file that adds spec_no_rails
if ENV['LOAD_RAILS'] == '1'
task :stats => "ma:add_no_rails_dirs_to_stats"
namespace :ma do
desc "Report code statistics (KLOCs, etc) from the application"
task :add_no_rails_dirs_to_stats do
require 'rails/code_statistics'
::STATS_DIRECTORIES << %w(NoRails\ Lib\ specs spec_no_rails/lib) if File.exist?('spec_no_rails/lib')
::CodeStatistics::TEST_TYPES << "NoRails Lib specs" if File.exist?('spec_no_rails/lib')
::STATS_DIRECTORIES << %w(NoRails\ Model\ specs spec_no_rails/model) if File.exist?('spec_no_rails/model')
@coreyhaines
coreyhaines / Flow.elm
Last active December 14, 2020 00:20
General workflow-management
module Flow exposing (Flow(..), map, withDefault, mapDefault, view, update)
import Html
type Flow state
= NotRunning
| Running state
@coreyhaines
coreyhaines / peano.pl
Last active April 19, 2020 20:31
Peano's Axioms in Prolog
% Peano's Axioms
:- module(peano, [
is_zero/1,
is_natural/1,
equal/2,
add/3,
subtract/3,
multiply/3,
divide/3
]).
@coreyhaines
coreyhaines / peano.pl
Created April 19, 2020 19:55
Peano's Axioms in Prolog
% Peano's Axioms
:- module(peano, [
is_zero/1,
is_natural/1,
equal/2,
pred/2
]).
/** Peano's Axioms
*
@coreyhaines
coreyhaines / state_spec.rb
Created March 21, 2012 21:05
Dealing with AR pollution
module CoderetreatLive::Coderetreats
# this Coderetreat gets loaded instead of the AR
class Coderetreat
include States
end
describe "The states a coderetreat can be in" do
let(:retreat) { Coderetreat.new }
example "Going through the day of a coderetreat" do
retreat.should be_not_started
retreat.start!
@coreyhaines
coreyhaines / maybe.ts
Last active June 19, 2019 19:16
Simple Maybe<T> approximation in typescript
type Maybe<T> = T | undefined;
function maybeMap<T, U>(mv: Maybe<T>, f: (v:T) => U) : Maybe<U> {
if(mv !== undefined) {
return f(mv);
}else{
return undefined;
}
}
function maybeBind<T, U>(mv: Maybe<T>, f: (v:T) => Maybe<U>) : Maybe<U> {
if(mv !== undefined) {