Skip to content

Instantly share code, notes, and snippets.

@lamchau
lamchau / bugsnag_event_exporter.py
Last active September 27, 2020 09:09
Python3 script to download all events from a bugsnag URL
#!/usr/bin/env python3
import collections
from typing import List
import datetime
import distutils.spawn
import hashlib
import json
@lamchau
lamchau / build-tmux.sh
Created September 14, 2020 03:03 — forked from mbreese/build-tmux.sh
HOWTO build a statically linked tmux in one script (downloads and builds dependencies from source)
#!/bin/bash
TARGETDIR=$1
if [ "$TARGETDIR" = "" ]; then
TARGETDIR=$(python -c 'import os; print os.path.realpath("local")')
fi
mkdir -p $TARGETDIR
libevent() {
curl -LO https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
tar -zxvf libevent-2.0.22-stable.tar.gz
@lamchau
lamchau / go-link-client.py
Created August 23, 2020 04:05
https://www.golinks.io client for learning python3 and argparse
@lamchau
lamchau / cli.py
Created August 22, 2020 07:18 — forked from mivade/cli.py
Using a decorator to simplify subcommand creation with argparse
from argparse import ArgumentParser
cli = ArgumentParser()
subparsers = cli.add_subparsers(dest="subcommand")
def argument(*name_or_flags, **kwargs):
"""Convenience function to properly format arguments to pass to the
subcommand decorator.
#!/usr/bin/env python3
import collections
import logging
import sys
import os
class ColorizedStreamHandler(logging.StreamHandler):
def __init__(self):
@lamchau
lamchau / date-fns.js
Created August 9, 2020 02:57
example date-fns bundler
import differenceInBusinessDays from 'date-fns/differenceInBusinessDays';
import parse from 'date-fns/parse';
import toDate from 'date-fns/toDate';
export default {
differenceInBusinessDays,
parse,
toDate
};
#!/usr/bin/env bash
if ! command -v inkscape &> /dev/null; then
echo "command 'inkscape' could not be found"
exit 1
fi
height=$1
if [[ "$height" -lt 1 ]]; then
echo "$height must be greater than 0"
(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)