Skip to content

Instantly share code, notes, and snippets.

View antelle's full-sized avatar

Dimitri Witkowski antelle

View GitHub Profile
@antelle
antelle / yubikey-hmac-secret.sh
Created March 29, 2021 21:10
PoC of using FIDO2 hmac-secret with a YubiKey
# https://github.com/trezor/trezor-firmware/blob/master/tests/fido_tests/libfido2/hmac-secret.sh
# DEVICE=$(fido2-token -L | cut -d : -f 1)
DEVICE=$(fido2-token -L | cut -d : -f 1-2)
if [ -z "$DEVICE" ] ; then
echo "No FIDO2 token found"
exit 1
fi
@antelle
antelle / codesign-macos.sh
Created March 27, 2021 15:06
Code signing on macOS
# show all
codesign -dv -vvvvvv my.app
# print entitlements
codesign --display --entitlements :- my.app
# get certificates
codesign --display --extract-certificates my.app
@antelle
antelle / shebang.sh
Last active March 27, 2021 15:05
bash shebang
#!/bin/bash
set -euxo pipefail
@antelle
antelle / x11-print-layout.cpp
Created March 20, 2021 11:54
x11-print-layout.cpp
// g++ x11-print-layout.cpp -lX11 -o x11-print-layout
// dumps keybaord layout on x11
#include <X11/XKBlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <iostream>
Display *display;
const started = process.hrtime();
// something
const elapsed = process.hrtime(started);
const elapsedMs = Math.round(elapsed[0] * 1e3 + elapsed[1] / 1e6);
console.log(`Elapsed ${elapsedMs} ms`);
@antelle
antelle / openssl.sh
Created September 6, 2019 16:43
OpenSSL file encrypt/decrypt
# encrypt file.txt to file.enc using 256-bit AES in CBC mode
openssl enc -aes-256-cbc -salt -in file.txt -out file.enc
# the same, only the output is base64 encoded for, e.g., e-mail
openssl enc -aes-256-cbc -a -salt -in file.txt -out file.enc
# decrypt binary file.enc
openssl enc -d -aes-256-cbc -in file.enc -out file.txt
# decrypt base64-encoded version
@antelle
antelle / flush_dns_cache.sh
Created September 6, 2019 16:43
Flush DNS cache on macOS
sudo killall -HUP mDNSResponder
@antelle
antelle / ram_disk.sh
Created September 6, 2019 16:41
Create a RAM disk on macOS
# 42 = desired disk size in megabytes
diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nomount ram://$((42*2048))`
@antelle
antelle / server.js
Created February 10, 2019 14:39
Simple web server with node.js
const http = require('http');
const path = require('path');
const fs = require('fs');
const port = 8080;
const server = http.createServer((req, resp) => {
const filePathPart = req.url.substr(1) || 'index.html';
const filePath = path.resolve(__dirname, filePathPart);
if (!filePath.startsWith(__dirname)) {
@antelle
antelle / escape.js
Last active March 9, 2018 15:49
JS string escape
function escape(str) {
return str.replace(/[\n\r\\\'\u2028\u2029]/g, ch => {
if (ch === '\n') { return '\\n'; }
else if (ch === '\r') { return '\\r'; }
else if (ch === '\\') { return '\\\\'; }
else if (ch === '\'') { return '\\\''; }
else if (ch === '\u2028') { return '\\u2028'; }
else if (ch === '\u2029') { return '\\u2029'; }
else throw 'Bad char';
});