Skip to content

Instantly share code, notes, and snippets.

View kotnik's full-sized avatar

Nikola Kotur kotnik

View GitHub Profile
@kotnik
kotnik / hook.sh
Created August 1, 2016 08:41
Git update hook to allow only signed commits
#!/usr/bin/env bash
##############################################################################
#
# check-commit-signature
# ----------------------
# A server-side update git hook for checking the GPG signature of a pushed
# commit.
#
# To enable this hook, rename this file to "update".
#
@kotnik
kotnik / small-dns-server.py
Created June 6, 2013 14:51
Example of how to create a DNS server in Python, based on Twisted libraries.
from collections import Mapping
from twisted.names import dns, server, client, cache
from twisted.application import service, internet
class MapResolver(client.Resolver):
def __init__(self, mapping, servers):
client.Resolver.__init__(self, servers=servers)
@kotnik
kotnik / gol.c
Created December 27, 2012 11:19
Game of Life in C.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define for_x for (int x = 0; x < w; x++)
#define for_y for (int y = 0; y < h; y++)
#define for_xy for_x for_y
void show(void *u, int w, int h)
{
int (*univ)[w] = u;
@kotnik
kotnik / gist:1986671
Created March 6, 2012 14:54 — forked from voxpelli/gist:1069596
OAuth Connector setup for OAuth Login provider
<?php
$provider = new stdClass;
$provider->disabled = FALSE; /* Edit this to true to make a default provider disabled initially */
$provider->name = 'sso1';
$provider->title = 'sso1';
$provider->url = 'http://sso1.loc/';
$provider->consumer_advanced = array(
'signature method' => 'HMAC-SHA512',
'request token endpoint' => '/oauth/request_token',
'authorization endpoint' => '/oauth/authorize',
-- Logs begin at Thu 2015-12-10 11:32:31 CET, end at Tue 2016-05-10 22:58:29 CEST. --
May 10 21:29:17 carpo systemd-journald[284]: Runtime journal (/run/log/journal/) is 8.0M, max 787.6M, 779.6M free.
May 10 21:29:17 carpo systemd-journald[284]: System journal (/var/log/journal/) is 1.9G, max 4.0G, 2.0G free.
May 10 21:29:17 carpo systemd-journald[284]: Time spent on flushing to /var is 96.647ms for 2 entries.
May 10 21:29:17 carpo kernel: Linux version 4.5.3-1-ARCH (builduser@tobias) (gcc version 6.1.1 20160501 (GCC) ) #1 SMP PREEMPT Sat May 7 20:43:57 CEST 2016
May 10 21:29:17 carpo kernel: Command line: BOOT_IMAGE=/vmlinuz-linux root=UUID=92fdeb9f-682d-475b-b60c-40d7a224d7de rw cryptdevice=/dev/sda2:cryptroot quiet
May 10 21:29:17 carpo kernel: x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
May 10 21:29:17 carpo kernel: x86/fpu: Supporting XSAVE feature 0x01: 'x87 floating point registers'
May 10 21:29:17 carpo kernel: x86/fpu: Supporting XSAVE feature 0x02: 'SSE registers'
May 10 21:29:17 carpo ke
#!/usr/bin/env python3
import sys
import datetime
import subprocess
from collections import Counter
if __name__ == '__main__':
hours = {}
@kotnik
kotnik / gist:7908359
Created December 11, 2013 10:44
Clean up after testing the DRBD
eval $(ls /dev/drbd* | sed 's/\/dev\/drbd//g' | awk '{print "drbdsetup " $1 " down;"}' ) ; lvremove -f /dev/platform_test/*-0 ; lvremove -f /dev/platform_test/*-1
ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAvzMU1f2mRAMTSSJmLp3QFfnZIk4AGlZQggSO1OuMEn9sqvmHSEyckW516A4eoqBvukFod4bBjl72bNZBMSCXjgELmiGxNvr0iDeuefSR4vHKBqgUp9HhDakSNGz6eBjV5XN0iyhzwe/0N4PHq0wlwwETAE1QzHGia9RiIfpo6jYUPehzUi7CKXJLmmtaOTRm6zRNdrj1P97ZBw/5CbPT2yOYPQlnl1A/FQqxocODKTSCGQSvrOZ1Y0qCmg0Fl63PcpH2KDZW5FIcIA8yPWE07xT7zfQOe+wu3IZ+aK38hUGdoZmzYPlGo49vf03/KOo6vwBUzeY2SEbZ/Nflu+F80Q==
@kotnik
kotnik / gist:6569574
Created September 15, 2013 10:36
Proper way to consistently read `/proc/mounts`.
import re
import collections
def get_current_mounts():
""" Get the currently mounted filesystems. """
# Reading from /proc/mounts is only consistent within a single read(3)
# call. Unfortunately, the maximum amount of data you can get from
# this file in a single call is hardcoded by the kernel to PAGE_SIZE
# (4096 bytes on x86). As a consequence, there is no way to read
@kotnik
kotnik / gist:6561982
Last active December 23, 2015 01:39
Validate schema with Colander for either uuid or mail are in the request.
@deferred
def deferred_check_missing(node, kw):
try:
json_request = kw.get("request").json_body
except ValueError:
raise Invalid(node, "Malformed JSON provided")
if "mail" not in json_request and "uuid" not in json_request:
raise Invalid(node, "Both mail and uuid are missing")