Skip to content

Instantly share code, notes, and snippets.

View ushuz's full-sized avatar

John HU ushuz

View GitHub Profile
@ushuz
ushuz / otp.js
Last active November 19, 2021 05:42
Minimal TOTP implementation based on Web Crypto API that runs in browser
// Minimal TOTP implementation based on Web Crypto API that runs in browser, based on:
// https://www.laroberto.com/totp-primer/
// https://github.com/BYossarian/base-desires/blob/601fb587bbc495e299a4f24b78d5ca101c7db2ce/index.js#L98-L149
const computeHOTP = async (secret, counter) => {
// https://tools.ietf.org/html/rfc4226#section-5.1
const formatCounter = (counter) => {
const binStr = ('0'.repeat(64) + counter.toString(2)).slice(-64);
let intArr = [];
for (let i = 0; i < 8; i++) {
@ushuz
ushuz / fix-country.py
Last active August 5, 2023 05:58
Fix macOS global "Country" setting
# view gloabl prefs in json
# plutil -convert json -o - -- /Library/Preferences/.GlobalPreferences.plist | python -m json.tool
import CoreFoundation as cf
# get current Country
cf.CFPreferencesCopyValue('Country', cf.kCFPreferencesAnyApplication, cf.kCFPreferencesAnyUser, cf.kCFPreferencesAnyHost)
# set Country
cf.CFPreferencesSetValue('Country', 'TW', cf.kCFPreferencesAnyApplication, cf.kCFPreferencesAnyUser, cf.kCFPreferencesAnyHost)
@ushuz
ushuz / keybase.md
Last active July 11, 2016 10:10
Keybase GitHub Proof

Keybase proof

I hereby claim:

  • I am ushuz on github.
  • I am ushuz (https://keybase.io/ushuz) on keybase.
  • I have a public key ASDlg-6JYDTg5j9xPkeoQ4wNAh5AwioNc3MPunJPEikO_Qo

To claim this, I am signing this object: