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
module DeferredTouch | |
def self.no_touching!(*klasses, &block) | |
to_touch = Set.new | |
old_methods = klasses.inject({}) {|acc, klass| acc[klass] = klass.instance_method(:touch); acc } | |
begin | |
klasses.each do |klass| | |
klass.send(:define_method, :touch) do | |
to_touch << self | |
end |
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
## Having: | |
module Foozle | |
module ClassMethods | |
# great, we can document the init stuff too now, isn't that nice? | |
def initialize_foozle | |
# do some init-stuff here | |
end | |
private :initialize_foozle | |
end | |
module InstanceMethods |
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
(.:/) :: (FromJSON a) => Object | |
-> [Text] | |
-> Parser a | |
obj .:/ (k:ks) = maybe (fail msg) parseJSON parsed | |
where parsed = deepValue ks =<< M.lookup k obj | |
msg = "Failed to find " ++ (intercalate "/" $ map unpack (k:ks)) | |
obj .:/ [] = parseJSON $ Object obj | |
deepValue :: [Text] | |
-> Value |
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
import Data.List (groupBy, sort) | |
toRanges :: (Ord a, Enum a) => [a] -> [(a,a)] | |
toRanges = map range . groupBy isSucc . sort | |
where range xs = (minimum xs, maximum xs) | |
isSucc a b = succ a == b |
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
class Buffer | |
attr_reader :size, :contents | |
def initialize(size, &block) | |
@size = size | |
@contents = [] | |
@callback = block | |
end | |
def <<(item) | |
@contents << item |
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
module Main (main) where | |
{-# Language Overloaded Strings #-} | |
import Control.Exception.Base (SomeException) | |
import Data.Aeson (Object) | |
import Data.Aeson.Encode (encode) | |
import Data.Aeson.Types (Value(String)) | |
import Data.ByteString (ByteString) | |
import qualified Data.ByteString.Lazy as LBS (putStr) | |
import Data.CSV.Enumerator |
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
require 'rubygems' | |
require 'nokogiri' | |
XML_FILE = 'profiles.xml' | |
INTERVAL = 60 | |
def randomize(hash) | |
%w[Contrast_Green Contrast_Red Contrast_Blue].each do |k| | |
hash[k] = rand(255) | |
end |
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 #-} | |
import Control.Monad | |
import Control.Applicative | |
import Data.Aeson | |
import Data.Maybe | |
import Data.ByteString as BS (readFile, ByteString(..)) | |
import Data.Attoparsec (parse, maybeResult, eitherResult) | |
main :: IO () | |
main = do str <- BS.readFile "sample.json" |