Skip to content

Instantly share code, notes, and snippets.

View sshine's full-sized avatar
🦀

Simon Shine sshine

🦀
View GitHub Profile
import Prelude hiding (exp)
import Data.Char
import Text.ParserCombinators.ReadP
data Exp = Plus Exp Exp
| Pow Exp Exp
| Num Int
deriving (Show)
--
-- Skeleton for Salsa interpreter
-- To be used at the exam for Advanced Programming, B1-2013
--
module SalsaInterp
-- (Position, interpolate, runProg)
where
import SalsaAst
@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
@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 / gist:fe5ddf9c3763583e0c10
Created January 20, 2015 01:24
I miss monads...
$.ajax({ url: "foo.csv", dataType: "text" })
.done(function(data) {
fetchPostTags(data);
$.ajax({ url: "bar.csv", dataType: "text" })
.done(fetchPostsComments);
.fail(function(failure) {
updateStatus("Failed to load posts-comments.csv");
console.log(failure);
});
{-# LANGUAGE TupleSections #-}
import Data.Char
import Control.Monad
import Control.Applicative hiding (many)
import Text.ParserCombinators.ReadP
import Test.QuickCheck
data Exp = Add Exp Exp
| Sub Exp Exp
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
@sshine
sshine / .ghci
Created September 10, 2015 13:34
let ghciEscape arg = "'" ++ concatMap (\c -> if c == '\'' then "'\"'\"'" else [c]) arg ++ "'"
:def! hoogle return . (":! hoogle --color --count=20 " ++) . ghciEscape
:def! doc return . (":! hoogle --color --info " ++) . ghciEscape
:set prompt "\ESC[1;34m%s\n\ESC[0;34mλ> \ESC[m"
@sshine
sshine / cata.hs
Last active September 29, 2016 16:09
import Data.Char
import Control.Monad
import Control.Applicative
para :: (a -> b -> [a] -> b) -> b -> [a] -> b
para f e [] = e
para f e (x:xs) = para f (f x e xs) xs
main = do
using (WebClient webClient = new WebClient())
{
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] request = System.Text.Encoding.UTF8.GetBytes("payload=" + JsonConvert.SerializeObject(message));
byte[] response = webClient.UploadData(this._webHookUri, "POST", request);
}