Skip to content

Instantly share code, notes, and snippets.

View titpetric's full-sized avatar

Tit Petric titpetric

View GitHub Profile
@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 / 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}
@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
{{< tweet "Adding a \"Tweet this\" shortcode to Hugo, step-by-step tutorial" >}}
func parse(input io.Reader) (p *point, err error) {
// handle read errors
read := func(data interface{}) {
if err == nil {
err = binary.Read(input, binary.BigEndian, data)
}
}
p := &point{}
read(&p.Longitude)
@titpetric
titpetric / mysql-testing.sh
Created April 30, 2018 19:42
MySQL docker testing bash script to spin up mysql container
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 [start/stop]"
exit 1
fi
function setup_database {
NAME="$1"
DOCKERFILE="titpetric/percona-xtrabackup"
docker run -d -h $NAME --name $NAME --net=party -e MYSQL_ROOT_PASSWORD="testing" $DOCKERFILE
@titpetric
titpetric / main_test.go
Created August 3, 2018 16:43
Illustrated example of poor implementation (memory use)
package main
import (
"strings"
"testing"
)
func BenchmarkStringReverseBad(b *testing.B) {
b.ReportAllocs()
@titpetric
titpetric / tweet.html
Created May 9, 2017 13:20
Hugo "Tweet this" shortcode HTML
<blockquote class="tweet-this">
<p><a href="http://twitter.com/intent/tweet?url={{ .Page.Permalink }}&text=&quot;{{ .Get 0 }}&quot;&via=TitPetric" target="_blank">"{{ .Get 0 }}" via @TitPetric</a></p>
<a href="http://twitter.com/intent/tweet?url={{ .Page.Permalink }}&text=&quot;{{ .Get 0 }}&quot;&via=TitPetric" target="_blank"><i class="fa fa-twitter"></i>Click to Tweet</a>
</blockquote>
@titpetric
titpetric / composer.json
Last active March 3, 2020 13:45
Fetch Wowza serverinfo statistics and write out SQL queries
{
"require": {
"guzzlehttp/guzzle": "~6.0"
}
}
@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() {