Skip to content

Instantly share code, notes, and snippets.

View mowat27's full-sized avatar

Adrian Mowat mowat27

  • Fort William, Scotland
View GitHub Profile
@mowat27
mowat27 / my-defn.clj
Created February 24, 2012 09:06
Example of using a macro to rewrite defn in Clojure
(ns homoiconic.my-defn)
; ----------- --- --- -- -- - -
(defn hello [what]
(str "hello " what))
(hello "world")
; ----------- --- --- -- -- - -
@mowat27
mowat27 / tsv_file_load.clj
Created May 28, 2012 13:25
EuroClojure Learnings: TSV file
; My "lightbulb" moment at EuroClojure 2012 was that clojure is at it's most
; powerful when you build abstractions in the data and keep the functions as
; generic as possible so you can chain them easily
; For example, here is some code I wrote a few months ago to parse a freebase TSV file
(def keywords {"id" "freebase_id"})
(defn override-keywords [field-name]
(let [alternative (get keywords field-name)]
(if (nil? alternative) field-name alternative)))
(defn get-field-names [line] (map override-keywords (str/split line #"\t")))
@mowat27
mowat27 / sketch.rb
Created June 29, 2012 16:04 — forked from mattwynne/sketch.rb
sketch for Matt Wynne
# Specs
describe "a sucessful create" do
it "redirects" do
Organization.any_instance.stub(:saved? => true)
controller = OrganizationsController.new
controller.should_receive(:redirect_to)
controller.create
end
end
@mowat27
mowat27 / resource_def.rb
Created June 29, 2012 17:00
Resource-driven framework thoughts
resource organisation do
responds_to do
get new {
success: -> {render "a page"},
error: (reason) -> {redirect_to some_error(reason)}
}
end
end
@mowat27
mowat27 / text_to_record.clj
Created July 15, 2012 10:24
Text stream to/from record structure sketch
(def pipe_delim_text
"Lorem|ipsum|dolor
sit|amet,|consectetur
")
(def fixed-width-text "122333455666")
(defrecstruct lorem-record
(:field1 (delimiter "|"))
(:field2 (delimiter "|"))
@mowat27
mowat27 / resource_model.rb
Created August 7, 2012 15:15
Rails ResourceModel
# Extracted from Matt Yoho's (https://github.com/mattyoho) talk at Scottish Ruby Conference 2012
# Exploiting the Resource Idiom - https://speakerdeck.com/u/mattyoho/p/exploiting-the-resource-idiom
#
module ResourceModel
def self.inherited(inheritor)
inheritor.class_eval do
include ActiveModel::Naming
include ActiveModel::Validations
include ActiveModel::Translation
@mowat27
mowat27 / hostname.sh
Created November 1, 2012 09:52
Linux Config Notes
echo HOST.DOMAIN.com > /etc/hostname
/bin/hostname -F /etc/hostname
/etc/init.d/httpd restart
# Add to /etc/hosts
127.0.0.1 HOST.DOMAIN.com
@mowat27
mowat27 / git_cheatsheet.md
Last active December 12, 2015 02:49
Cheat sheet for git

Branches

List remote branches

git branch -a

Checkout a remote branch (from origin)

git checkout -b branch_name origin/branch_name
@mowat27
mowat27 / aikido_principles.md
Last active December 12, 2015 06:08
Principles of Aikido

Four major principles to unify mind and body

  • Keep one-point.
  • Relax completely.
  • Keep weight underside.
  • Extend Ki.

Five Principles of Ki-Aikido

  • Ki is extending.
@mowat27
mowat27 / calculator.rb
Last active December 21, 2015 11:29
First stab at the string calculator kata using red-refactor-green and dependency injection as my only refactoring
describe "calculator" do
let(:calculator) { CalculatorFactory.new.create }
it "adds numbers" do
calculator.calculate("1 + 2").should == 3
end
it "adds big numbers" do
calculator.calculate("11 + 22").should == 33
end