Skip to content

Instantly share code, notes, and snippets.

@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,
@jsonberry
jsonberry / onload.js
Last active July 3, 2023 14:10
Window vs. Document Loading Events
/**
Taken from: http://stackoverflow.com/questions/588040/window-onload-vs-document-onload
According to Parsing HTML documents - The end,
The browser parses the HTML source and runs deferred scripts.
A DOMContentLoaded is dispatched at the document when all the HTML has been parsed and have run. The event bubbles to the window.
The browser loads resources (like images) that delay the load event.
A load event is dispatched at the window.
Therefore, the order of execution will be
DOMContentLoaded event listeners of window in the capture phase
DOMContentLoaded event listeners of document
@jsonberry
jsonberry / helpful-javascript-utilities.js
Last active September 20, 2022 01:33
Helpful JavaScript Utilities
// 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 / prot-war-big-guns
Created September 12, 2022 03:24
WoW Shadowlands S4 Protection Warrior Weak Auras
!WA:2!DB1wZTrsv4OA2q8ozzXxI9gNDHOkM1SuaghNefipHghPnkRILZi54KTGvtpZ0sthpAMXDpJKL52gryXCheWYLD5YQkab2auLEHxP8VGtPIk)aYpHu8dGtpJKJDivbl7lu4h009PpN(C7781o11MuOF2fo9clnzJjTN0ENf6s4wfPE1dDU9mpW0NBt5AeRnS5(bbJR5Y2EBc3oDfFF3qwaFRs1QjOHx6VDYZACi8pE7rcAE3t(6OG(eplhF(Q(mVqZLZTsLC69tU1L9D95xovQuk6IaIf9WCIviZ3tKrxes4HQAmpwOQzn8JWrTtiNvVoLloX88HlFJE2uZOA1Q0oGYVuUIRMFTIAH4gDseNSuhra11TGTq9bIitAtQxyzuB2w9RUC2YvQwUsw9kArOtmdCjTPCDpsdQqvpwvZlrjUHo7z6QCkAQE5vZvSy3iVHHGAFlF3OgELLzGIjNyZIe3(z6s8yniYSjd8m5HP0889O7sjcA5qECX9idSXyuQrvzeZfulFpBrhPoY8bMtRbH5H2cZbF0JaVimp8XWLp7JlrN4YQ7bJXXIMmIs1dJyDADzLuvZ1NyNxtW2MoJEJiSLPQHvfRzGfu1TCjcHCLziXfZq5YbMd71jDhffLvvwCHZ1PoNzldRtPFrEsUrD0fwODkMjTtNEjFZzxNgmr5nJiCA68rUUPx3Hfs7XJdj5DSRDBSqZSQZ9JcgAvzmcpSMWNhcZ1RgA1YmULl1OtKGwK1Gf6O7k)C0hI4ik3J4EnSMHx4gpaRByQ7fMhHp(Ct9SxSWALhqIcryxPGyeL6UjEjbB(0dbGf8Wnk9c9TAMCxhpLr1tXSdMoG7hMUfHZz(80MS6PRh5j6kRbRZSdDoA)ACePGTssir5Hji88srY0ZS8Y65YTshUFReuXsrm7(3mJ3vkC5nDxNw2eJ4AS6QAybOvVlvsVWRwALkzlIwegJis1tIfyjHEFMxnFEcysTRG6wlEwcgBsRlSZC9yOQL9J4w0x4qWYQWhifCeyS
@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 / DateComponent.vue
Created October 12, 2021 00:22
Vue Native Platform Date Component Strategy
<template>
<fieldset class="date-input" :data-qa-id="id">
<legend>{{ legend }}</legend>
<component
@change="onChange($event)"
:is="component"
:custom-validity="customValidity"
v-bind="$props"
/>
</fieldset>
@jsonberry
jsonberry / readme.md
Created November 27, 2019 21:51
Injecting Actions Service for profit

Reference to this twitter thread: https://twitter.com/jsonberrry/status/1199566382716731393

Subject: "injecting the actions service into the component level as a means for propagating success/error states to a presentational layer"

Question from @jdpearce

"“Injecting the actions service...” woah, woah, woah...what?!

Why aren’t you setting a property in the store and selecting that?"

@jsonberry
jsonberry / app.component.ts
Last active February 20, 2019 04:25
Reactive Angular Scroll Position Restoration with RxJS
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { Event, NavigationEnd, NavigationStart, Router } from '@angular/router';
import { asyncScheduler } from 'rxjs';
import { filter, observeOn, scan } from 'rxjs/operators';
interface ScrollPositionRestore {
event: Event;
positions: { [K: number]: number };
trigger: 'imperative' | 'popstate';
idToRestore: number;
@jsonberry
jsonberry / ignoreFalsyValues.ts
Last active January 14, 2019 17:01
rxjs-examples
import { someDataSource } from './some-api.service';
import { ignoreFalsySignals, tapLog } from 'rxjs-toolkit';
interface Signal {
foo: string;
}
/**
* signals$ pushes out an Observable of Signal
* imagine the source of the stream is the return from an API call
@jsonberry
jsonberry / propsAreTruthy.ts
Last active January 14, 2019 16:58
rxjs-toolkit examples
import { from } from 'rxjs';
import { propsAreTruthy, tapLog } from 'rxjs-toolkit';
const topLevelTruthy = {
one: 'I',
two: 'am',
three: 'truthy',
iHaveNestedProps: { // top level also truthy
nested: null,
},