Skip to content

Instantly share code, notes, and snippets.

View Rydgel's full-sized avatar
😂
💯 🔥

Jérôme Mahuet Rydgel

😂
💯 🔥
View GitHub Profile
@Rydgel
Rydgel / gist.hs
Created August 12, 2015 08:12
haskell async http requests example
{-# OPTIONS_GHC -Wall -O2 -threaded -with-rtsopts="-N" #-}
import Control.Concurrent
import Control.Concurrent.Async
import Control.Lens
import Control.Monad
import Data.ByteString.Lazy hiding (replicate)
import Data.List.Split
import Network.Wreq hiding (getWith)
import Network.Wreq.Session
#! /bin/bash
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
export GHC_DOT_APP="/Applications/ghc-7.8.4.app"
export PATH="${HOME}/.cabal/bin:${GHC_DOT_APP}/Contents/bin:${PATH}"
export PATH=$HOME/.cabal/bin:$PATH
@Rydgel
Rydgel / gist:c47f92e6736cf0df43c1
Last active August 29, 2015 14:08
Algebraic Data Types - Binary Search Tree
/**
* Binary Search Tree in Scala with ADT
*/
sealed trait Tree[+T]
case object Leaf extends Tree[Nothing]
case class Branch[T](value: T, left: Tree[T], right: Tree[T]) extends Tree[T]
object Tree {
def showTree[T](tree: Tree[T]): String = tree match {
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
{-# LANGUAGE FlexibleInstances #-}
-- Homework 6 - http://www.seas.upenn.edu/~cis194/spring13/hw/06-laziness.pdf
fib :: Integer -> Integer
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
-- Homework 6 - http://www.seas.upenn.edu/~cis194/spring13/hw/05-type-classes.pdf
import ExprT
import Parser
import StackVM as VM
import qualified Data.Map as M
import Control.Monad
-- Homework 4 - http://www.seas.upenn.edu/~cis194/spring13/hw/04-higher-order.pdf
import Data.List
-- Exercise 1: Wholemeal programming
fun1 :: [Integer] -> Integer
fun1 [] = 1
fun1 (x:xs)
| even x = (x - 2) * fun1 xs
-- Homework 3 - http://www.seas.upenn.edu/~cis194/spring13/hw/03-rec-poly.pdf
module Golf where
import Data.List
skips :: [a] -> [[a]]
skips xs = map (\(i,x) -> takeNth i x) $ zipWith (\_ b -> (b, xs)) xs [1..]
takeNth :: Int -> [a] -> [a]
module Golf where
skips :: [a] -> [[a]]
skips xs = map (\(i,x) -> takeNth i x) $ zipWith (\_ b -> (b, xs)) xs [1..]
takeNth :: Int -> [a] -> [a]
takeNth n xs = [y | (i,y) <- zip [1..] xs, i `mod` n == 0]
{-# OPTIONS_GHC -Wall #-}
-- Homework 2 - http://www.seas.upenn.edu/~cis194/spring13/hw/02-ADTs.pdf
module LogAnalysis where
import Log
parseMessage :: String -> LogMessage
parseMessage = parseWords . words
where parseWords :: [String] -> LogMessage