Skip to content

Instantly share code, notes, and snippets.

Avatar
🏡
WFH 🦠

Dimitri Witkowski antelle

🏡
WFH 🦠
View GitHub Profile
@antelle
antelle / yubikey-hmac-secret.sh
Created Mar 29, 2021
PoC of using FIDO2 hmac-secret with a YubiKey
View yubikey-hmac-secret.sh
# 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 Mar 27, 2021
Code signing on macOS
View codesign-macos.sh
# 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 Mar 27, 2021
bash shebang
View shebang.sh
#!/bin/bash
set -euxo pipefail
View 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;
View elapsed.js
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 Sep 6, 2019
OpenSSL file encrypt/decrypt
View openssl.sh
# 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 Sep 6, 2019
Flush DNS cache on macOS
View flush_dns_cache.sh
sudo killall -HUP mDNSResponder
@antelle
antelle / ram_disk.sh
Created Sep 6, 2019
Create a RAM disk on macOS
View ram_disk.sh
# 42 = desired disk size in megabytes
diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nomount ram://$((42*2048))`
@antelle
antelle / server.js
Created Feb 10, 2019
Simple web server with node.js
View server.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 Mar 9, 2018
JS string escape
View escape.js
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';
});