Skip to content

Instantly share code, notes, and snippets.

View sshine's full-sized avatar
🦀

Simon Shine sshine

🦀
View GitHub Profile
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module WorkspaceOverviewPopup where
import Data.Maybe
import Control.Monad
import XMonad
import qualified XMonad.StackSet as W
import XMonad.Layout.LayoutModifier
import XMonad.Util.Font
from __future__ import division
## Equations:
# x(t+h) = x(t) + 1/2 (F1 + F2)
# F1 = h*f(t,x)
# F2 = h*f(t+h, x+h*f(t,x))
def rungekutta(f, a, b, x0, iterations):
h = (b - a) / iterations
x = x0
replaceEs :: String -> String
-- One way
replaceEs ('e':cs) = 'a' : replaceEs cs
replaceEs (c:cs) = c : replaceEs cs
replaceEs [] = []
-- Or another
replaceEs [] = []
replaceEs (c:cs) =
case c of
m <- matrix(c(1, 0, 0,
0, 4, 0,
0, 0, 2), ncol=3, byrow=T)
# RISK Attack Simulation
attack <- function(na, nb) {
die <- 1:6
while (na > 0 & nb > 0) {
attackers <- min(na, 3)
defenders <- min(nb, 2)
fights <- min(attackers, defenders)
hit_a <- sort(sample(die, attackers), decreasing=T)[1:fights]
{
(* A position in a file is identified as a (line,column) : int * int *)
type position = int * int
(* Lexical errors have some error message and a position in the file *)
exception LexicalError of string * position (* (message, (line, column)) *)
(* While scanning the file, line numbers and the character offset (the integer
position for the character in the file) for each beginning line are kept
local
fun fbstr i =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => Int.toString i
fun fizzbuzz' (n, j) =
-module(simple2).
-export([start/0]).
-define(PORT, 33333).
start() ->
{ok, spawn(fun listener/0)}.
listener() ->
ChatMaster = spawn(fun() -> chatmaster(dict:new()) end),
{ok, ListenSocket} = gen_tcp:listen(?PORT, [binary, {active, true}]),
-module(simple_chatserver).
-export([start/0]).
-define(PORT, 33333).
% External API function for starting chat server
start() ->
% Start a process for coordinating communication between clients
CoordinatorPid = spawn(fun() -> coordinator(dict:new()) end),
% Listen to a TCP socket and start a process that accepts incoming
datatype bentSpil = BentSlutter of int
| BentSpiller of ingeSpil list
and ingeSpil = IngeSlutter of int
| IngeSpiller of bentSpil list
(* bent8 *)
val inge3 = IngeSpiller [ BentSlutter 0 ]
val inge4 = IngeSpiller [ BentSlutter 0, BentSlutter 1 ]