Skip to content

Instantly share code, notes, and snippets.

@mdmarek
mdmarek / WaiApp1.hs
Created May 6, 2012 17:12
Minimum Wai + Warp Application Server. Compiled with GHC 7.4, Wai 1.1, Warp 1.1 versions.
{-# LANGUAGE OverloadedStrings #-}
-- | Hello world Wai+Warp applicaion server. 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.Handler.Warp (run)
-- | Hello word Wai application.
@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)
@mdmarek
mdmarek / WaiApp3.hs
Created May 13, 2012 22:06
Haskell web application to serve static files.
{-# LANGUAGE OverloadedStrings #-}
-- | Wai+Warp file server. Used GHC 7.4, Wai 1.1, Warp 1.1 versions.
module Main where
import Network.Wai.Handler.Warp (run)
import Network.Wai.Application.Static
( StaticSettings(..)
, staticApp
, fileSystemLookup
@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 / 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-

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 / 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"
@mdmarek
mdmarek / twotriangles.go
Last active August 29, 2015 14:08
Modern OpenGL to draw using multiple Vertex Attribute Objects.
// Copyright 2014 The go-gl Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"runtime"
@mdmarek
mdmarek / multiparam.go
Last active August 29, 2015 14:08
Vertex shader that passes color information to fragment shader.
package main
import (
"fmt"
"runtime"
"github.com/go-gl/gl"
glfw "github.com/go-gl/glfw3"
)
@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