Skip to content

Instantly share code, notes, and snippets.

View titpetric's full-sized avatar
:atom:
Available for consulting

Tit Petric titpetric

:atom:
Available for consulting
View GitHub Profile
{{< tweet "Adding a \"Tweet this\" shortcode to Hugo, step-by-step tutorial" >}}
@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>
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 / 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 / count-imports.go
Created November 29, 2022 16:47
Count imports (detect import pollution)
package main
import (
"errors"
"fmt"
"go/parser"
"go/token"
"log"
"os"
"path/filepath"