Skip to content

Instantly share code, notes, and snippets.

@callemo
callemo / wg.sh
Last active August 9, 2023 15:22
WireGuard for OpenBSD
#!/bin/sh
gw="$(route -n show | awk '$1 == "default" { print $2 }')"
awk -v gw="$gw" '
$1 == "PrivateKey" { key = $3 }
$1 == "Address" {
addr = $3
sub(/,.*/, "", addr)
}
$1 == "DNS" { dns = $3 }
$1 == "PublicKey" { peer = $3 }
@callemo
callemo / dock.sh
Created August 1, 2023 18:31
Dock and undock your OpenBSD laptop
#!/bin/sh
# dock: switches between external and internal displays.
prefix="${0##*/}:"
log() { echo "$prefix" "$@" >&2; }
fatal() { log "$@"; exit 1; }
int='eDP-1'
mode='1920x1080'
[ "$(uname)" = OpenBSD ] || fatal 'not running in OpenBSD'
@callemo
callemo / Makefile
Last active March 29, 2020 23:10
Makefile for java projects
artifactId = a
directory = build
outputDirectory = $(directory)/classes/java/main
sourceDirectory = src/main/java
sources = $(shell find $(sourceDirectory) -name \*.java)
objects = $(sources:$(sourceDirectory)/%.java=$(outputDirectory)/%.class)
package = $(directory)/libs/$(artifactId).jar
JAR = jar
JAR_FLAGS = cvf
@callemo
callemo / .tmux.conf
Last active March 28, 2020 23:46
Simple vim and tmux configuration
set-option -g prefix C-a
bind-key C-a send-prefix
set-option -g default-terminal "screen-256color"
set-option -g escape-time 50
set-option -g focus-events on
set-option -g history-limit 10000
set-option -g mouse on
set-option -g status-bg default
set-option -g status-fg default
/* trie.js */
class TrieNode {
constructor(value) {
this.value = value;
this.children = new Map();
this.isEndOfWord = false;
}
}
@callemo
callemo / install-userkeymap.sh
Last active October 13, 2019 06:40
Remapping Keys in macOS
#!/bin/bash
# Remapping Keys in macOS
# https://developer.apple.com/library/archive/technotes/tn2450/_index.html
set -e
userscript="$HOME/bin/userkeymap"
mkdir -p "$HOME"/bin
cat <<EOF > "$userscript"
#!/bin/bash
hidutil property --set '{"UserKeyMapping": [
{"HIDKeyboardModifierMappingSrc": 0x700000064, "HIDKeyboardModifierMappingDst": 0x700000035}
@callemo
callemo / Dockerfile
Created February 1, 2019 13:14
Cling environment
FROM debian:buster
ENV SHELL=/bin/bash
RUN apt-get update -y && apt-get install -y \
bash-completion \
build-essential \
cmake \
ctags \
curl \
git \
git-extras \
@callemo
callemo / collection.sql
Last active July 11, 2018 10:02
Unstructured key-value storage for MySQL
CREATE TABLE IF NOT EXISTS `collection` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`uuid` BINARY(16) NOT NULL,
`value` MEDIUMBLOB NOT NULL,
`version` BIGINT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'optimistic updates',
`format` ENUM ('R', 'J', 'M') NOT NULL DEFAULT 'J' COMMENT 'R: raw, J: json, M: msgpack',
`compression` ENUM ('N', 'Z') NOT NULL DEFAULT 'N' COMMENT 'N: none, Z: gzip',
`deleted_at` DATETIME NULL DEFAULT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
@callemo
callemo / escapeHTML.js
Created July 5, 2018 18:11
Escape HTML text. Distilled from `handlebars/utils.js`.
const entity = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#x27;",
"`": "&#x60;",
"=": "&#x3D;"
};
@callemo
callemo / htag.js
Last active July 5, 2018 14:47
htag.js – A Bare bones interpretation of the Hyperscript syntax.
/*
htag.js
A Bare bones interpretation of the Hyperscript syntax.
*/
var h = function h(tag, attributes, ...children) {
const node = document.createElement(tag);
attributes = attributes || {};
Object.keys(attributes).forEach(attr => {
if (attr === "style" || attr === "dataset") {
const value = attributes[attr];