Skip to content

Instantly share code, notes, and snippets.

@mdmarek
mdmarek / GCD.tla
Created November 3, 2016 16:16
TLA+ GCD
---- MODULE GCD ----
EXTENDS Integers, TLC
Divides(p, n) == \E q \in -1000..1000 : n = q * p
DivisorsOf(n) == {p \in -1000..1000 : Divides(p, n)}
SetMax(S) == CHOOSE i \in S : \A j \in S : i >= j
@mdmarek
mdmarek / DieHard.cfg
Created November 3, 2016 16:14
TLA+ DieHard
INIT
Init
NEXT
Next
INVARIANT
TypeOK
@mdmarek
mdmarek / Chan.cfg
Created November 3, 2016 16:12
TLA+ Channel
INIT
Init
NEXT
Next
INVARIANT
TypeOK
CONSTANTS
@mdmarek
mdmarek / service-checklist.md
Created September 15, 2016 20:34 — forked from acolyer/service-checklist.md
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
@mdmarek
mdmarek / check-user-limits.sh
Created November 19, 2013 20:46
Find the nofile limit for a user, which may or may not have a valid user shell
#!/bin/bash
USR=$1
su $USR --shell /bin/bash --comman "ulimit -n"

Set values in:

/etc/security/limits.conf

Needs to be enabled in:

/etc/pam.d/common-session
/etc/pam.d/common-session-noninteractive

by adding:

@mdmarek
mdmarek / example-cut.sh
Created September 21, 2013 22:26
How to use the cut command
# Use white space as delimiter and return the 1st
# field and all fields including and after the
# 7th field.
cut -d' ' -f1,7-
@mdmarek
mdmarek / fileatomic.go
Created October 13, 2015 01:08
Write a file atomically under Linux.
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Write file to temp and atomically move when everything else succeeds.
func WriteFileAtomic(filename string, data []byte, perm os.FileMode) error {
dir, name := path.Split(filename)
f, err := ioutil.TempFile(dir, name)
if err != nil {
return err
@mdmarek
mdmarek / WaiApp4.hs
Created May 21, 2012 02:09
Wai+Warp file server with routes. Used GHC 7.4, Wai 1.1, Warp 1.1 versions.
{-# LANGUAGE OverloadedStrings #-}
-- | Wai+Warp file server with routes. Used GHC 7.4, Wai 1.1, Warp 1.1 versions.
module Main where
import Network.HTTP.Types (status200)
import Network.Wai (Application,responseLBS)
import Network.Wai.Middleware.Router (router,dir)
import Network.Wai.Handler.Warp (run)
import Network.Wai.Application.Static
@mdmarek
mdmarek / TextMatrix.hs
Created May 12, 2012 01:42
Read matrix from CSV file and convert to Matrix (Hmatrix)
{-# LANGUAGE OverloadedStrings #-}
-- | Converts a matrix represented as text to Hmatrix Matrix. Used GHC 7.4, Hmatrix 0.14.
module Main where
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Data.Text (Text,splitOn,lines)
import Data.Text.Read (double)
import Data.Packed.Matrix (Matrix,fromLists)