Skip to content

Instantly share code, notes, and snippets.

View hugows's full-sized avatar
🏠
Working from home

Hugo Schmitt hugows

🏠
Working from home
View GitHub Profile
@hugows
hugows / .screenrc
Last active March 7, 2018 16:26 — forked from jbeluch/.screenrc
Basic .screenrc (Good enough for 2018 - hugo)
startup_message off
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{..G}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a"
// This is a helper function to make Go work with https://github.com/marmelab/admin-on-rest parameters
// a little bit easier.
func QueryBuilder(tableName string, cols string, query url.Values) (string, error) {
// only match string like `name`, `users.name`
var columnRegexp = regexp.MustCompile("^[a-zA-Z\\d]+(\\.[a-zA-Z\\d]+)*$")
baseQuery := fmt.Sprintf("SELECT %s FROM %s", cols, tableName)
colsMap := make(map[string]bool)
// A slower insert that is faster to type.
func (db *DB) ReflectInsert(tablename string, obj interface{}) error {
base := "INSERT INTO %s(%s) VALUES (%s)"
count := 1
var columns []string
var placeholders []string
var vals []interface{}
v := reflect.ValueOf(obj).Elem()
t := v.Type()
type AppResponse struct {
Error error `json:"-"`
Code int `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Data interface{} `json:"data,omitempty"`
}
type apiHandler func(w http.ResponseWriter, r *http.Request) AppResponse
func (handler apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
hugo@hp ~/play/ktor-ktor-0.3.3/ktor-samples/ktor-samples-hello $ mvn exec:java -Pexec-netty
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.jetbrains.ktor:ktor-samples-hello:jar:0.3.3
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-deploy-plugin is missing. @ org.jetbrains.ktor:ktor-samples:[unknown-version], /home/hugo/play/ktor-ktor-0.3.3/ktor-samples/pom.xml, line 65, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
# Precisei disto no Linux Mint 18.1 Serena
# (http://www.andersonlfeitosa.com/2014/10/cedilha-no-linux-mint-17-com-teclado-americano.html)
sudo bash
sed -i "s/az:ca:co:fr:gv:oc:pt:sq:tr:wa/az:ca:co:fr:gv:oc:pt:sq:tr:wa:en/" /usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules.cache
sed -i "s/az:ca:co:fr:gv:oc:pt:sq:tr:wa/az:ca:co:fr:gv:oc:pt:sq:tr:wa:en/" /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules.cache
sed -i "s/ć/ç/g" /usr/share/X11/locale/en_US.UTF-8/Compose
sed -i "s/Ć/Ç/g" /usr/share/X11/locale/en_US.UTF-8/Compose
echo "GTK_IM_MODULE=cedilla" >> /etc/environment
echo "QT_IM_MODULE=cedilla" >> /etc/environment
@hugows
hugows / pack_unpack.c
Last active September 12, 2016 13:21
/* from http://number-none.com/product/Packing%20Integers/index.html */
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
static uint32_t m_accumulator = 0;
static char m_buffer[17];
char* to_bitstring(uint32_t val, char buffer[], int size) {
Originally: https://gist.github.com/vurtun/8da6c0ec7820ec002044579f84547a2e
LIBRARY WRITING REFERENCE LIST
===============================
1.) Designing and Evaluating Reusable Components (Casey Muratori: http://mollyrocket.com/casey/stream_0028.html)
----------------------------------------------------------------------------------------------------------------
_THE_ reference on API design up to this day on the internet. Nobody should write a library without having seen this.
I come back to this talk every N number of weeks it is that good.
2.) stb_howto (Sean Barrett: https://github.com/nothings/stb/blob/master/docs/stb_howto.txt)
// [[a b] [c d]] -> [[a c] [a d] [b c] [b d]]
func combinations(path []int, sets [][]int, acc *[][]int) {
if len(sets) == 0 {
*acc = append(*acc, path)
} else {
for _, el := range sets[0] {
path := append(path, el)
np := make([]int, len(path))
copy(np, path)
combinations(np, sets[1:], acc)
package main
import (
"os/exec"
"strings"
"log"
"time"
"fmt"
)