Skip to content

Instantly share code, notes, and snippets.

Corey Haines coreyhaines

Block or report user

Report or block coreyhaines

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
View Editable.elm
module Editable exposing (..)
type Editable ofType
= NotEditing { value : ofType }
| Editing { originalValue : ofType, buffer : ofType }
value : Editable ofType -> ofType
value editable =
@coreyhaines
coreyhaines / churn script
Created Feb 16, 2011
Bash script to generate churn counts in git repo
View churn script
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 / Flow.elm
Last active Dec 13, 2019
General workflow-management
View Flow.elm
module Flow exposing (Flow(..), map, withDefault, mapDefault, view, update)
import Html
type Flow state
= NotRunning
| Running state
@coreyhaines
coreyhaines / state_spec.rb
Created Mar 21, 2012
Dealing with AR pollution
View state_spec.rb
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 / .rspec
Last active Sep 4, 2019
Active Record Spec Helper - Loading just active record
View .rspec
--colour
-I app
@coreyhaines
coreyhaines / maybe.ts
Last active Jun 19, 2019
Simple Maybe<T> approximation in typescript
View maybe.ts
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) {
@coreyhaines
coreyhaines / some_spec.rb
Created Mar 20, 2012 — forked from stevenharman/some_spec.rb
Using Rspec's "let" inside an "it" block. Crazy? Yes. Useful? Occasionally.
View some_spec.rb
describe "#mentions_story?" do
subject { described_class.new(file) }
let(:file) { "COMMIT_EDITMSG" }
before do
File.stub(:read).with(file) { example_commit_message(@relevant_part) }
end
context "commit message contains the special Pivotal Tracker story syntax" do
it "matches just the number" do
@relevant_part = "[#8675309]"
@coreyhaines
coreyhaines / old_school_use.rb
Created Sep 11, 2012
Environment-based initializers in Rails - USE THEM!
View old_school_use.rb
# what? why does your production code care what environment it is in? SILLY!
unless Rails.development? || Rails.test?
Slottd::CreatesReservationTimer.for(slot.id)
end
@coreyhaines
coreyhaines / Foldit.exs
Last active Apr 4, 2018
Convert a list of paths to a tree
View Foldit.exs
defmodule FolditTest do
use ExUnit.Case
doctest Foldit
def to_keyword([], keyword), do: keyword
def to_keyword([val], keyword) do
Keyword.update(keyword, nil, [val], fn existing -> [val | existing] end)
end
@coreyhaines
coreyhaines / timer.rb
Created Feb 4, 2012
Timer for coderetreat session
View timer.rb
#!/usr/bin/env ruby
# Usage ruby 2-minute-timer.rb "message to say when time is up"
# or just chmod +x timer.rb and ./timer.rb
# for more info, see http://coderetreat.org/profiles/blogs/new-session-idea-baby-steps
message = ARGV[0] || "times up"
minutes = 2
seconds = minutes*60
while(true)
You can’t perform that action at this time.