Skip to content

Instantly share code, notes, and snippets.

View xyproto's full-sized avatar
😊

Alexander F. Rødseth xyproto

😊
View GitHub Profile
@xyproto
xyproto / main.go
Created June 24, 2015 10:14
gzip compression/decompression example
package main
import (
"fmt"
"compress/gzip"
"io"
"io/ioutil"
"bytes"
"log"
)
package main
//
// Example program for checking errors when adding users.
//
// HOWEVER it might be better to instead check that the values are as expected
// in the Redis database AFTER adding them.
//
import (
@xyproto
xyproto / README.md
Last active April 9, 2020 10:21
Configuration for the Nano editor - red/black theme

Alias for .bashrc or .zshrc:

sh alias nano="LC_ALL=en_US.UTF-8 nano --smarthome --autoindent --linenumbers --mouse --historylog --trimblanks --backupdir=$HOME/.backup --rcfile=$HOME/.config/nano/config --nohelp --tempfile"

@xyproto
xyproto / props.go
Created October 3, 2018 16:06
List user properties with permissionbolt and simplebolt
package main
import (
"fmt"
"github.com/coreos/bbolt"
"github.com/xyproto/permissionbolt"
"github.com/xyproto/simplebolt"
"log"
"os"
"path"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
extern char* go_add(char*, char*) __asm__ ("example.main.Add");
char* __go_string_plus(char *a, char *b) {
char *c = malloc((strlen(a) + strlen(b) + 1));
strcat(c, a);
strcat(c, b);
@xyproto
xyproto / GC.md
Last active August 1, 2017 17:22
Garbage collection is not mandatory in Go

Go

Disable garbage collection:

debug.SetGCPercent(-1)

Trigger garbage collection:

runtime.GC()

@xyproto
xyproto / Makefile
Created July 26, 2017 14:00
One way of processing shell scripts through the C preprocessor + strip comments. Beware that cpp may do surprising things to shell scripts.
RELEASE ?= 0
%: %.in
@$(eval SHEBANG=$(shell head -1 ${<} | grep -q -F '#!' && echo 1 || echo 0))
@if [ $(SHEBANG) = 1 ]; then \
head -1 $< > $@; \
tail -n +2 $< | sed -e 's/^ *# .*$$//' -e '/^$$/d' -e '/^#$$/d' | cpp -DRELEASE=$(RELEASE) -P >> $@; \
else \
sed -e 's/^ *# .*$$//' -e '/^$$/d' -e '/^#$$/d' $< | cpp -DRELEASE=$(RELEASE) -P > $@; \
fi
@xyproto
xyproto / tag_hash.sh
Created March 21, 2017 13:12
First attempt at command line for extracting the latest tag's git hash from a PKGBUILD file that uses git
#!/bin/bash
# Try to extract the latest tag's commit hash
git ls-remote --tags $(grep source= PKGBUILD | cut -d\" -f2 | cut -d\# -f1 | cut -d+ -f2 | sed "s/\$pkgname/$(grep pkgname= PKGBUILD | cut -d= -f2)/g") | tail -1
package main
import (
"fmt"
"github.com/xyproto/permissionwrench"
"github.com/xyproto/simplehstore"
)
func main() {
perm, err := permissionwrench.New()