Skip to content

Instantly share code, notes, and snippets.

@andrewchilds
andrewchilds / commit-and-branch-formatting-example.sh
Last active September 14, 2016 17:42
Clubhouse Branch & Commit Formatting Examples
# Associate a branch with story 123:
git checkout -b ac/ch123/my-story-name
# Or, you might want to associate a single commit with story 123:
git commit -m "Fix bug [ch234]"
@andrewchilds
andrewchilds / extract-stories-from-commits.sh
Last active August 4, 2016 19:43
Extracting Clubhouse story IDs from a set of git commits
old_sha="87d4fed"
new_sha="2d5b22d"
git log $old_sha..$new_sha --oneline
# 2d5b22d Merge pull request #6 from company/me/ch345/my-story-name
# e730351 Fix bug
# c410ba0 Fix other bug [ch1004]
function clubhouse_find_stories_in_commit_range {
old_sha="$1"
@andrewchilds
andrewchilds / moving-stories-to-deployed.sh
Last active August 4, 2016 19:42
Moving Clubhouse Stories to Deployed
# Define the range of commits in this deploy.
old_sha="87d4fed"
new_sha="2d5b22d"
# Define a comment to be posted to each story.
deploy_id="v1.1234"
deploy_url="https://github.com/company/repo/compare/$old_sha...$new_sha"
comment="This story was deployed as part of $deploy_id.$deploy_url"
# Move stories to deployed and post a comment.
@andrewchilds
andrewchilds / getAgeOfCodebase.sh
Created July 3, 2017 14:59
Creates a histogram CSV file of the age of every line of code in a directory
#!/bin/bash
set -e
APP_DIR="$1"
TEMP_FILE="codebase-age-histogram.txt"
OUTPUT_FILE="codebase-age-histogram.csv"
pushd $APP_DIR
@andrewchilds
andrewchilds / redirect.js
Created November 1, 2017 19:47
How long does it take to stop JS execution during a location redirect?
for (var i = 0; i < 1000; i++) {
logAndRedirect(i);
}
window.location.href = window.location.href;
function logAndRedirect(i) {
setTimeout(function () {
window.console.log(i);
}, i);
@andrewchilds
andrewchilds / google-meet-kindergarten-edition.css
Last active September 25, 2020 02:25
Google Meet: Kindergarten Edition
/*
This is a quick attempt to make Google Meet work better for someone in Kindergarten
(one in particular - it may or may not work for yours).
Requirements:
- I used the "Stylebot" extension to make this CSS work, but any other related extension should also work.
Changes:
- Hides the "who's here" rotating carousel which is distracting.
@andrewchilds
andrewchilds / deepGet.js
Last active January 11, 2023 22:38 — forked from harish2704/lodash.get.js
Simple, standalone, vanilla implementation of lodash.get
// Simple implementation of lodash.get
// Handles arrays, objects, and any nested combination of the two.
// Also handles undefined as a valid value - see test case for details.
// Based on: https://gist.github.com/harish2704/d0ee530e6ee75bad6fd30c98e5ad9dab
export function deepGet(obj, query, defaultVal) {
query = Array.isArray(query) ? query : query.replace(/(\[(\d)\])/g, '.$2').replace(/^\./, '').split('.');
if (!(query[0] in obj)) {
return defaultVal;
}
obj = obj[query[0]];
@andrewchilds
andrewchilds / deepClone.js
Created April 28, 2022 01:07
Simple, standalone, vanilla implementation of lodash.cloneDeep
// Simple implementation of lodash.cloneDeep
// Does not clone functions or handle recursive references.
export function deepClone(original) {
if (original instanceof RegExp) {
return new RegExp(original);
} else if (original instanceof Date) {
return new Date(original.getTime());
} else if (Array.isArray(original)) {
return original.map(deepClone);
} else if (typeof original === 'object' && original !== null) {
@andrewchilds
andrewchilds / getTimezoneOffset.js
Created May 3, 2022 18:37
Convert a minute-based timezone offset like `240` to an offset like `"-04:00"`.
// Converts a getTimezoneOffset() offset to one that can be used in new Date().
// Examples:
// Eastern Standard Time: 240 -> '-04:00'
// India Standard Time: -330 -> '+05:30'
// Australian Central Western Standard Time: -525 -> '+08:45'
export function getTimezoneOffset(d) {
return convertTimezoneOffset(d.getTimezoneOffset());
}
export function convertTimezoneOffset(offset) {
@andrewchilds
andrewchilds / clientCache.js
Last active June 22, 2022 18:12
Proposal: A client-side key-value store interface
const tableName = 'crayons';
const crayons = [
{ id: 1, color: 'blue', updated_at: new Date('2022-02-10T11:31:25-0500') },
{ id: 2, color: 'black', updated_at: new Date('2022-02-10T11:31:25-0500') },
{ id: 3, color: 'brown', updated_at: new Date('2022-02-10T11:31:25-0500') },
{ id: 4, color: 'green', updated_at: new Date('2022-02-10T11:31:25-0500') },
];
// Upsert multiple entries to a table, returning number of rows changed