Skip to content

Instantly share code, notes, and snippets.

View dlongmuir's full-sized avatar

Derek Longmuir dlongmuir

View GitHub Profile
@dlongmuir
dlongmuir / btserver_killer.rb
Created November 2, 2011 14:33
BTServer killer
#!/usr/bin/env ruby
# Kill crazy BTServer processes when the iPad simulator is running and
# you wake your Mac from sleeping
seconds_between_checking = 30
kill_threshold_percent = 10.0
while true do
ps_out_full = %x[ps aux | grep BTServer]
@dlongmuir
dlongmuir / run_sdk_tests.rb
Created November 3, 2011 14:36
Run 'rake test' for all installed iOS sdks; good for iOS regressions
showsdks = %x[xcodebuild -showsdks | grep sdk | grep iphonesimulator]
results = []
showsdks.each_line do |sdkline|
sdk = /-sdk (\S+)/.match(sdkline)[1]
return_code = system("export IOS_SDK=#{sdk}; rake test")
results << "#{sdk} success?#{return_code}"
end
results.each do |r|
puts r
end
@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
@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 / 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 / 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
;; 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)
(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*
(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))
(defn say-hello []
(println "Please type your name:")
(let [name (read)]
(println "Nice to meet you, " name)))
(def hello "123")
(println "blah blah")