Skip to content

Instantly share code, notes, and snippets.

View titpetric's full-sized avatar

Tit Petric titpetric

View GitHub Profile
@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 / 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 / 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;
@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 / 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 / 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)
#!/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 / 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() {
@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 / 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>