Skip to content

Instantly share code, notes, and snippets.

{-# 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)
{-# 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
@MichaelXavier
MichaelXavier / CFBFeatures.js
Created June 28, 2012 15:47 — forked from dplummer/CFBFeatures.js
Ajax from PHP
var count = 2;
var loader = $('.infinite-loader');
$(window).scroll(function() {
if($(window).scrollTop() == $(document).height() - $(window).height()) {
if(count > total) {
return false;
} else {
@MichaelXavier
MichaelXavier / hash_of_arrays_permutations.rb
Created September 13, 2011 17:10 — forked from dplummer/hash_of_arrays_permutations.rb
Permutations of a hash of arrays
# 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"},
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