Skip to content

Instantly share code, notes, and snippets.

@softa
softa / numerology.hs
Created September 25, 2010 19:33
numerology in haskell
import Char
r = flip mod
b [l] = l
b l = b $ map (\x -> read [x]) $ show $ sum l
s = b . map ((+1) . r 9 . r 97 . ord . toLower) . filter isAlpha
main = do
x <- getLine
putStr $ show $ s x
module Main where
import Text.ParserCombinators.Parsec
runop :: Char -> Integer -> Integer -> Integer
runop '+' n1 n2 = n1 + n2
runop '-' n1 n2 = n1 - n2
runop '*' n1 n2 = n1 * n2
runop '^' n1 n2 = n1 ^ n2
operation :: Parser Integer
operation = do
module Mongo where
import Database.MongoDB
import Database.MongoDB.BSON
import Network
import Data.ByteString.Lazy.UTF8
fS = fromString
db = fS "yourdb"
module ChameleonBass where
import Haskore.Music
import Haskore.Melody
import Haskore.Basic.Pitch
import Haskore.Basic.Duration
import Haskore.Music.GeneralMIDI
import Haskore.Interface.MIDI.Render
pitch_line = map (\(x,y,z) -> x (y :: Octave) z () )
module FrereJacques where
import Haskore.Music
import Haskore.Melody
import Haskore.Basic.Pitch
import Haskore.Basic.Duration
import Haskore.Music.GeneralMIDI as MidiMusic
import Haskore.Interface.MIDI.Render as Render
render_to f m = Render.fileFromGeneralMIDIMusic f song where
-- relational.hs
import Database.HDBC
import Database.HDBC.PostgreSQL
import Data.List
printTuples conn rel = quickQuery' conn ("SELECT DISTINCT * FROM " ++ rel) []
(⋈) = intercalate " NATURAL JOIN "
(π) fields rel1 = "(SELECT " ++ (intercalate "," fields) ++ " FROM " ++ rel1 ++ ") a"
---
format: markdown+lhs
title: A simple pasteboard app
...
We're going to write a simple "pasteboard" web application in Haskell,
using `happstack-server` and `HDBC`. Here's the basic interface:
`GET /`
: show a form for entering some code, a title, and a syntax
##
# Identity Monad for Ruby taken from
# http://moonbase.rydia.net/mental/writings/programming/monads-in-ruby/00introduction.html
# ... but without the typos and with complete functions
##
class Identity
attr_reader :value
def initialize( value )
@value = value
Processing UsersController#create (for 127.0.0.1 at 2010-05-14 16:59:59) [POST]
Parameters: {"commit"=>"Create", "action"=>"create", "authenticity_token"=>"XFJroHBsMoFLCJRqYC3Z15c7U3hooDDiqZW09pWAH6U=", "controller"=>"users", "user"=>{"password_confirmation"=>"[FILTERED]", "openid_identifier"=>"", "password"=>"[FILTERED]", "email"=>"wittgenstein@tractatus.org"}}
AppConfiguration Load (1.0ms) SELECT * FROM "configurations" WHERE ("configurations"."name" = E'Default configuration') AND ( ("configurations"."type" = 'AppConfiguration' ) ) LIMIT 1
Cache hit: Spree::Config ({})
Cache hit: Spree::Config ({})
SQL (0.3ms) BEGIN
User Load (1.5ms) SELECT "users".id FROM "users" WHERE (LOWER("users"."email") = E'wittgenstein@tractatus.org') LIMIT 1
User Load (1.0ms) SELECT "users".id FROM "users" WHERE (LOWER("users"."login") = E'wittgenstein@tractatus.org') LIMIT 1
User Load (0.3ms) SELECT "users".id FROM "users" WHERE ("users"."persistence_token" = E'8b2211023b79864659e7ac4ebb1f51362a4d35e7ca1bcb7
> rake mailee:send
(in /home/maiz/projetos/my_store)
Enviando
.............. (segue)