Skip to content

Instantly share code, notes, and snippets.

View roman's full-sized avatar

Roman Gonzalez roman

View GitHub Profile
@roman
roman / gsub.hs
Created June 14, 2011 01:36
Nahive implementation of a gsub
module Text.Regex.Gsub
(gsub) where
import Text.Regex.Posix ((=~), MatchText)
import Data.Array ((!))
import Data.Char (isDigit)
-------------------------------------------------------------------------------
gsub :: String -> String -> String -> String
gsub text match replacement = replaceMatches 0 matches text
@roman
roman / quickfix_ghc.vim
Created June 4, 2011 22:18
Code to use QuickFix with GHC + Cabal
" let mapleader='\'
" When using \b on normal mode, it will compile the
" project
nmap <LEADER>b :<C-u>make<CR>
" Close the QuickFix window just with the q
au FileType qf nnoremap <buffer> q :<C-u>cclose<CR>
" After compiling, open the QuickFix window if there
data RequesType
= GetRequest
| PutRequest ByteString
| MultipartPostRequest FileParams
| UrlEncodedPostRequest
| DeleteRequest
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
let lineStartsWithPipe = getline('.') =~# '^\s*|'
let pipedContentOnPrevLine = getline(line('.')-1) =~# p
let pipedContentOnNextLine = getline(line('.')+1) =~# p
if exists(':Tabularize') && lineStartsWithPipe && (pipedContentOnPrevLine || pipedContentOnNextLine)
" Getting the number of pipes that are on the line
{-# 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
#!/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
@roman
roman / gist:755865
Created December 27, 2010 04:35
curry.rb
class Proc
alias_method :old_call, :call
public
def curried?
!!@curried
end
@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 / 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 / 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)