Skip to content

Instantly share code, notes, and snippets.

View kyle-west's full-sized avatar
🍰
Writing code (as always)

Kyle West kyle-west

🍰
Writing code (as always)
View GitHub Profile
@kyle-west
kyle-west / sequential-async-iteration.js
Last active October 3, 2019 19:06
Sequential asynchronous iteration over an array of values (with use of function generators)
// Example of a basic async-callback based pattern
function asyncProcess (value, callback) {
setTimeout(() => {
console.log(value);
callback && callback(value ? null : new Error('Something is broken'))
}, 1000 * Math.random())
}
// use a function generator to map an iterator over the array items
@kyle-west
kyle-west / what-did-i-even-do-yesterday
Last active July 23, 2019 22:20
Go thru all the git logs under the `~/dev` folder and see what commits you logged
usrn=`git config --global user.github-username`
yesterday=`date -v-1d +%F`
if [ "$1" == "--today" ]; then
yesterday=`date +%F`
elif [ "$1" != "" ]; then
yesterday="$1"
fi
if [ "$usrn" == "" ]; then
@kyle-west
kyle-west / debug-chrome-on-ios.js
Last active March 26, 2019 15:18
Debug Chrome on iOS (Tracer Method)
...
// Add this to your app.js
// Listen for console.x events on the front end, and print them in our logging
app.get('/console/:type', (req, res) => {
console[req.params.type](`[REMOTE: console.${req.params.type}]`, req.query)
res.end()
});
@kyle-west
kyle-west / make-release.sh
Last active December 12, 2023 22:42
Keep your `dist` folder in the release packages, but not in version control
# Make sure our master branch is up to date
git checkout master
git pull
# Remove our former release branch
git branch -D lastest-release 2>/dev/null
git push origin --delete lastest-release 2>/dev/null
# Create a new branch to run the build under
git checkout -b lastest-release
@kyle-west
kyle-west / prune
Last active January 15, 2020 15:32
Remove all the Git branches that match a pattern
#!/bin/bash
branches=""
for branch in $@; do
branches="$branches $(git branch | grep -v "master" | grep -v '*' | grep "$branch")";
done;
echo "Prune would permenantly remove the following branches from your machine:";
paste -s -d" " <(echo "$branches");
printf 'Are all these ok to remove? [y/N] : '
read -r yN
@kyle-west
kyle-west / String.prototype.containsUnicode.js
Created February 12, 2019 16:13
String Class Extension for determining if a string has unicode characters or not.
/**
* @method containsUnicode
* @extends {String}
*
* @returns {Boolean} - True iff <String> contains one or more Unicode Characters
*/
String.prototype.containsUnicode = function () {
return this.split('').reduce((a,x)=> a || x.charCodeAt(0) > 255, false)
}
@kyle-west
kyle-west / lang-mv
Created February 4, 2019 15:27
Move string keys from a locale JSON file to another
#!/bin/bash
###########################################################################
# USAGE Example:
# lang-mv from_files to_files key1 key2 key3@KEY_3_NEW_NAME key4
###########################################################################
from_list=$(find . | grep "$1_...json")
echo "Moving ${@:3}..."
@kyle-west
kyle-west / migrate-to
Last active August 9, 2022 14:59
See what components need to update in what order (requires bower)
#!/bin/bash
# bashful import json
target_repo=$1
target_version=$2
echo "Please consider running 'bower install' before running 'migrate-to'"
sleep 3s;
echo;
@kyle-west
kyle-west / Singleton.js
Created September 24, 2018 22:25
Barebones JavaScript Singleton Example Class
const Singleton = (function () {
let instance = null;
class Singleton {
constructor () {
if (instance) return instance;
instance = this;
return this;
}
}
@kyle-west
kyle-west / UncertainValue.py
Created July 19, 2018 21:23
[MATH] Create a value from a random +/- uncertainty which can be treated like a float or integer.
##############################################################################
# @class UncertainValue
# (c) 2018 Kyle West - [email protected]
# MIT License. See: [Licensing Info](https://opensource.org/licenses/MIT)
#
# Create a value from a random +/- uncertainty which can be treated like a
# float or integer.
#
# x = UncertainValue(50, 5) # <--- random sample from 45 to 55.
#