This file contains hidden or 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 NoMonomorphismRestriction #-} | |
module Tree where | |
-- Example of how ADT's work by implementing the List type | |
-- data List a | |
-- = EmptyList -- [] | |
-- | ConsList a (List a) -- (1:[]) | |
-- (1:2:[]) | |
-- (ConsList 1 (ConsList 2 EmptyList)) |
This file contains hidden or 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
// need an algebraic data structure | |
// a..e are defined as meta param names | |
// f variable will hold all the declared Algebraic Data Types | |
newdata("Maybe", function(spec){ | |
// the data constructor name as key | |
// the parameters specified as an array | |
spec["Just"] = [a]; | |
spec["Nothing"] = []; | |
}); |
This file contains hidden or 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
// As see on: http://cocoawithlove.com/2008/10/sliding-uitextfields-around-to-avoid.html | |
#import <Foundation/Foundation.h> | |
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3; | |
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2; | |
static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8; | |
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216; | |
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 162; |
This file contains hidden or 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
The Traveling Hacker -------------------- | |
Today you will be building a tool for a travel agency that determines the | |
total distance traveled on a tour with many stops. As luck would have it, some | |
of the core functionality you need has already been implemented, and you won't | |
need to worry about coding a mileage and routing system from scratch. | |
But there's a catch: The mileage and routing system you'll be using lies on | |
the other side of a service boundary, and only minimal work has been done on | |
the client side. Essentially, all that has been written so far is a bit of |
This file contains hidden or 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 GeneralizedNewtypeDeriving #-} | |
import qualified Data.Map as M | |
import Data.List (isSuffixOf, isPrefixOf) | |
import Control.Arrow (second) | |
import Control.Monad (mapM_) | |
import Control.Monad.State | |
newtype ParamsParserMonad a = PPM (State (M.Map String [String]) a) | |
deriving (Monad) |
This file contains hidden or 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 MethodInterceptor | |
def self.included(base) | |
base.extend(ClassMethods) | |
base.send(:include, InstanceMethods) | |
base.class_eval do | |
# we declare the method_list on the class env | |
@_instance_method_list = base.instance_methods.inject(Hash.new) do |methods, method_name| | |
# we undef all methods | |
if !%w(__send__ __id__ method_missing class).include?(method_name) |
This file contains hidden or 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
- # app/views/posts/_post.html | |
%h1= post.title | |
... | |
%p Actions: | |
%ul | |
- # checking the authorizations on the view... | |
%li= edit_post_path(post) if current_user.can?(:update, post) | |
%li= post_path(post) if current_user.can?(:read, post) |
This file contains hidden or 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 WorkerForker | |
ReloadWorkerMessage = Class.new(StandardError) | |
class Worker | |
def initialize(ppid, stream) | |
@ppid = ppid | |
@pid = Process.pid | |
@stream = stream |
This file contains hidden or 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 System.Random hiding (next) | |
randomsIO :: Random a => IO [a] | |
randomsIO = | |
getStdRandom $ \g -> | |
let (a, b) = split g | |
in (randoms a, b) |
This file contains hidden or 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 Foo | |
def test | |
self.class::Baz | |
end | |
end | |
=> nil | |
class Bar | |
include Foo | |
class Baz |