Skip to content

Instantly share code, notes, and snippets.

@aradnom
aradnom / kubernetes-shortcuts.sh
Last active November 10, 2023 17:28
Shell functions and aliases for common things I do with kubectl (Kubernetes, K8s)
###############################################################################
# Kubernetes Shortcuts ########################################################
###############################################################################
# Shell functions and aliases for common things I do with kubectl (Kubernetes,
# K8s)
#
# A lot of the below makes the following assumptions:
# - That you have separate staging and production clusters or a similar
# arrangement
@aradnom
aradnom / slug-to-display.js
Created April 9, 2018 23:06
Simple function for converting a slugified value to display text.
/**
* Converts passed slug to capitalized display value. Not super clever, just
* intended to deal with lowercase, dashed slugs. Ex.: bananas-in-pajamas -->
* Bananas In Pajamas
*
* @param {String} slug Slug to convert to display text
*
* @return {String} Returns formatted text
*/
function slugToDisplay ( slug ) {
@aradnom
aradnom / multiline-tag-regex
Created March 29, 2018 20:08
Regex for grabbing everything between a multiline tag. I always forget the multiline bit and have to futz with it until I find it again, so this time I'm writing it down.
<Tag>(.|\s)*?</Tag>
@aradnom
aradnom / replace-function-calls-regex.txt
Created October 17, 2017 23:14
Simple regex for replacing pre-ES6-style functions with ES6-style functions
Find: function \((\s)?(.*)(\s)?\) {
Replace: ($1$2$3) => {
@aradnom
aradnom / getPhoneNumberComponents.js
Last active March 24, 2017 22:04
Parse phone number components from a string, string manipulation flavor. Tends to be more bulletproof than regex flavor.
/**
* Given a raw phone number, parse out individual components.
*
* @param {String} raw Raw phone number to parse
*
* @return {Object} Returns object containing countryCode, areaCode, officeCode
* and stationNumber components
*/
function getPhoneNumberComponents ( raw ) {
// First cut raw string down to just numbers
@aradnom
aradnom / parse-phone-number.js
Created March 24, 2017 21:29
Parse a phone number with regex. May take some finessing with a few formats, but will attempt to parse country code, area code and number.
/(\d{1,3})?(\s|-|\.)?\(?(\d{3})?\)?(\s|-|\.)?(\d{3})(\s|-|\.)?(\d{4})/.exec( string );
@aradnom
aradnom / localstorage-size.js
Created September 14, 2016 19:02
How much junk you got in localStorage? Useful for figuring out how close you're getting to the localStorage cap.
/**
* Return total byte size of all current keys in localStorage. Based on
* UTF-8 encoding for byte size, so not guaranteed to be accurate in
* other encodings.
*/
localStorage.__proto__.size = function () {
return Object.keys( this )
.map( function ( key ) {
return ( new TextEncoder( 'utf-8' ).encode( localStorage[ key ] ) ).length;
})
@aradnom
aradnom / hide-desktop-icons.sh
Created March 1, 2016 00:13
Hide/show desktop icons on OS X
# Hide icons
defaults write com.apple.finder CreateDesktop -bool false && killall Finder
# Show icons
defaults write com.apple.finder CreateDesktop -bool true && killall Finder
@aradnom
aradnom / move-timezones.js
Created February 25, 2016 18:53
Move timestamp from one timezone to another with moment.js
moment.tz( 'US/Eastern' ).set({ hours: moment().hours() });
@aradnom
aradnom / splitCardNumber.js
Created October 9, 2015 21:41
Splits passed credit number into quartets (groups of 4 digits).
/**
* Split a credit card into groups of four for more readable display.
*
* @param {Integer} number Number to split
*
* @return {String} Returns formatted number for display
*/
function splitCardNumber ( number ) {
return number
.toString()