Skip to content

Instantly share code, notes, and snippets.

View roman's full-sized avatar

Roman Gonzalez roman

View GitHub Profile
@roman
roman / Tree.hs
Created November 11, 2010 01:24
Resolved Problems of the Trees exercises module
{-# 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))
// 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"] = [];
});
@roman
roman / TextFieldDelegate.h
Created July 9, 2010 23:22
Delegate that handles all the annoying gotchas of textfields
// 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;
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
{-# 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)
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)
- # 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)
class WorkerForker
ReloadWorkerMessage = Class.new(StandardError)
class Worker
def initialize(ppid, stream)
@ppid = ppid
@pid = Process.pid
@stream = stream
import System.Random hiding (next)
randomsIO :: Random a => IO [a]
randomsIO =
getStdRandom $ \g ->
let (a, b) = split g
in (randoms a, b)
@roman
roman / gist:231304
Created November 10, 2009 21:47 — forked from hassox/gist:231290
module Foo
def test
self.class::Baz
end
end
=> nil
class Bar
include Foo
class Baz