Skip to content

Instantly share code, notes, and snippets.

(function() {
sessionStorage.clear();
const targetNode = document.querySelector('.unredeemed-keys-table');
if (!targetNode) {
return;
}
const config = { attributes: true, childList: true, subtree: true };
const steamRegex = /\S{5}-\S{5}-\S{5}(-\S{5}-\S{5})?/;
const extract = (mutationsList, observer) => {
@lamchau
lamchau / remove-null.sh
Last active June 14, 2020 07:26
removing null/empty values from JSON
# from: https://github.com/stedolan/jq/issues/104
# more explicit (per value)
walk(
if type == "object" then
with_entries(
select(
.value != null and
.value != "" and
.value != [] and
@lamchau
lamchau / glog.fish
Created May 20, 2020 08:16
git log + fzf + delta => returns git_sha
# ported from https://github.com/junegunn/fzf/wiki/examples#git
function glog --description 'git log + fzf + delta => returns git_sha'
set -lx git_dir (git rev-parse --git-dir 2> /dev/null)
if test -n "$git_dir"
set -l EXTRACTED_SHA "echo {} | head -1 | cut -d' ' -f1"
set -l VIEW_LINE "$EXTRACTED_SHA | xargs -I % sh -c 'git show --color=always % | delta'"
set -l FORMAT "%C(auto)%h%d %s %C(black)%C(bold)%cr% C(auto)%aE"
set -l commit_sha (git log --color=always --format="$FORMAT" $argv \
| fzf --no-sort --reverse --tiebreak=index --no-multi --ansi --preview="$VIEW_LINE" \
| cut -d' ' -f1)
@lamchau
lamchau / glog.sh
Created May 19, 2020 11:20
browsable git log (requires `fzf` `delta`)
#!/usr/bin/env bash
# derived from https://github.com/junegunn/fzf/wiki/examples#git
glog() {
# extra sha from git log
local parse_log="echo {} | grep -o '[a-f0-9]\{7\}' | head -1"
# pass log line into colorized diff `delta`
# https://github.com/dandavison/delta
local view_line="$parse_log | xargs -I % sh -c 'git show --color=always % | delta'"
@lamchau
lamchau / git-stat.py
Last active May 12, 2020 08:04
creates a table for total git differences on a file or directory (with net changes)
#!/usr/bin/env python
import git
import logging
import os
import re
import sys
from collections import Counter
from prettytable import PrettyTable
@lamchau
lamchau / volume.sh
Created January 26, 2020 14:03
bash script for setting the volume on macOS
#!/usr/bin/env bash
MIN_LEVEL=0
MAX_LEVEL=100
if [ "$#" -eq 0 ]; then
LEVEL=$MAX_LEVEL
else
LEVEL=$1
fi
@lamchau
lamchau / iterm_open_with
Last active January 5, 2020 09:41 — forked from trinitronx/iterm_open_with
Semantic history command for iTerm2 and Sublime Text 3. Allows iTerm integration of Command+Click to open a file in default app (if non-text), or Sublime Text with optional line number and column. Detects relative paths based on PWD. From: https://coderwall.com/p/0kapug/iterm2-open-text-file-paths-in-sublime-text-with-jump-to-line-number
#!/bin/sh
# iterm_open_with - open a URL, file from CWD, full path, or path with linenumber in default app or Sublime Text if text file
# For usage with iTerm2:
# In iTerm's Preferences > Profiles > Default > Advanced > Semantic History,
# choose "Run command..." and enter "/your/path/to/iterm_open_with \5 \1 \2".
# Usage: iterm_open_with $(pwd) filename [linenumber]
# $(pwd) = current working directory (either use `pwd` or $PWD)
# filename = filename to open
# lineno = line number
pwd=$1
#!/usr/bin/env python3
import math
from prettytable import PrettyTable
def main():
params = {
'amount': 12.34,
'split': 1
$asArray = selector => Array.from(document.querySelectorAll(selector));
loadMore = setInterval(() => {
const clickButton = ($x, index) => setTimeout(() => $x.click(), index * 25);
const $more = $asArray('.load-more');
if ($more.length) {
$more.forEach(clickButton);
return;
}
clearInterval(loadMore);
$asArray('.grid-coupon-btn').forEach(clickButton);
@lamchau
lamchau / purge-facebook-ads-info.md
Last active June 9, 2019 06:20
Facebook builds an extensive list for targeting you on ads, this bookmarklet script will remove/purge all interests.