Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am dsimunic on github.
  • I am dsimunic (https://keybase.io/dsimunic) on keybase.
  • I have a public key ASA4sK7jOta7QTZfrLtVZUgeWob_0qzFPm8FWA9d72CaPQo

To claim this, I am signing this object:

@dsimunic
dsimunic / clock.elm
Last active April 30, 2016 11:23
Elm Clock
import Html exposing (..)
import Html.App exposing (program)
import Svg exposing (circle, line, svg)
import Svg.Attributes exposing (..)
import Time exposing (Time, minute, second)
main =
program { init = init, view = view, update = update, subscriptions = subs }
@dsimunic
dsimunic / splitrows.fs
Created April 2, 2015 12:54
Read rows from a multi-line string
open System.IO
let splitRows (s:string) =
new StringReader(s)
|> Seq.unfold (fun sr ->
match sr.ReadLine() with
| null -> sr.Dispose(); None
| str -> Some(str, sr))
|> Seq.toArray
'use strict';
var m = require('mithril');
var extend = require('lodash').extend;
var setFocus = require('../util/viewhelper').setFocus;
var keymage = require('keymage');
function noop(){}
function addClass(el, className) {
@dsimunic
dsimunic / docker-preserve-ownership.md
Created January 27, 2015 17:59
Running as a non-root inside a container

Running as a non-root inside a container

Docker can start a container with a specific user by passing the id on the command line with -u. The parameter to the -u switch is either a username or id of a user existing inside the container. More precisely, the container must have valid /etc/passwd file with the defined user:

$ mkdir etc 
$ echo 'postgres:x:1000:1000::/home/postgres:/bin/sh' > etc/passwd

While not needed for this simple experiment, we might want to create group and shadow files for completeness:

var animator = ( function animatorScope(){
var animating = false;
return function animator( input, incoming, outgoing, alwaysAnimate ){
var module = {
controller : input.controller || function(){},
view : function animatedView( ctrl ){
var view = ( input.view || input )( ctrl );
var cfg = view.attrs.config;
@dsimunic
dsimunic / parse_numerals.fs
Created October 2, 2014 20:17
Parse roman numerals
type RomanDigit = Nil | I | V | X | L | C | D | M
let romanDigitToInt aRomanDigit =
match aRomanDigit with
| Nil -> 0
| I -> 1
| V -> 5
| X -> 10
| L -> 50
| C -> 100
apt-get install -y wget build-essential gettext autoconf automake libtool
MONO_VERSION=3.4.0
wget http://download.mono-project.com/sources/mono/mono-${MONO_VERSION}.tar.bz2
bunzip2 -df mono-${MONO_VERSION}.tar.bz2
tar -xf mono-${MONO_VERSION}.tar
cd mono-${MONO_VERSION}
@dsimunic
dsimunic / caller_test.lua
Last active August 29, 2015 13:56
Test if a lua file is runnnig standalone or is it required
-- Obviously, if a standalone file is called with an argument that corresponds to a loaded file, it will think it's required.
-- For example:
-- lua caller_test.lua _G
-- will choose the else branch.
-- For our purposes, though, this is good enough.
if not _G.package.loaded[...] then
print("Running standalone")
else
print("Required")
end
public static void OverwriteConsoleMessage(string message)
{
Console.CursorLeft = 0;
int maxCharacterWidth = Console.WindowWidth - 1;
if (message.Length > maxCharacterWidth) {
message = message.Substring(0, maxCharacterWidth - 3) + "...";
}
message = message + new string(' ', maxCharacterWidth - message.Length);
Console.Write(message);
}