Skip to content

Instantly share code, notes, and snippets.

View wtakuo's full-sized avatar

Takuo Watanabe wtakuo

View GitHub Profile
#!/usr/bin/env node
// wpa_passphrase - Generate a WPA PSK from an ASCII passphrase for a SSID
// usage: wpa_passphrase <ssid> [passphrase]
const crypto = require('crypto');
if (process.argv.length < 3 || process.argv.length > 4) {
console.error('usage: wpa_passphrase <ssid> [passphrase]');
process.exit(1);
}
#!/usr/bin/env python3
# wpa_passphrase - Generate a WPA PSK from an ASCII passphrase for a SSID
# usage: wpa_passphrase <ssid> [passphrase]
import sys
from hashlib import pbkdf2_hmac
from getpass import getpass
if len(sys.argv) < 2 or len(sys.argv) > 3:
print("usage: wpa_passphrase <ssid> [passphrase]", file = sys.stderr)
@wtakuo
wtakuo / launch.json
Last active November 11, 2024 22:51
To debug xv6 from VScode
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
@wtakuo
wtakuo / uppaal
Last active December 20, 2020 14:18
UPPAAL startup script for macOS
#!/usr/bin/env bash
#
# Run this script to start UPPAAL 4.1.x.
#
# Default options if needed.
# Add -Duppaal.extra if you want to force extra features.
# JAVA_DEF="-Duppaal.extra"
#JAVA_DEF=-Duppaal.lsc
@wtakuo
wtakuo / sizes.c
Created March 16, 2017 08:22
Prints data sizes
#include <stdio.h>
#define print_size(t) printf("sizeof(%s) = %zu\n", #t, sizeof(t))
int main(void) {
print_size(char);
print_size(short);
print_size(int);
print_size(long);
print_size(long long);
@wtakuo
wtakuo / signed.py
Created June 3, 2016 07:44
Sign Extension Functions in Python
# Sign Extension Functions in Python
# adapted from Henry S. Warren, Jr., Hacker's Delight (2e), Ch. 2, Addison-Wesley, 2012.
# signed byte to signed int
def sb1(x):
return ((x + 0x80) & 0xff) - 0x80
def sb2(x):
return ((x & 0xff) ^ 0x80) - 0x80
#!/usr/bin/env python
'''
OpenCV WebCam Viewer
Reference: http://stackoverflow.com/questions/2601194/displaying-webcam-feed-using-opencv-and-python
'''
import cv2
def camview(name):
cv2.namedWindow(name)
@wtakuo
wtakuo / e.hs
Created May 9, 2014 10:23
arbitrary precision e as a lazy list
-- arbitrary presision e as a lazy list
main = print $ take 1000 e
e = conv (2 : [1, 1 ..])
where
conv (x : xs) =
x : conv (norm 2 (0 : map (* 10) xs))
norm c (x : y : xs) =
if y + 9 < c then zs else carry c zs