Skip to content

Instantly share code, notes, and snippets.

@Komosa
Komosa / prepipe.cpp
Created September 18, 2018 20:15
pass thru, but color some words and cut some lines
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
#define EACH(it, cont) for (auto &it: cont)
#define TermReset "\e[0m"
#define TermBlack "\e[0;30m"
#define TermRed "\e[0;31m"
@Komosa
Komosa / clickpad.sh
Created October 15, 2017 13:23
clickpad.sh
#!/bin/bash
#
# list of synaptics device properties http://www.x.org/archive/X11R7.5/doc/man/man4/synaptics.4.html#sect4
# list current synaptics device properties: xinput list-props '"SynPS/2 Synaptics TouchPad"'
#
#sleep 5 #added delay...
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Device Enabled" 8 1
xinput --set-prop --type=int --format=32 "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 4
xinput --set-prop --type=int --format=32 "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 9 # Below width 1 finger touch, above width simulate 2 finger touch. - value=pad-pixels
@Komosa
Komosa / rm_files.sh
Created October 13, 2017 08:57
nice awk trick
#!/bin/bash
# remove files not in arrar 'files_to_keep'
find -type f -name '*.bin' \
| awk -v keep=" ${files_to_keep[*]} " -e 'keep !~ " "$0" "' \
| xargs -L1 -I II sh -c 'git rm -f II 2>/dev/null || rm II'
@Komosa
Komosa / stoper.html
Last active September 19, 2017 07:38
standup stoper
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Stoper to keep your standup under control (at least it duration)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
text-align: center;
@Komosa
Komosa / htmlize.go
Created March 7, 2017 00:19
htmlize
package main
import (
"errors"
"fmt"
"html/template"
"io"
"os"
"strings"
)
@Komosa
Komosa / unyaml.go
Created February 5, 2017 22:16
unyaml
package main
import (
"flag"
"io/ioutil"
"os"
yaml "gopkg.in/yaml.v2"
)
@Komosa
Komosa / _test.go
Created July 11, 2016 10:03
error handling in golang tests
func Test(t *testing.T) {
fatalIf := func(err error) {
if err != nil {
t.Fatal(err)
}
}
err := os.MkdirAll(TEST_DATA_DIR, 0700)
fatalIf(err)
func TestUpdate(t *testing.T) {
os.RemoveAll(TEST_DATA_DIR)
defer os.RemoveAll(TEST_DATA_DIR)
if err := os.MkdirAll(TEST_DATA_DIR, 0700); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(TEST_DATA_DIR+"/number_of_partitions", []byte("2"), 0600); err != nil {
t.Fatal(err)
}
db, err := OpenDB(TEST_DATA_DIR)
@Komosa
Komosa / cookie.go
Created March 10, 2016 06:41
persistent cookie
@Komosa
Komosa / drawstring.go
Last active March 2, 2016 22:37
termbox: drawString
func drawString(s string, x, y int, fg, bg termbox.Attribute) {
// s = strings.Replace(s, "\t", " ", -1)
// s = strings.Replace(s, "\r", "^R", -1)
w, _ := termbox.Size()
for _, ch := range s {
if x+runewidth.RuneWidth(ch) >= w {
break
}
termbox.SetCell(x, y, ch, fg, bg)
x += runewidth.RuneWidth(ch)