Skip to content

Instantly share code, notes, and snippets.

Avatar
📠

Andrew Childs andrewchilds

📠
View GitHub Profile
@andrewchilds
andrewchilds / clientCache.js
Last active Jun 22, 2022
Proposal: A client-side key-value store interface
View clientCache.js
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
@andrewchilds
andrewchilds / getTimezoneOffset.js
Created May 3, 2022
Convert a minute-based timezone offset like `240` to an offset like `"-04:00"`.
View getTimezoneOffset.js
// 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 / deepClone.js
Created Apr 28, 2022
Simple, standalone, vanilla implementation of lodash.cloneDeep
View deepClone.js
// 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 / deepGet.js
Last active Aug 5, 2022 — forked from harish2704/lodash.get.js
Simple, standalone, vanilla implementation of lodash.get
View deepGet.js
// 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 / google-meet-kindergarten-edition.css
Last active Sep 25, 2020
Google Meet: Kindergarten Edition
View google-meet-kindergarten-edition.css
/*
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 / redirect.js
Created Nov 1, 2017
How long does it take to stop JS execution during a location redirect?
View redirect.js
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 / getAgeOfCodebase.sh
Created Jul 3, 2017
Creates a histogram CSV file of the age of every line of code in a directory
View getAgeOfCodebase.sh
#!/bin/bash
set -e
APP_DIR="$1"
TEMP_FILE="codebase-age-histogram.txt"
OUTPUT_FILE="codebase-age-histogram.csv"
pushd $APP_DIR
@andrewchilds
andrewchilds / moving-stories-to-deployed.sh
Last active Aug 4, 2016
Moving Clubhouse Stories to Deployed
View moving-stories-to-deployed.sh
# 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 / extract-stories-from-commits.sh
Last active Aug 4, 2016
Extracting Clubhouse story IDs from a set of git commits
View extract-stories-from-commits.sh
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 / commit-and-branch-formatting-example.sh
Last active Sep 14, 2016
Clubhouse Branch & Commit Formatting Examples
View commit-and-branch-formatting-example.sh
# 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]"