This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
import Control.Applicative | |
import Data.Monoid | |
import Test.QuickCheck | |
data JoinList m a = Empty | |
| Single m a | |
| Append m (JoinList m a) (JoinList m a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
data GUIEvent = KeyDownEvent { key_down__ctrl :: !Bool | |
, key_down__shift :: !Bool | |
, key_down__code :: !Int } | |
| MouseEvent { mouse__x :: !Int | |
, mouse__y ::!Int } | |
deriving (Show) | |
instance FromJSON GUIEvent where | |
parseJSON = withObject "GUIObject" parseGUIEvent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var count = 2; | |
var loader = $('.infinite-loader'); | |
$(window).scroll(function() { | |
if($(window).scrollTop() == $(document).height() - $(window).height()) { | |
if(count > total) { | |
return false; | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Input: | |
# choices = { | |
# 'color' => %w(blue red green), | |
# 'sizes' => %w(small medium large extra-large), | |
# 'style' => %w(tshirt longsleeve) | |
# } | |
# | |
# Output: | |
# [{"sizes"=>"small", "color"=>"blue", "style"=>"tshirt"}, | |
# {"sizes"=>"small", "color"=>"blue", "style"=>"longsleeve"}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def profile(label=nil, unit = :M) | |
# trying to see where our memory is going | |
population = Hash.new{|h,k| h[k] = [0,0]} | |
array_sizes = Hash.new{|h,k| h[k] = 0} | |
ObjectSpace.each_object do |object| | |
# rough estimates, see http://eigenclass.org/hiki.rb?ruby+space+overhead | |
size = case object | |
when Array | |
array_sizes[object.size / 10] += 1 | |
case object.size |