Skip to content

Instantly share code, notes, and snippets.

@skilldrick
skilldrick / fizzbuzz.hs
Created November 2, 2011 23:35
FizzBuzz
fizzBuzz max = [fizzBuzzConvert x | x <- [1..max]]
fizzBuzzConvert x
| x `mod` 15 == 0 = "FizzBuzz"
| x `mod` 3 == 0 = "Fizz"
| x `mod` 5 == 0 = "Buzz"
| otherwise = show x
@skilldrick
skilldrick / sagepay.html
Created October 13, 2011 09:49
Comedy markup from Sage Pay
<tr>
<td bgcolor="#FFFFFF" align="right" colspan="2">
<a href="#" onmouseover="activate('login')" onmouseout="inactivate('login')" onclick="submitTheForm('GetPasswordForm','login')">
<img name="login" src="https://support.sagepay.com/GetPassword/images/btnProceed.gif" alt="" border="0" align="right" title="Click here to log into the system">
</a>
</td>
</tr>
class Person < ActiveRecord::Base
has_many :friends
demeter_mate :friends, :with => :find, :create
end
# This gives:
# :find_friend, :create_friend
# as well as the other variations of inflection and order
@skilldrick
skilldrick / demeter.rb
Created July 4, 2011 21:55
Avoiding Demeter violations in Rails
class Example < ActiveRecord::Base
# The rest of the class .....
def get_object_and_method method_name
assoc_methods = [
:push,
:concat,
:build,
class User < ActiveRecord::Base
# ...
def method_missing method, *args
if method.to_s.starts_with? 'find'
reading_lists.find *args
else
super
@skilldrick
skilldrick / clipdirs.sh
Created June 29, 2011 14:21
Bash script for cygwin to save list of dirs to clipboard
find . -maxdepth 1 -type d | ruby -pe 'gsub(/^\.\/?/, "")' | grep '.' > /dev/clipboard
@skilldrick
skilldrick / gist:1034242
Created June 19, 2011 12:49
SICP craziness in JS
function segments(agenda) {
return agenda.segments;
}
function someThingElse(agenda) {
var segments = segments(agenda);
}
@skilldrick
skilldrick / gist:1034238
Created June 19, 2011 12:45
SICP craziness
;;segments is a function that takes an agenda and returns its segments
(define (segments agenda) (cdr agenda))
;;Then, inside another function:
(let ((segments (segments agenda)))
;;In this let, segments is the return value of segments. WTF.
)
@skilldrick
skilldrick / gist:888344
Created March 26, 2011 14:56
jsautotest not resetting runner
#This happens after saving src/request.js
2011-03-26 14:54:19 Running GetRequestTest,ReadyStateHandlerTest,RequestTest,PostRequestTest
Chrome: Runner reset.
................
Total 16 tests (Passed: 16; Fails: 0; Errors: 0) (6.00 ms)
Chrome 10.0.648.133 Linux: Run 16 tests (Passed: 16; Fails: 0; Errors 0) (6.00 ms)