Skip to content

Instantly share code, notes, and snippets.

@dimp-pl
dimp-pl / life.rb
Created July 23, 2012 19:52
Conway's Game of Life in Ruby
require 'matrix'
class Matrix
def []=(i, j, x)
@rows[i][j] = x
end
end
class GameOfLife
def initialize(row, col)
@dimp-pl
dimp-pl / p26.erl
Created August 8, 2012 12:22
Erlang, combinations generation. Problem #26 of 99 %LANGUAGE_NAME problems.
-module(p26).
-export([combinations/2]).
% Generates all combinations of List by length Of
% Antilex order
combinations(List, Of) when List == []; Of == 0 ->
[];
combinations(List, Of) ->
Mask = vallist(length(List), 0),
@dimp-pl
dimp-pl / gist:3379406
Created August 17, 2012 14:50
How to make git ignore file changes?
# Fortunately GIT has a very easy solution for this, just run the following command on the file or path you want to ignore the changes of:
$ git update-index --assume-unchanged <file>
# If you wanna start tracking changes again run the following command:
$ git update-index --no-assume-unchanged <file>
Add following lines in section [alias] your git config file (~/.gitconfig).
lg1 = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative
lg2 = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' --abbrev-commit
lg = !"git lg1"
Now you can use $ git lg $ git lg1 or $ git lg2 to get really fancy git logs.
@dimp-pl
dimp-pl / regs.py
Created May 13, 2013 22:58
Regular languages engine built on top of Python generators
"""
Simple engine for maching regular languages.
Proof of concept that regexps can be built on top of Python generators.
"""
def literal(c): # regexp 'a'
assert len(c) < 2
def matcher(input):
if input.startswith(c):
yield input[len(c):]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dimp-pl
dimp-pl / preview-snap.py
Created February 6, 2014 15:34
Dirty preview/snap photo script. Relies on gphoto2 and piggyphoto.
import piggyphoto
import pygame
def quit_pressed():
for event in pygame.event.get():
if event.type == pygame.QUIT:
return True
return False
def show(file):
@dimp-pl
dimp-pl / StackMachine.hs
Created May 16, 2014 21:54
Another way of evaluating arithmetic expressions — stack machine
module StackMachine where
type Value = Double
data Instruction = IPush Value | IAdd | ISubtract | IMultiply | IDivide
deriving (Show)
data Expr = Lit Value
| Add Expr Expr
| Subtract Expr Expr
@dimp-pl
dimp-pl / arch-container-howto.md
Last active August 29, 2015 14:13
Arch systemd containers

Install pacstrap

pacman -S arch-install-scripts

Create base rootfs with pacstrap utility (this will also install systemd and linux, which can be removed later)

pacstrap -i -c -d ~/containers/arch base base-devel