Skip to content

Instantly share code, notes, and snippets.

@jmiserez
jmiserez / export_google_music.js
Last active December 20, 2023 01:45
(fixed/updated 2016-05-10) Export your Google Music Library and Playlists (Google Play Music All Access) (see http://webapps.stackexchange.com/questions/50311/print-playlist-from-google-play-music for more)
// Copyright 2016 Jeremie Miserez <jeremie@miserez.org>
//
// MIT License
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF O
@jmiserez
jmiserez / gist:744116545d7f595923966f883c4f1b5d
Last active August 11, 2023 07:32
CyberChef: Parse Google Authenticator QR Code (single export) using protobuf schema and extract TOTP secret as Base32
1. Go to https://gchq.github.io/CyberChef/
2. Download CyberChef (top left), extract .zip and open .html file
3. Click "Load Recipe" in the top middle
4. Enter the following recipe:
Parse_QR_Code(false)
Regular_expression('User defined','otpauth-migration\\:\\/\\/offline\\?data\\=(.*)',true,false,true,false,false,false,'List capture groups')
URL_Decode()
From_Base64('A-Za-z0-9+/=',true)
Protobuf_Decode('syntax = "proto3";\n\noption java_package = "com.beemdevelopment.aegis";\noption java_outer_classname = "GoogleAuthProtos";\n\nmessage MigrationPayload {\n enum Algorithm {\n ALGORITHM_UNSPECIFIED = 0;\n ALGORITHM_SHA1 = 1;\n ALGORITHM_SHA256 = 2;\n ALGORITHM_SHA512 = 3;\n ALGORITHM_MD5 = 4;\n }\n\n enum DigitCount {\n DIGIT_COUNT_UNSPECIFIED = 0;\n DIGIT_COUNT_SIX = 1;\n DIGIT_COUNT_EIGHT = 2;\n }\n\n enum OtpType {\n OTP_TYPE_UNSPECIFIED = 0;\n OTP_TYPE_HOTP = 1;\n OTP_TYPE_TOTP = 2;\n }\n\n message OtpParameters {\n bytes secret = 1;\n string name = 2;\n str
@jmiserez
jmiserez / bingdesktop.sh
Last active January 19, 2022 13:21
Linux / WSL alternative client for Bing Wallpaper, with annotation using ImageMagick
#!/bin/bash
# exit on error
set -e
# Description:
# - Linux-compatible alternative to the official Bing Wallpaper client (https://www.microsoft.com/en-us/bing/bing-wallpaper).
# - Downloads the current Bing wallpaper of the day directly.
# - Fetches the matching image description / copyright information and overlays it onto the image using ImageMagick.
#
@jmiserez
jmiserez / wslsuspendresumeps.sh
Last active June 12, 2019 16:54
Bash on WSL or Cygwin: suspend and resume Windows processes by name and optionally command line part
# Add this to your Cygwin or WSL Ubuntu .bashrc
# Args:
# - process name
# - optional: commandline (use '%' as wildcards)
# Example: suspendps name commandline
# - suspendps notepad.exe %mytextfile.txt%
# - resumeps notepad.exe
# Note: pssuspend64.exe must be installed and available (https://docs.microsoft.com/en-us/sysinternals/downloads/pssuspend)
getwin32processid() {
# WSL / Windows 10 suitable version without spawning a shell
@jmiserez
jmiserez / forallsubdirs.sh
Last active June 12, 2019 13:48
Bash: "Execute for all subdirectories", execute commands in all subdirectorys, cache output and print sequentially with locking
# Add this to your .bashrc and source it (source ~/.bashrc)
# Example: forallsubdirs basedir commands
# - forallsubdirs . "ls | wc -l; git status"
# - forallsubdirs . "git fetch --all; git merge --ff-only"
# Note:
# - To include hidden directories (starting with a "."), set the dotglob option in Bash: shopt -s dotglob
# - Silencing job control (see comments) is only partially possible, in certain cases job control output will still be printed (see https://stackoverflow.com/a/38278291/202504).
forallsubdirs() {
if [ -d "$1" ]; then
dir="$1"
@jmiserez
jmiserez / rightclick-element-ios-safari-bookmarklet.js
Last active October 22, 2018 08:27 — forked from foobear/copy-element-text-bookmarklet.js
JavaScript bookmarklet to right click an element in Safari Mobile. Only works when "Request Desktop Site" is used, tested on 12.0.1. Adapted from https://gist.github.com/foobear/f19f2cca87eaf005922323fe04f993c7 (license: MIT).
# Bookmarklet on one line:
javascript:(function(){var x=0;var y=0;var overlay=document.createElement('div');Object.assign(overlay.style,{position:'fixed',top:0,left:0,width:'100vw',height:'100vh',zIndex:99999999,background:'transparent',cursor:'crosshair'});document.body.append(overlay);overlay.addEventListener('click',function(event){Object.assign(overlay.style,{width:0,height:0});x= event.clientX;y=event.clientY; var element=document.elementFromPoint(x,y);var position=element.getBoundingClientRect();Object.assign(overlay.style,{background:'rgba(0,128,255,0.25)',outline:'1px solid rgba(0,128,255,0.5)',top:''+position.top+'px',left:''+position.left+'px',width:''+position.width+'px',height:''+position.height+'px'});setTimeout(function(){var ev1=new MouseEvent("mousedown",{bubbles:true,cancelable:false,view:window,button:2,buttons:2,clientX:x,clientY:y});element.dispatchEvent(ev1);var ev2=new MouseEvent("mouseup",{bubbles:true,cancelable:false,view:window,button:2,buttons:0,clientX:x,clientY:y});element.dispatc
@jmiserez
jmiserez / extensions.zotfile.wildcards.user
Created May 27, 2016 19:21
Zotero ZotFile Renaming user json for setting: zotfile.wildcards.user. Simplifies series field (remove all non-words, e.g. "PLDI '14" -> "PLDI14") for journal articles and conference papers. Use like this: "{%a_}{%y_}{%1|%w_}{%t}" in ZotFile settings. Also see this bug report: https://github.com/jlegewie/zotfile/issues/170
{
"1":{
"default":{},
"journalArticle":{
"field":"series",
"operations":[
{
"function":"replace",
"regex":"\\W",
"replacement":"",
@jmiserez
jmiserez / vm.c
Created January 6, 2016 14:54
X86 (subset) interpreter, prototype. Reads instructions from plaintext file, instructions separated by spaces.
/*
* vm.c - Simple X86 interpreter
*
* Copyright (c) 2013, Jeremie Miserez <jeremie@miserez.org>
*/
/*
* Highlights/Features not specified in assignment
* ===============================================
* - Memory simulation of all 4GB with paging
#!/bin/bash
# Make default camera /dev/video0 point to the "best" camera present.
# Source: Jason Eisner http://askubuntu.com/a/520857/145754
# on question http://askubuntu.com/questions/396952/how-to-change-the-default-webcam-changing-dfaults-in-multimedia-selctor-not-wor
setdefaultwebcam() {
if [ -h /dev/video0 ]; then
sudo rm /dev/video0 # not first run: remove our old symlink
elif [ -e /dev/video0 ]; then
sudo mv /dev/video0 /dev/video0.original # first run: rename original video0
@jmiserez
jmiserez / bash_run_parallel.sh
Last active May 18, 2016 09:17
Run bash functions in parallel for a list of directories. Emulates GNU parallel (grouped output) but only uses standard tools (find, xargs, bash, etc.)
#!/bin/bash
# reliable way to get the directory where this file is stored
SCRIPT=$(readlink -f $0)
export SCRIPTPATH=`dirname $SCRIPT`
SCRIPTNAME=$(basename "$SCRIPT")
if [ "$#" -lt 1 ]
then
echo "Usage: ./$SCRIPTNAME <root folder path> [<pattern for matching directories within root directory, default is \"*\">]"
echo "or ./$SCRIPTNAME -i <single directory path to process>"