Skip to content

Instantly share code, notes, and snippets.

@lamchau
lamchau / smartsheet.user.js
Last active Sep 4, 2021
Due to how smartsheet handles seat licensing when publishing 'read only' reports they add CSS/JS to prevent selection of text or right-clicking on the page. This seems too restrictive so using this script in conjunction with Tampermonkey should enable this behavior again.
View smartsheet.user.js
// ==UserScript==
// @name Smartsheet - Enable text selection and context menu clicks
// @version 1.1
// @author lamchau
// @description Enables text selection and context menu clicks from published Smartsheets
// @updateUrl https://go/smartsheet-hack
// @match https://app.smartsheet.com/b/publish?*
// @icon https://www.google.com/s2/favicons?domain=smartsheet.com
// @run-at document-end
// ==/UserScript==
View vd_dateutil.py
from typing import Union, Callable
import types
# 3p libraries
from dateutil.relativedelta import relativedelta # type: ignore
from visidata import Sheet, Column, SettableColumn, asyncthread, vd # type: ignore
import pandas as pd # type: ignore
def get_frequency(column: Column,
View extract-urls-google-docs.js
/**
* 1. [If not owner] Create a copy of the Google Documents link
* 2. Publish to web
* 3. [Chrome] Inspect page
* 4. Open Developer Console
* 5. Paste script below
* 6. From clipboard, paste to $EDITOR
* 7. Optional: Open multiple URLs Chrome extension
* - https://chrome.google.com/webstore/detail/open-multiple-urls/oifijhaokejakekmnjmphonojcfkpbbh
*/
View download-prs.py
#!/usr/bin/env python3
import argparse
import datetime
import json
import logging
import os
import re
import requests
import sys
@lamchau
lamchau / prune-stale-branches.sh
Created Jun 23, 2021
Prune remote stale and merged branches that are >= 1 year old
View prune-stale-branches.sh
#!/usr/bin/env bash
# used to execute branch deletes in parallel, shows progress bar
if ! [ -x "$(command -v parallel)" ]; then
echo "ERROR: Missing command 'parallel'"
exit 1
fi
if ! [ -x "$(command -v git)" ]; then
echo "ERROR: Missing command 'git'"
@lamchau
lamchau / mark-private.js
Created Jun 9, 2021
https://replit.it - mark all public REPLs as private
View mark-private.js
Array.from(document.querySelectorAll('svg.globe-svg-icon'))
.map(x => x.parentNode.click());
View medium-clapper-bookmarklet.js
const triggerMouseEvent = (node, eventType) => {
const clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent(eventType, true, true);
node.dispatchEvent(clickEvent);
};
const clapButton = document.querySelector('[aria-label="clap"]').parentNode;
const click = button => {
triggerMouseEvent(button, 'mousedown');
triggerMouseEvent(button, 'mouseup');
};
@lamchau
lamchau / uptime.fish
Created Apr 30, 2021
human readable uptime (osx)
View uptime.fish
#!/usr/bin/env fish
set -l boottime_in_seconds (sysctl -n kern.boottime | rg '(?:\bsec\s+=\s+)(\d+)' --replace '$1' --only-matching)
set -l now_in_seconds (date +%s)
set -l seconds_elapsed (math $now_in_seconds - $boottime_in_seconds)
set -l uptime (awk -v seconds_elapsed=$seconds_elapsed '
BEGIN {
ONE_HOUR_IN_SECONDS = int(60 * 60);
ONE_DAY_IN_SECONDS = int(24 * ONE_HOUR_IN_SECONDS);
ONE_WEEK_IN_SECONDS = int(7 * ONE_DAY_IN_SECONDS);
View uk.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lamchau
lamchau / README.rst
Last active Sep 19, 2021
[Chrome/Tampermonky] Extract *.user.js scripts from LevelDB backup
View README.rst

Restoring Tampermonkey scripts

Chrome stores .user.js scripts in a .ldb, which isn't in a user accessible format to recovery. On some versions of macOS the provided python script can't compile the leveldb package. As a workaround, we can use the node level package to recover our userscripts.

Prerequisite