Skip to content

Instantly share code, notes, and snippets.

@aradnom
aradnom / checkbox-input.html
Created September 30, 2015 22:05
Checkbox input
<div class="checkbox-input">
<input class="checkbox-input__input" id="card-default" name="card-default" type="checkbox" ng-model="creditCard.default">
<label class="checkbox-input__label" for="card-default">Make this my default card</label>
</div>
@aradnom
aradnom / _checkbox-input.sass
Created September 30, 2015 22:07
Checkbox input sass
.checkbox-input
display: block
position: relative
background-color: rgba(#000, 0.2)
border-bottom: 1px solid rgba(#fff, 0.2)
overflow: hidden
&__input
display: none
@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()
@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 / 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 / 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 / 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 / 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 / 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 / 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>