Skip to content

Instantly share code, notes, and snippets.

View adinapoli's full-sized avatar
🐘

Alfredo Di Napoli adinapoli

🐘
View GitHub Profile
@adinapoli
adinapoli / simple_maybe_monad_usage.fs
Created April 1, 2012 10:49
A VERY simple application scenario of the Maybe Monad in F#
open FSharpx.Option
/// Type synonims
type ProductId = string
type Price = float
type Inventory() =
let inv_ = new System.Collections.Generic.Dictionary<ProductId, Price>()
@adinapoli
adinapoli / whenInScala.scala
Created April 12, 2012 17:25
when operator in scala
/**
* A syntactic sugar corresponding to the Lisp's when. Execute the body
* when the pred evaluates to true.
* @param condition A predicate or value that evaluate to a Boolean
* @param block A valid block of scala code
*/
def when (condition : => Boolean)( block : => Unit)
{
if (condition){ block }
}
@adinapoli
adinapoli / tmux.conf
Created July 1, 2012 15:12
My tmux.conf
set -g prefix C-a
bind C-a send-prefix
unbind C-b
set -sg escape-time 1
set -g base-index 1
setw -g pane-base-index 1
bind r source-file ~/.tmux.conf \; display "Reloaded!"
bind | split-window -h
bind - split-window -v
bind h select-pane -L
createUser :: Text -- ^ Username
-> ByteString -- ^ Password
-> Handler b (AuthManager b) (Either String AuthUser)
createUser "" _ = return $ Left "Username cannot be empty"
createUser unm pwd = withBackend (\r -> liftM (\x -> Right x) $ liftIO $ buildAuthUser r unm pwd)
createUser unm pwd
| null (strip unm) = return $ Left "Username cannot be empty"
| otherwise = withBackend $ \r -> do
u <- liftIO $ buildAuthUser r unm pwd
return $ Right u
@adinapoli
adinapoli / gist:3782217
Created September 25, 2012 14:20
MusicStore snaplet
{-# LANGUAGE OverloadedStrings #-}
module Blackbox.MusicStoreSnaplet where
------------------------------------------------------------------------------
import Control.Applicative
import qualified Data.ByteString.Char8 as B
import Data.Lens.Lazy
import Data.Lens.Template
@adinapoli
adinapoli / first.hs
Created October 1, 2012 12:49
First attempt
loginUser
:: ByteString
-- ^ Username field
-> ByteString
-- ^ Password field
-> Maybe ByteString
-- ^ Remember field; Nothing if you want no remember function.
-> (AuthFailure -> Handler b (AuthManager b) ())
-- ^ Upon failure
-> Handler b (AuthManager b) ()
@adinapoli
adinapoli / gist:3839983
Created October 5, 2012 14:09
Trying to reproduce the StackOverflow problem - Nice version
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
------------------------------------------------------------------------------
import Control.Monad.State
import Data.Lens.Template
import qualified Data.Map as Map
import Data.Text as T
@adinapoli
adinapoli / gist:3899017
Created October 16, 2012 12:39
Iteratee attempt
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Enumerator (Iteratee, Enumeratee, ($=), (=$), (=$=), (==<<))
import qualified Data.Enumerator as E
import qualified Data.Enumerator.Binary as EB
import qualified Data.Enumerator.Text as ET
import qualified Data.Enumerator.List as EL
import Data.Text
# Codification of discussion at http://code.google.com/p/xmonad/issues/detail?id=177
# Probably better to run each of these lines one by one instead of as a shell
# script, since there's a high probability of `cabal install` failing (usually
# fixed by installing the relevant libfoo-dev package)
# One person said these steps did not work.
# My Java version is:
# java version "1.6.0_34"
# Java(TM) SE Runtime Environment (build 1.6.0_34-b04)
# Java HotSpot(TM) Server VM (build 20.9-b04, mixed mode)