Skip to content

Instantly share code, notes, and snippets.

View mpdroog's full-sized avatar

MP Droog mpdroog

View GitHub Profile
@mpdroog
mpdroog / http_query.go
Created June 10, 2016 18:29
SELECT-query through Go without types
package sql
import (
"database/sql"
"net/http"
"github.com/julienschmidt/httprouter"
"log"
"github.com/mpdroog/invoiced/writer"
)
@mpdroog
mpdroog / toml.po.php
Created December 27, 2018 13:29
TOML-config to PO-file for Poedit
<?php
/**
* TOML to PO converter.
*/
$args = $_SERVER["argv"];
if ($args[0] === "php") {
array_shift($args);
}
array_shift($args);
$args = array_values($args); // php-file

Keybase proof

I hereby claim:

  • I am mpdroog on github.
  • I am mpdroog (https://keybase.io/mpdroog) on keybase.
  • I have a public key ASCAECt2B8dGFQJtmjIIPjKV_tBYUUT6Hj23-ug-YCVTNwo

To claim this, I am signing this object:

@mpdroog
mpdroog / http-dump.php
Last active December 4, 2020 09:36
Dump HTTP-request for easy debugging if head/body is properly set
<?php
/**
* Dump received HTTP-request to console for quickly
* seeing what we're trying to send.
*/
$address = '127.0.0.1';
$port = 8080;
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, $address, $port) or die('Could not bind to address');
<?php
// Search&Replace all occurrences of a given string
// Got tired of all the harship with sed -i so made this
// small script to get the same result.
$search = "Fn";
$replace = "Shared";
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.'));
foreach ($rii as $file) {
if (in_array($file->getFilename(), [".", "..", "findreplace.php", ".git"])) continue; // Ignored files (in curdir)
<?php
/**
* PO to JSON.
*/
$lang = "fr";
$lines = explode("\n", file_get_contents(__DIR__ . "/text.po"));
array_shift($lines); array_shift($lines); // Ignore first two lines
$out = [];
@mpdroog
mpdroog / StringMap
Last active June 3, 2021 17:04
golang XML map[string]string encode/decode
// https://stackoverflow.com/questions/30928770/marshall-map-to-xml-in-go
// https://stackoverflow.com/questions/33486725/golang-xml-unmarshal-interface-types
package main
import (
"fmt"
"encoding/xml"
)
// StringMap is a map[string]string.
@mpdroog
mpdroog / once.sh
Created August 31, 2021 13:48
Ensure only one instance at the same time
#!/usr/bin/env bash
# Using lock-file to ensure only one instance can be running
# at the same time.
# DevNote: The trap is used to ensure we ALWAYS remove the lock upon completion
set -x
set -e
if ! mkdir /tmp/MYSCRIPT.lock; then
printf "MYSCRIPT already running.\n" >&2
exit 1
fi
@mpdroog
mpdroog / bootstrap-carousel.js
Created March 4, 2022 14:02
Minimal JS to implement bootstrap carousel
// Small (vanilla) JS to make div scroll with the view
// Saving this code for historical purposes
// Note: In 2022 this is also possible with CSS through position: sticky
var dom = {
off: function ($node) {
var sum = $node.offsetTop;
if ($node.offsetParent) {
sum += dom.off($node.offsetParent);
}