Skip to content

Instantly share code, notes, and snippets.

View david-hodgetts's full-sized avatar

david hodgetts david-hodgetts

View GitHub Profile
@david-hodgetts
david-hodgetts / pre-commit
Created August 12, 2011 13:06
pre-commit git hook, runs rspec iff branch is master
#!/usr/bin/env ruby
# pre-commit git hook
# will run rspec if and only if current branch is master
# script adapted from http://book.git-scm.com/5_git_hooks.html
def run_tests
html_path = "/tmp/git_hook_spec_results.html"
`rspec -f p -f h -o #{html_path} spec` # run the spec. send progress to screen. save html results to html_path
@david-hodgetts
david-hodgetts / to_haml.rb
Created September 5, 2011 09:33
Convert views to Haml
class ToHaml
def initialize(path)
@path = path
end
def convert!
Dir["#{@path}/**/*.erb"].each do |file|
`html2haml -rx #{file} #{file.gsub(/\.erb$/, '.haml')}`
end
end
@david-hodgetts
david-hodgetts / convert_tags.rb
Created January 29, 2012 21:43
convert tags for nicolas
# variables
input_filename = 'in.html'
output_filename = 'result.htm'
#
def convert_line(line)
regex = /(TAGS=".*")/
line.gsub(regex) { $1.gsub(/\s+/, ',') }
end
@david-hodgetts
david-hodgetts / make_fake_users.rb
Created February 15, 2012 09:46
make fake users
def make_user(how_many)
count = 0
tags = %w{ ancient brief early fast late long modern old old-fashioned quick rapid short slow swift young agreeable brave calm delightful eager faithful gentle happy jolly kind lively nice obedient proud relieved silly thankful victorious witty zealous big colossal fat gigantic great huge immense large mammoth massive miniature petite puny scrawny short small tall teeny teeny-tiny tiny }
how_many.times do
email = "david_#{count}@demainlalune.ch"
first_name = "david_#{count}"
last_name = "hodge_#{count}"
@david-hodgetts
david-hodgetts / VideoPlayer_SetVideoTexture
Created June 18, 2012 08:19
adaptation of function SetVideoTexture to work with unity 3.4
function SetVideoTexture(resourceName:String)
{
Debug.Log("changing video texture " + resourceName);
movieTexture = Resources.Load(resourceName) as MovieTexture;
if (movieTexture)
{
movieTexture.Play();
@david-hodgetts
david-hodgetts / make_me_work_01.py
Created November 28, 2012 18:27
exercise 01 for sae intro python course
# sae course
# problem solving with python
# make this script work
print make me work
print "i love video games""
prinl 10 * "3
@david-hodgetts
david-hodgetts / gist:5366970
Created April 11, 2013 20:37
4clojure #62 (with olange)
;; Take 1 (noter que lazy-cat retourne toujours une liste;
;; et que son implémentation utilise lazy-seq)
(defn iter1 [f x] (lazy-cat [x] (iter f (f x) ) ) )
(= (take 5 (iter1 #(* 2 %) 1))
[1 2 4 8 16])
(= (take 100 (iter1 inc 0))
(take 100 (range)))
(= (take 9 (iter1 #(inc (mod % 3)) 1))
(take 9 (cycle [1 2 3])))
@david-hodgetts
david-hodgetts / gist:5367088
Created April 11, 2013 20:56
Solution to 4Clojure problem 46
(fn flip-fn-args [f]
(fn [& rest] (apply f (reverse rest))))
@david-hodgetts
david-hodgetts / gist:5367378
Last active December 16, 2015 03:09
4Clojure problem 92 (Take One)
(fn roman
([s] (roman (seq s) 0))
([s v]
(let [c1 (first s)
c2 (second s)
c12 (list c1 c2)]
(if (empty? s) v
(cond
(= c12 '(\I \V)) (roman (drop 2 s) (+ v 4))
(= c12 '(\I \X)) (roman (drop 2 s) (+ v 9))
@david-hodgetts
david-hodgetts / gist:5367522
Created April 11, 2013 21:52
4Clojure problem 92 (Take Two)
(fn roman
([s] (roman (seq s) 0))
([s v]
(let [
rdigits {\M 1000, \D 500, \C 100, \L 50, \X 10, \V 5, \I 1}
sdigits {"IV" 4, "IX" 9, "XL" 40, "XC" 90, "CD" 400, "CM" 900}
c1 (first s)
c12 (str c1 (second s))
v1 (get rdigits c1 0)
v12 (get sdigits c12)]