Skip to content

Instantly share code, notes, and snippets.

git() {
if [ "$1" = "add" -o "$1" = "stage" ]; then
if [ "$2" = "." ]; then
echo H4sIAG8APmcAA7VWO27kOBDNdQqCCd0AxXQJEtgLOGAHTpQRAoPNCphTbDgD2DvAAL5cn2RfUWqJkqiPZ7FEuyEV69X3VbUf//z9wOfjp8B5PF8es3R+HJ/KT6GwkImtuLivWT/RXTnY026eTz/KdH4U0o3s/fHxffys43tfybPNj19L6YT/vOhlobt2sadfJLYsweRiXYsy6XNlIcSiYrsN3JqocWBM4XOr21TszGlv6nUlmY3yfjK7ducu7upue4OugA1lxtXsl4QoEefqB6lUaLap9ld0m4LbCKZ4ni4+RfFYaHw/UR2TKN5rajWDpfyKbiPWp5rrsbS+DK9wfmmiKG09qNO1UGFffbNd2CPT1cTAItz3Wu2WLDwcwUtrac3ywuR6LP57QNUxOCvXer7mUtXjqQ/zz6Mhv7IxjlHLqzLiCvsPh3QpPZ//ff1SXIzpNqD/7fzZ/Iaz+Ca1ia3+vTiV1cKZL2KjlJFweiPf9NfAuo3S3IK3LjFetRfh2piojFKiTfeXW7LBdmQdSy8l3pLt26ehW6IQrFOOvIidvWYCuJ4MvnFuAXhrSQlHwQgh8RcvZKKFjDKxBWsDH6RhSQgXLHnDGt7r/syMThkrx8ORwIrLZmwg4x1BkM7MSAmt0CMY3baCMRyMM3hUo+nOhvuZmcTec1VQGzaTS+OccO4EKqUwSMX2FJXS2nP0XAmGXuiITsly4XWLflrGIWIP7JnfjO1fAH272bsDkA+LL2FbKXV88UG+pkAD7jIWnl+1kgbch76asHQJK0Yc8mS/LjNGFVjuQKnuaTjG5OKg4EOk4Fr+AjiTVoOYOZgosgWTfAYosTkOsXr+4gA8g5OekwOcOERfjx+4AS2VcdRwH9QzYjcOBNBSKIRhtmDcEtv2OWd153z41YR7piGGmtN
/**
* Converts a timestamp into a human-readable "time since" string
* @param timestamp - Date string or Date object
* @returns Human-readable duration string
*/
export function getTimeSince(timestamp: string | Date): string {
const date =
typeof timestamp === "string" ? new Date(timestamp) : timestamp;
const now = new Date();
const diffMs = now.getTime() - date.getTime();
@kthwaite
kthwaite / h.js
Created September 21, 2021 13:19
function h()
function h() {
const sel = arguments[0];
const tag = sel.match(/^[^\.#]+/)[0].trim();
// WONTFIX: i should handle tag === '', but instead i'll just avoid
// doing that, ha ha
const e = document.createElement(tag);
let classes = sel.match(/\.[^\.#]+/g);
if (classes != null) {
classes = classes.map((c) => c.slice(1));
e.classList.add(...classes);
/**
* Extract and data from the DOM in JSON format.
* @param selector {string} - Selector to query.
* @param extractor {function} - Operation to apply to each DOM element.
* @param filename {string}
*/
function selectorToJson(selector, extractor, filename) {
const elements = document.querySelectorAll(selector);
const data = Array.from(elements).map(extractor);
if(filename == null) {
#[macro_export]
macro_rules! associated_idx_type {
($base_type: ty, $id_type :ident) => {
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct $id_type(pub usize);
impl ops::Index<$id_type> for Vec<$base_type> {
type Output = $base_type;
fn index(&self, index: $id_type) -> &$base_type {
@kthwaite
kthwaite / async_execute_batch.py
Created August 15, 2018 08:44
aiopg execute_batch implementation
# coding: utf-8
'''Async implementation of psycopg2.extras.execute_batch, for use with aiopg.
async with aiopg.connect(...) as conn:
async with conn.cursor() as cur:
await execute_batch(cur, 'SELECT ...', args)
'''
def _paginate(seq, page_size):
'''Consume an iterable and return it in chunks.
@kthwaite
kthwaite / list_psql_columns.sql
Created June 15, 2018 19:27
list columns of PostgreSQL tables inc. primary keys and foreign key relationships
SELECT
c.table_catalog,
t.table_schema,
t.table_name,
c.column_name,
c.ordinal_position,
c.data_type,
c.udt_name,
c.character_maximum_length,
c.numeric_precision,
@kthwaite
kthwaite / postgres-cheatsheet.md
Created January 11, 2018 16:26 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@kthwaite
kthwaite / new_email_outlook.scpt
Last active July 31, 2017 13:03
Create and send an email in Outlook with Applescript
tell application "Microsoft Outlook"
set theContent to "Mail Content"
-- substitute 'plain text content' for 'content' if you don't want to use HTML
set theMessage to make new outgoing message with properties {subject:"Mail Subject", content:theContent}
make new recipient with properties {email address:{address:"[email protected]"}} at end of to recipients of theMessage
-- recipient type can be 'to recipient', 'cc recipient' or 'bcc recipient'
make new recipient with properties {email address:{address:"[email protected]"}} at end of cc recipients of theMessage
-- optionally open the message instead...
-- open theMessage
send theMessage