Skip to content

Instantly share code, notes, and snippets.

Jason Awbrey jsonberry

Block or report user

Report or block jsonberry

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jsonberry
jsonberry / helpful-javascript-utilities.js
Last active Apr 30, 2018
Helpful JavaScript Utilities
View helpful-javascript-utilities.js
// zip arrays together
// Catalin Dumitru @colin_dumitru
// Jason Awbrey @jsawbrey
const zip = (a, b) => a.map((n, i) => [n, b[i]])
// merge objects in an array together
// caution: properties are overridden if duplicated
// @a [{a},{b}]
// @returns [{a, b}]
// Jason Awbrey @jsawbrey
@jsonberry
jsonberry / word-break-cross-browser.scss
Created Oct 24, 2017
Cross / Legacy browser support for word wrapping
View word-break-cross-browser.scss
.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
@jsonberry
jsonberry / api.service.js
Last active Oct 5, 2017
Angular: RxJS + Lodash for getting deeply nested data out of an Observable stream and into presentational components
View api.service.js
// .js extension for syntax highlighting - all files are actually .ts
// A general service that makes an HTTP call to an API
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
@Injectable()
export class ApiService {
constructor (
private http: HttpClient,
@jsonberry
jsonberry / watcher.js
Created Jul 7, 2017
Spawn a new task!
View watcher.js
'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 / git_stats.sh
Created May 31, 2017
Get some git project stats!
View git_stats.sh
#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 }' -
}
View breakpoints.sass
=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 / hasEmptyProps.js
Last active Feb 17, 2017
Data latch utility for JSON using Lodash
View hasEmptyProps.js
/*
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 / es6_scoped_decl.md
Last active Feb 13, 2017
Override const declaration with function scope and let
View es6_scoped_decl.md

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 / styles.less
Last active Feb 2, 2017
Make the active tab in Atom stand out
View styles.less
/*
* 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 / purge_branches.sh
Last active Jun 10, 2019
Mass remove local git branches and prune remote tracking
View purge_branches.sh
// List all remotely tracked branches that do not exist in the remote repo
git remote prune origin --dry-run
// Prune all remotely tracked branches that do not exist in the remote repo
git remote prune origin
// List all local branches that were merged into master, explicitly exclude master from that list
git branch --merged master | grep -v 'master'
/*
You can’t perform that action at this time.