Skip to content

Instantly share code, notes, and snippets.

View sshine's full-sized avatar
🦀

Simon Shine sshine

🦀
View GitHub Profile
@sshine
sshine / Foo.hs
Last active August 29, 2015 14:09
foo :: IO (Maybe Socket) -> IO () -> IO (Maybe Socket)
foo sock action = do
actionHandler <- tryIOError action
return $ either (\err -> Nothing) (\sock' -> sock <|> Just sock') actionHandler
performSocketAction2 :: Socket -> IO () -> IO (Maybe Socket)
performSocketAction2 sock action = foo (Just sock) action
makeSocket :: IO (Socket) -> IO (Maybe Socket)
@sshine
sshine / AST.hs
Last active August 29, 2015 14:08
TCL clone
module AST where
type Program = [Command]
data Command = Command Expr [Expr]
data Expr = Str Ident
| Num Integer
| List [Expr]
type Ident = String
--
-- Skeleton for Salsa interpreter
-- To be used at the exam for Advanced Programming, B1-2013
--
module SalsaInterp
-- (Position, interpolate, runProg)
where
import SalsaAst
import Prelude hiding (exp)
import Data.Char
import Text.ParserCombinators.ReadP
data Exp = Plus Exp Exp
| Pow Exp Exp
| Num Int
deriving (Show)
import Text.ParserCombinators.ReadP
import Control.Monad
import Data.Char
data Exp = Add Exp Exp
| Mul Exp Exp
| Num Int
| Dbl Double
| Neg Exp
@sshine
sshine / qc.hs
Last active August 29, 2015 14:07
import Test.QuickCheck
import Text.ParserCombinators.ReadP
import Control.Monad
import Control.Applicative hiding (Const)
data Tree = Leaf Int
| Branch Tree Tree
deriving (Show)
@sshine
sshine / keyservers.txt
Created October 9, 2014 13:20
Keyserver exercise
Keyservers:
A keyserver is a repository for cryptographic keys. A person can upload their
keys to a keyserver, and other persons can retrieve the key if they want to
send them an encrypted message.
To avoid a keyserver being compromised, several keyservers can be connected
and share their databases. So if one server has its keys changed, the other
servers can
-module(transact).
-export([ start_server/1, start_transaction/1,
modify_state/3, commit_transaction/2 ]).
%%%%%%%
rpc_send(Pid, Msg) ->
Pid ! {self(), Msg},
receive
{reply, Reply} ->
@sshine
sshine / keybase.md
Last active September 15, 2016 12:59

Keybase proof

I hereby claim:

  • I am sshine on github.
  • I am sshine (https://keybase.io/sshine) on keybase.
  • I have a public key ASBgprI2XryI_tASbgYfLUjHl1-zCW53t7A8TpIl7OXGvAo

To claim this, I am signing this object:

minima :: Ord a => [a] -> [a]
minima [] = []
minima (y:xs) = foldr aux [y] xs
where aux x result =
case x `compare` head result of
LT -> [x]
EQ -> x:result
GT -> result