Skip to content

Instantly share code, notes, and snippets.

View jamesholcomb's full-sized avatar

James Holcomb jamesholcomb

View GitHub Profile
@jamesholcomb
jamesholcomb / gist:dee325408d68e22bf3491624887757a8
Last active July 8, 2021 19:32
How to move to a fork after cloning? Switch the cloned fork to a new remote origin.
git clone https://github.com/otherusername/some-awesome-repo.git
# make changes, commit as needed
git remote set-url origin https://github.com/myusername/myforkedrepo.git
git push
~done~
@jamesholcomb
jamesholcomb / del-keys
Created March 9, 2021 15:41
The definitive script to remove keys by pattern including spaces from redis on MacOS
redis-cli --scan --pattern "myprefix:*" | tr \\n \\0 | xargs -0 redis-cli unlink
@jamesholcomb
jamesholcomb / script.sh
Last active October 12, 2022 14:17
Code mod to remove // @ts-check from
# recurisvely remove lines containing // @ts-check from all javascript files in current directory
find . -type f -name "*.js" -print0 | xargs -0 sed -i '' -e '/@ts-check/d'
@jamesholcomb
jamesholcomb / codes.js
Created October 31, 2020 16:57
Country codes
export const COUNTRY_CODES = {
AF: "Afghanistan",
AL: "Albania",
DZ: "Algeria",
AS: "American Samoa",
AD: "Andorra",
AO: "Angola",
AI: "Anguilla",
AQ: "Antarctica",
AG: "Antigua and Barbuda",
@jamesholcomb
jamesholcomb / script.sh
Created October 1, 2020 18:46
Bash functions
#!/bash/bin
# Recursively find all occurences of X in all *.js files excluding node_modules
egrep -lir --include=*.js "X" --exclude-dir="node_modules" .
@jamesholcomb
jamesholcomb / deep-merge-example.js
Last active June 30, 2020 16:28
Deep merge with comparator to ensure null/undefined data values are patched
import { mergeWith, isNil } from "lodash"
var existing = {
a: 1,
b: 2,
d: {
a: 1,
b: [],
c: { test1: 123, test2: 321 }
},
@jamesholcomb
jamesholcomb / deep-assign.js
Last active March 2, 2022 15:25
Deeply traverse an object to replace or redact values using a regex and replacer function
export const assignDeep = (input, regex, replacer) => {
const json = JSON.stringify(input)
return JSON.parse(json, (k, v) =>
typeof v === "string" && regex.test(k) ? replacer(v) : v
)
}
export const redactDeep = (input, regex) =>
assignDeep(input, regex, () => "[REDACTED]")
@jamesholcomb
jamesholcomb / script.sh
Last active January 24, 2020 17:18
mongoimport geonames US zip codes
# https://download.geonames.org/export/zip/US.zip
mongoimport -d mydb -c zipcodes \
--columnsHaveTypes --type tsv --file US.txt \
--stopOnError --drop \
--fields="countryCode.string(),postalCode.string(),placeName.string(),adminName1.string(),adminCode1.string(),adminName2.string(),adminCode2.string(),adminName3.string(),adminCode3.string(),latitude.double(),longitude.double(),accuracy.string()"
@jamesholcomb
jamesholcomb / script.sh
Last active September 12, 2019 21:13
Disable fluentd-gcp on a Kubernetes node
# disable stackdriver logging in the cluster
gcloud beta container clusters update [CLUSTER_NAME] --logging-service none
# delete the label on the specific node
kubectl label nodes [NODE_NAME] beta.kubernetes.io/fluentd-ds-ready-
# apply config
kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/kubernetes-engine-customize-fluentd/master/kubernetes/fluentd-configmap.yaml
# apply daemonset
kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/kubernetes-engine-customize-fluentd/master/kubernetes/fluentd-daemonset.yaml
@jamesholcomb
jamesholcomb / ContactsSectionList.js
Created May 21, 2019 14:53
React Native SectionList for contacts
import React, { Component, PureComponent } from "react"
import PropTypes from "prop-types"
import {
StyleSheet,
View,
Text,
ViewPropTypes,
TouchableWithoutFeedback,
SectionList
} from "react-native"