Skip to content

Instantly share code, notes, and snippets.

View roman's full-sized avatar

Roman Gonzalez roman

View GitHub Profile
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
@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;
// 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 / 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))
@roman
roman / Iteratee.hs
Created November 25, 2010 21:10
Implementing Parsec Like combinators using the Oleg's spec of Iteratee
{-# LANGUAGE TypeSynonymInstances, NoMonomorphismRestriction #-}
module Iteratee where
import Control.Applicative hiding (many)
import Control.Monad (liftM, ap)
import Data.Char (isSpace, isAlpha)
import Data.Monoid
import qualified Prelude as P
import Prelude hiding (head, break)
@roman
roman / Extensions.hs
Created December 8, 2010 03:33
A Posts lookup on mongoDB database
{-# LANGUAGE FlexibleInstances #-}
module Database.MongoDB.Extensions where
import Database.MongoDB hiding (find)
import Data.List (find)
import Control.Monad ((=<<))
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
instance Val (Maybe Value) where
val Nothing = Null
@roman
roman / Validator.hs
Created December 10, 2010 19:40
Nahive validation Monad
{-# LANGUAGE MultiParamTypeClasses, GeneralizedNewtypeDeriving #-}
import Data.Char
import Control.Monad
import Control.Monad.State
type ErrorMessage = String
data User = User {
name :: String
, age :: Int
@roman
roman / gist:755865
Created December 27, 2010 04:35
curry.rb
class Proc
alias_method :old_call, :call
public
def curried?
!!@curried
end
#!/usr/bin/ruby
#
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/mxcl/homebrew/tarball/master anywhere you like.
#
#
# 30th March 2010:
# Added a check to make sure user is in the staff group. This was a problem
# for me, and I think it was due to me migrating my account over several
# versions of OS X. I cannot verify that for sure, and it was tested on
{-# LANGUAGE OverloadedStrings #-}
{-|
This is where all the routes and handlers are defined for your site. The
'site' function combines everything together and is exported by this module.
-}
module Site