Skip to content

Instantly share code, notes, and snippets.

@jsonberry
jsonberry / functions.php
Created August 11, 2016 17:46
Update WordPress Site and Home URL via functions.php
<?php
// When migrating a site the siteurl and home url need to be adjusted
// Add these two update functions to functions.php...
// ..Load the site up...
// ..Verify that everything is working correctly..
// ..Then remove these functions from functions.php
update_option( 'siteurl', 'http://localhost:8888' ); // Be sure Replace the parameter with the correct url
update_option( 'home', 'http://localhost:8888' );
@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 / purge_branches.sh
Last active August 8, 2022 14:42
Mass remove local git branches and prune remote tracking
// 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'
/*
@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 / 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 / api.service.js
Last active August 31, 2023 08:45
Angular: RxJS + Lodash for getting deeply nested data out of an Observable stream and into presentational components
// .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,