Skip to content

Instantly share code, notes, and snippets.

View titpetric's full-sized avatar

Tit Petric titpetric

View GitHub Profile
@titpetric
titpetric / purge-multi.lua
Created January 8, 2017 18:34
Delete NGINX cached items with a PURGE with wildcard support
-- Tit Petric, Monotek d.o.o., Tue 03 Jan 2017 06:54:56 PM CET
--
-- Delete nginx cached assets with a PURGE request against an endpoint
-- supports extended regular expression PURGE requests (/upload/.*)
--
function file_exists(name)
local f = io.open(name, "r")
if f~=nil then io.close(f) return true else return false end
end
@titpetric
titpetric / proxy-proc-net.sh
Created November 12, 2016 11:36
Fake copy of a part of /proc/net fs, with about 200ms of latency
#!/bin/bash
OUTPUT="/dev/shm/fakenet/";
if [ ! -d "$OUTPUT" ]; then
mkdir -p $OUTPUT/{rpc,stat,ip_vs}
fi
SOURCES="/proc/net/dev
/proc/net/ip_vs_stats
/proc/net/ip_vs/stats
@titpetric
titpetric / purge.lua
Created November 2, 2016 11:00
Delete NGINX cached items from a PURGE request
-- Tit Petric, Monotek d.o.o., Thu 27 Oct 2016 10:43:38 AM CEST
--
-- Delete nginx cached assets with a PURGE request against an endpoint
--
local md5 = require 'md5'
function file_exists(name)
local f = io.open(name, "r")
if f~=nil then io.close(f) return true else return false end
@titpetric
titpetric / gpio.go
Created July 19, 2016 14:45
Using GPIO pins with GoLang
package main
import "os"
import "io/ioutil"
import "time"
type GPIO struct{}
func (r GPIO) Pin(name string) GPIO_Pin {
pin := GPIO_Pin{name}
#!/bin/bash
function docker_run_shell {
NAME=$1
DOCKERFILE=$2
# docker needs a few libraries, but not all - essential libs here
BIND_LIBS=`ldd /usr/bin/docker | grep /lib/ | awk '{print $3}' | egrep '(apparmor|libseccomp|libdevmap|libsystemd-journal|libcgmanager.so.0|libnih.so.1|libnih-dbus.so.1|libdbus-1.so.3|libgcrypt.so.11)'`
ARGS=""
for LIB in $BIND_LIBS; do
ARGS="$ARGS -v $LIB:$LIB:ro"
@titpetric
titpetric / logtail.sh
Last active December 19, 2015 16:38
Incremental reading of files that get rotated. If files are being written to it ignores the bytes written since the first `stat` call, avoiding double reads. Fairly untested so far, not even sure if it recognizes that the log rotation was performed. Mileage may vary, feel free to submit fixes.
#!/bin/bash
function usage {
echo Usage: $0 logfile.log logfile.log.1 [name]
exit
}
if [ -z $1 ]; then
usage
fi
if [ -z $2 ]; then
@titpetric
titpetric / AnimalDependencies.php
Created July 5, 2013 11:36
Dependency Injection with Traits (PHP 5.4+)
<?php
namespace AnimalDependencies;
trait Dog {
private $dog = false;
function setDog(\Animals\Dog $dog) {
$this->dog = $dog;
}
function getDog() {