Skip to content

Instantly share code, notes, and snippets.

View fizzbuzz.hs
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 Oct 13, 2011
Comedy markup from Sage Pay
View sagepay.html
<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>
View DemeterMateExample.rb
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 Jul 4, 2011
Avoiding Demeter violations in Rails
View demeter.rb
class Example < ActiveRecord::Base
# The rest of the class .....
def get_object_and_method method_name
assoc_methods = [
:push,
:concat,
:build,
View demeter.rb
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 Jun 29, 2011
Bash script for cygwin to save list of dirs to clipboard
View clipdirs.sh
find . -maxdepth 1 -type d | ruby -pe 'gsub(/^\.\/?/, "")' | grep '.' > /dev/clipboard
@skilldrick
skilldrick / gist:1034242
Created Jun 19, 2011
SICP craziness in JS
View gist:1034242
function segments(agenda) {
return agenda.segments;
}
function someThingElse(agenda) {
var segments = segments(agenda);
}
View gist:1034238
;;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 Mar 26, 2011
jsautotest not resetting runner
View gist:888344
#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)