Skip to content

Instantly share code, notes, and snippets.

@jsonberry
jsonberry / styles.less
Last active February 2, 2017 19:57
Make the active tab in Atom stand out
/*
* Have only your active Atom tab have a different style
*
* In Atom sometimes I open four panes...
* Top LR might correspond to an HTML template for a component,
* Bottom LR would correspond to similar style sheet for those components...
* and each pane might have multiple components.
*
* It can be helpful if Atom styles your active tab differently.
* Here's one way to do that:
@jsonberry
jsonberry / es6_scoped_decl.md
Last active February 13, 2017 19:17
Override const declaration with function scope and let

You can effectively "override" a const if the subsequent declaration is in a nested function scope.

You can also override a const in a block with let, as that will keep the declaration lexically scoped to that block

Example: The JS engine will not allow an override of the const, even though the var is in a nested block scope

function myScopedConst() {
    const myScopedConst = 42;
    console.log('myScopedConst:: before the block ->', myScopedConst);
@jsonberry
jsonberry / hasEmptyProps.js
Last active February 17, 2017 23:38
Data latch utility for JSON using Lodash
/*
Sometimes I pass data into a transformation layer
I always expect the data to be a JSON object
None of the properties of the object should be undefined, null, empty objects, or empty arrays
If any of them are, then eject out of the transformation so the app doesn't have a chance to explode
*/
// How to implement
function transformData(data) {
@jsonberry
jsonberry / javascript-promise-examples.js
Last active March 9, 2017 23:28
Simple Asynchronous JavaScript Promise Example
// TODO
// Add Promise.race example
// Add Promise.all example
// Refactor async simulations to better reflect real-world scenarios
// Refactor so that if the evenOrOdd async work is not wrapped in a Promise that it could cause unexpected behavior sometimes depending on JS Type/Reference errors
function getRandomData() {
return {
number: Math.floor(Math.random() * 10),
timeout: Math.floor(Math.random() * 10000)
}
@jsonberry
jsonberry / breakpoints.sass
Created May 16, 2017 04:22
Breakpoint mixin
=breakpoint($size)
@if $size == phone-only
@media (max-width: 599px)
@content
@else if $size == tablet-portrait-up
@media (min-width: 600px)
@content
@else if $size == tablet-landscape-up
@media (min-width: 900px)
@content
@jsonberry
jsonberry / git_stats.sh
Created May 31, 2017 16:52
Get some git project stats!
#author @StevenIrby
function git-stats() {
git log --shortstat --author="$(git config user.name)" | grep -E "fil(e|es) changed" | awk '{files+=$1; inserted+=$4; deleted+=$6; delta+=$4-$6; ratio=deleted/inserted} END {printf "Commit stats:\n- Files changed (total).. %s\n- Lines added (total).... %s\n- Lines deleted (total).. %s\n- Total lines (delta).... %s\n- Add./Del. ratio (1:n).. 1 : %s\n", files, inserted, deleted, delta, ratio }' -
}
@jsonberry
jsonberry / watcher.js
Created July 7, 2017 16:50
Spawn a new task!
'use strict';
/*
* Run the Metalsmith build upon hbs and json changes
* This enables live reloading of template and data changes
*/
const { watch } = require('fs');
const { spawn: run } = require('child_process');
const { resolve, extname } = require('path');
@jsonberry
jsonberry / word-break-cross-browser.scss
Created October 24, 2017 18:26
Cross / Legacy browser support for word wrapping
.container {
word-wrap: break-word; // works for IE11, IE10
overflow-wrap: break-word; // New naming for word-wrap attribute, keep for possible deprecation of word-wrap
word-break: break-word; // Helps with non English character wrapping, supported by Blink based browsers
.item {
// display: block or inline-block may be required
max-width: 250px;
width: 100%; // Allows for word wrap in IE10/IE11
/// Breakpoints
/// @author Jason Awbrey
/// @param { phone | tablet-portrait | tablet-landscape | desktop | desktop-big } $type [no default]
/// @return { Number } Rem calculated value for a given breakpoint
@function bp($type) {
/// @prop
$breakpoints: (phone: 599, tablet-portrait: 600, tablet-landscape: 900, desktop: 1200, desktop-big: 1800);
@if (map-has-key($breakpoints, $type) != true) {
@error "$type must be one of these: #{map-keys($breakpoints)}";
}
@jsonberry
jsonberry / actions.js
Last active November 9, 2018 21:23
Angular ngrx-router-store Router Actions / Effects
/* tslint:disable:max-classes-per-file */
import {Action} from '@ngrx/store';
import {NavigationExtras} from '@angular/router';
export enum RouterActionTypes {
GO = '[router] Go',
BACK = '[router] Back',
FORWARD = '[router] Forward',
}