Skip to content

Instantly share code, notes, and snippets.

View dlongmuir's full-sized avatar

Derek Longmuir dlongmuir

View GitHub Profile
@dlongmuir
dlongmuir / diamond.clj
Last active August 29, 2015 14:13
Diamond Kata in (newb) Clojure
(def alphabet (map #(str (char %)) (range (int \A) (inc (int \Z)))))
(defn outside-spaces
[letter letters]
(loop [[current-letter & rest] letters
position 0]
(if (= current-letter letter)
position
(recur rest (inc position)))))
@dlongmuir
dlongmuir / objc_memory.m
Created May 15, 2014 22:49
Testing different ways of defining Objective-C variables
@interface VariableNoBrackets : NSObject
@end
@implementation VariableNoBrackets
NSString *aString;
- (instancetype)initWithString: (NSString *)newString {
self = [super init];
if (self) {
aString = newString;
}
(defn say-hello []
(println "Please type your name:")
(let [name (read)]
(println "Nice to meet you, " name)))
(def hello "123")
(println "blah blah")
(ns wizard)
(def nodes {:living-room "You are in the living room. A wizard is snoring loudly on the couch. "
:garden "You are in a beautiful garden. There is a well in front of you. "
:attic "You are in the attic. There is a giant welding torch in the corner. "})
;(nodes :living-room)
(defn describe-location [loc node-list]
(loc node-list))
(and (odd? 5) (odd? 7))
(or (odd? 4) (odd? 7))
(def *is-it-even* (atom nil))
(or (odd? 4) (reset! *is-it-even* true))
@*is-it-even*
;; cell
[1 2]
;; world
#{ [1 0] [1 1] [1 2]}
;; compute neighbors of a cell
(defn neighbors [[x y]]
(for [dx [-1 0 1]
dy (if (zero? dx)
@dlongmuir
dlongmuir / gcovr_runner.rb
Last active December 23, 2015 23:59
Get code coverage on Xcode5. Hacky but pragmatic.
#! /usr/bin/env ruby
workspace_name = %x[ls].split.find{ |file_name| file_name.include? 'xcworkspace' }
project_name = workspace_name.split('.')[0]
pwd = %x[pwd].strip
settings = %x[xcodebuild -workspace #{workspace_name} -showBuildSettings -scheme #{project_name}]
%x[xcodebuild -workspace #{workspace_name} test -scheme #{project_name} -destination OS=6.1,name=iPad -configuration Debug]
if $? == 0
full_build_root = settings[/BUILD_ROOT = (.*)/].split[2]
full_build_root[/(.*)\/Build\/Products/]
root_for_gcovr = $1
@dlongmuir
dlongmuir / calculator_form_controller.rb
Created October 27, 2012 19:54
Formotion with dynamic table
class CalculatorFormController < Formotion::FormController
attr_accessor :calc
def done
puts "row done #{@form.render}"
@calc.got_answers @form.render
new_form = Formotion::Form.new(@calc.get_questions)
@form = new_form
@form.controller = self
@dlongmuir
dlongmuir / ipfw_hooks.rb
Last active October 4, 2015 07:48
Networking steps for cucumber
Around('@no_connection_to_qaserver') do |scenario, block|
%x[sudo ipfw add 10 deny tcp from qaserver to me]
%x[sudo ipfw add 11 deny tcp from me to qaserver]
block.call
%x[sudo ipfw delete 11 > /dev/null 2>&1]
%x[sudo ipfw delete 10 > /dev/null 2>&1]
end
Around('@no_network') do |scenario, block|
%x[sudo ifconfig en1 down]
@dlongmuir
dlongmuir / env.rb
Created December 2, 2011 20:12
env.rb that greps for Frankified apps
require 'frank-cucumber'
temp_app_path= `find . -regex ".*[Ff]rankified\.app$"`.chomp
if temp_app_path.empty?
temp_app_path= `find ../build -regex ".*[Ff]rankified\.app$"`.chomp
end
if temp_app_path.empty?
temp_app_path= `find ~/Library/Developer/Xcode/DerivedData -regex ".*[Ff]rankified\.app$"`.chomp