Skip to content

Instantly share code, notes, and snippets.

@miekg
miekg / gitconfig
Created December 4, 2023 16:09
git config
# Fetch a mr/pr number from the hub and check it out in either mr-<num> or pr-<num> branch
pr = "!f() { \
case $(git hubtype) in \
github) git githubpr;; \
gitlab) git gitlabpr;; \
esac; \
}; f"
gitlabpr = "!f() { pr=$(basename $1); git fetch origin pull/$pr/head:pr-$pr && git checkout pr-$pr; }; f"
githubpr = "!f() { mr=$(basename $1); git fetch origin merge-requests/$mr/head:mr-$mr && git checkout mr-$mr; }; f"
hubtype = "!f() { case $(git remote get-url origin) in *github*) echo github;; *gitlab*) echo gitlab;; esac; }; f"
@miekg
miekg / replace2.go
Created November 14, 2023 16:39
replace BBCode [color=#xxxxx] with terminal equivalent
package main
import (
"bytes"
"flag"
"fmt"
"log"
"os"
"os/exec"
"strconv"
@miekg
miekg / gallery.html
Created September 6, 2023 18:48
hugo shortcode to have a gallery
@miekg
miekg / udpserv.go
Created May 10, 2017 09:29
Simple udp server in Go
package main
import (
"log"
"net"
)
func main() {
// listen to incoming udp packets
pc, err := net.ListenPacket("udp", ":1053")
@miekg
miekg / udpserv.c
Created May 10, 2017 10:33
udp server in C
/*
* udpserver.c - A simple UDP echo server
* usage: udpserver <port>
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
# check current service
% ./gitopperctl list service @localhost grafana-server
SERVICE HASH STATE INFO SINCE
grafana-server 606eb576c1b91248e4c1c4cd0d720f27ac0deb70 OK 0001-01-01 00:00:00 +0000 UTC
# oh no, we need to rollback
% ./gitopperctl state rollback @localhost grafana-server 8df1b3db679253ba501d594de285cc3e9ed308ed
# check
package dns
import (
"fmt"
"net"
"testing"
)
// Test function to test how the API feels.
func TestDNS(t *testing.T) {
@miekg
miekg / 14-add-lockaftersleep-patch
Created March 8, 2014 13:14
add -lockaftersleep to xautolock
Description: Add -lockaftersleep
Lock the moment the machine comes out of sleep.
.
xautolock (1:2.2-4) unstable; urgency=low
.
* debian/control:
- Removed xautolock from Recommends since it was removed from Debian
- Standards-Version: 3.9.4
- Depends: debhelper (>= 9)
* debian/compat: 9
package main
import (
"fmt"
"log"
"os"
"github.com/miekg/dns"
)
@miekg
miekg / coredns.md
Created March 25, 2021 09:50
coredns overlay plugin

Corefile is:

example.com {
    file db.example.com
    debug
    lboverlay example.com
    forward . 8.8.8.8
}