Skip to content

Instantly share code, notes, and snippets.

@bssstudio
bssstudio / Main.hs
Created August 10, 2014 10:32
MontePi
module Main where
import MontePi
import System.IO
main :: IO ()
main = do
hSetBuffering stdout NoBuffering
putStr "Please enter n = "
n <- readLn :: IO Int
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module Main where
import Web.Scotty (get, post, delete, param, html, json, jsonData, scotty, ScottyM)
import Data.Aeson (FromJSON, ToJSON)
import Control.Monad.IO.Class (liftIO, MonadIO)
import Control.Concurrent.STM (atomically, STM)
import Control.Concurrent.STM.TChan
@bssstudio
bssstudio / gist:8010747
Last active December 31, 2015 15:59
AVL tree insertion in haskell
data BinTree a = Leaf
| Node { nodeData :: a, left :: BinTree a, right :: BinTree a}
deriving (Eq, Show)
instance Functor BinTree where
fmap f Leaf = Leaf
fmap f (Node a l r) = Node (f a) (fmap f l) (fmap f r)
toList :: BinTree a -> [a]
@bssstudio
bssstudio / .bashrc
Created July 12, 2013 07:08
GIT branch in bash on mint
__git_ps1 ()
{
local b="$(git symbolic-ref HEAD 2>/dev/null)";
if [ -n "$b" ]; then
printf " (%s)" "${b##refs/heads/}";
fi
}
#PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]"
PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[01;31m\]\$( __git_ps1 ) \[\033[01;34m\]\$\[\033[00m\] "
@bssstudio
bssstudio / excpectedNumOfSubnodes.scala
Created January 24, 2013 10:06
Expected number of subnodes of a randomly selected node in a tree.
def propab(d: Int, n: Int, b: Int): Double = {
Math.pow(b,d-1)/Math.pow(b,n)
}
def expected(n:Int, bf: Int): Double = {
(1 to n).foldLeft(0.0)( (a:Double,b:Int) => a + (b*propab(b,n,bf)) )
}
@bssstudio
bssstudio / TCPServer.scala
Created January 11, 2013 07:41
Dead simple http responder (not even echo test)
//scalaVersion 2.9.2
//akkaVersion 2.0.1
import akka.actor._
import java.net.InetSocketAddress
import akka.util.ByteString
import java.net.Socket
import akka.actor.IO.SocketHandle
import akka.actor.IO._
import akka.routing.RoundRobinRouter