This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Database.HDBC | |
import Database.HDBC.Sqlite3 | |
import qualified Data.Convertible.Base as C | |
get :: forall a. C.Convertible SqlValue a => [[SqlValue]] -> [[a]] | |
get sql = map f sql | |
where f row = map fromSql row | |
main = do | |
connection <- connectSqlite3 "development.sqlite3" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Application_user = Settings[:authentication][:user] | |
Application_pass = Settings[:authentication][:password] | |
def protected! username = Application_user, password = Application_pass | |
unless authorized? username, password | |
response['WWW-Authenticate'] = %(Basic realm="Testing HTTP Auth") | |
throw(:halt, [401, "Not authorized\n"]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Matrix m a | -- * Voodoo goes here? | |
where | |
-- required | |
fromRows :: [[a]] -> m a | |
rows :: m a -> Integer | |
columns :: m a -> Integer | |
at :: m a -> Integer -> Integer -> a | |
-- defaults | |
toList :: m a -> [a] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts #-} | |
{- -- Has the error: | |
Matrix.hs:33:49: | |
Kind error: `m' is applied to too many type arguments | |
In the type `m (Maybe a)' | |
In the type `Integer -> m (Maybe a)' | |
In the type `Integer -> Integer -> m (Maybe a)' | |
--} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Matrix ( | |
Matrix, | |
fromRows, | |
toList, | |
toListWithPos, | |
toRows, | |
rows, | |
columns, | |
at, | |
neighbours, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rack' | |
require 'sinatra' | |
disable :show_errors | |
not_found do | |
status 200 | |
"not found" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fac 0 = 1 | |
fac n = n * fac (n - 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Logic | |
import Data.Maybe | |
import Data.List | |
import Data.Numbers.Primes | |
import Test.QuickCheck | |
-- This program demonstrates a mapping between the pairs of natural numbers and a (nonstrict?) subset of co-primes. | |
-- The property should hold for all sized lists, not just pairs. Ordering is preserved. | |
-- Question: Are we able to compress the range to create a bijection? | |
-- Answer: Yes! We can use the breadth-wise indces of the products, rather than the products themselves. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Concurrent | |
import Random | |
main = print =<< threadAndJoin (replicate 10 randomAction) | |
randomAction = do | |
x <- randomRIO (0::Double,2) | |
threadDelay $ floor $ x * (10 ** 6) | |
print x >> return x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.Rendering.OpenGL | |
import Graphics.UI.GLUT | |
import Data.IORef | |
main = do | |
pixels <- newIORef automata | |
getArgsAndInitialize | |
createWindow "1D Finite Automata" | |
initialDisplayMode $= [DoubleBuffered] | |
initialWindowSize $= Size 400 400 |
OlderNewer