Skip to content

Instantly share code, notes, and snippets.

View titpetric's full-sized avatar

Tit Petric titpetric

View GitHub Profile
@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"
@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 / 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 / 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
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 / 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>
{{< tweet "Adding a \"Tweet this\" shortcode to Hugo, step-by-step tutorial" >}}
@titpetric
titpetric / setup_ssmtp.bash
Created April 13, 2017 21:27
setting up ssmtp config from environment variables (docker start-up script)
#!/bin/bash
#
# You can set up sSMTP by setting the following ENV variables:
#
# SSMTP_TO - This is the address alarms will be delivered to.
# SSMTP_SERVER - This is your SMTP server. Defaults to smtp.gmail.com.
# SSMTP_PORT - This is the SMTP server port. Defaults to 587.
# SSMTP_USER - This is your username for the SMTP server.
# SSMTP_PASS - This is your password for the SMTP server. Use an app password if using Gmail.
# SSMTP_TLS - Use TLS for the connection. Defaults to YES.
@titpetric
titpetric / graphql-mini.php
Created April 11, 2017 08:47
Transform GraphQL fields into JSON to use them for filtering native PHP arrays
<?php
/** A poor mans GraphQL fields parser
*
* Try to convert graphQL fields to JSON and then just use json_decode to produce an array.
*/
class Fields
{
/** Parse GraphQL fields into an array */
public static function parse($query)
@titpetric
titpetric / client.lua
Created March 10, 2017 10:37
LUA FFI bridge to Go shared Lib
local ffi = require("ffi")
local awesome = ffi.load("./awesome.so")
ffi.cdef([[
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef double GoFloat64;