Skip to content

Instantly share code, notes, and snippets.

View jayphelps's full-sized avatar
💭
I may be slow to respond.

Jay Phelps jayphelps

💭
I may be slow to respond.
View GitHub Profile
@jayphelps
jayphelps / script.sh
Created May 1, 2020 06:56
Add .crt SSL certificate to macOS Keychain via command line
SCRIPT="security add-trusted-cert -d -r trustAsRoot -p ssl -p basic -k /Library/Keychains/System.keychain "filename.crt""
osascript -e "do shell script \"$SCRIPT\" with administrator privileges"
# or you can just run the above SCRIPT command with sudo directly.
# This osascript stuff is so that you get a native OS password prompt
@jayphelps
jayphelps / package.json
Last active March 20, 2024 09:41
TypeScript output es2015, esm (ES Modules), CJS, UMD, UMD + Min + Gzip. Assumes you install typescript (tsc), rollup, uglifyjs either globally or included as devDependencies
{
"scripts": {
"build": "npm run build:es2015 && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
"build:es2015": "tsc --module es2015 --target es2015 --outDir dist/es2015",
"build:esm": "tsc --module es2015 --target es5 --outDir dist/esm",
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs",
"build:umd": "rollup dist/esm/index.js --format umd --name YourLibrary --sourceMap --output dist/umd/yourlibrary.js",
"build:umd:min": "cd dist/umd && uglifyjs --compress --mangle --source-map --screw-ie8 --comments --o yourlibrary.min.js -- yourlibrary.js && gzip yourlibrary.min.js -c > yourlibrary.min.js.gz",
}
}
@jayphelps
jayphelps / batchsampling.js
Last active August 18, 2022 23:27
Batch Sampling Example from my talk, Real-time Insights, powered by Reactive Programming
let buffer = getWebSocket()
.bufferTime(1000);
let gate = new BehaviorSubject(true);
let batchSize = 50;
let batchSizeCounter = 0;
let results = gate
.switchMap(enabled => enabled ? buffer : Observable.never())
.do(buffer => {
@jayphelps
jayphelps / settings.json
Last active March 28, 2022 17:10
Modifications on top of "Community Material Theme Palenight" Before and after: https://twitter.com/_jayphelps/status/1259321038728560642?s=20
// Modify your settings.json to add these. Customize further how you prefer.
{
"workbench.editor.highlightModifiedTabs": true,
"workbench.editor.tabCloseButton": "off",
"workbench.colorCustomizations": {
"editor.lineHighlightBackground": "#ffffff06",
"editor.foreground": "#acb3db",
"selection.background": "#89DDFF",
"progressBar.background": "#89DDFF",
"textLink.foreground": "#89DDFF",
@jayphelps
jayphelps / index.js
Created May 24, 2016 23:47
async window.open()
window.onclick = () => {
// You MUST create the window on the same event
// tick/stack as the user-initiated event (e.g. click callback)
const googleWindow = window.open();
// Do your async work
fakeAjax(response => {
// Change the URL of the window you created once you
// know what the full URL is!
googleWindow.location.replace(`https://google.com?q=${response}`);
@jayphelps
jayphelps / ofPropertyPathChanges.js
Last active June 15, 2021 18:09
RxJS observable of property value changes, given an object and property path
function isObject(value) {
// Avoid an old bug in Chrome 19-20
// See https://code.google.com/p/v8/issues/detail?id=2291
const type = typeof value;
return type === 'function' || (!!value && type === 'object');
}
function ofPropertyChanges(obj, key) {
if (isObject(obj) === false) {
return Rx.Observable.return(undefined);
@jayphelps
jayphelps / redux-observable-typescript-testing-example.ts
Created February 24, 2019 05:33
Example using redux-observable + typescript + TestScheduler, with a run helper written
import { map, delay } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import { Action } from 'redux';
import { Epic, ofType, ActionsObservable, StateObservable } from 'redux-observable';
const scheduler = new TestScheduler((actual, expected) => {
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
throw new Error(`Failing test
actual: ${JSON.stringify(actual, null, 2)}
@jayphelps
jayphelps / resolver.js
Last active September 4, 2020 17:56
Example of using multiple Ember.Namespaces with a custom Ember.Resolver to reuse code between projects. Ember App Kit's resolver as another example: https://github.com/stefanpenner/ember-jj-abrams-resolver DefaultResolver docs: https://github.com/emberjs/ember.js/blob/master/packages/ember-application/lib/system/resolver.js
/**
* Super namespace that all our libs and apps will live on. We also extend all
* of the native Ember classes as well and exclusely use them that way so we can
* alter the behavior in one place without needing to reopen the original class.
*
* We call the super namespace PS for Pivotshare, call it what you'd like.
*/
window.PS = Ember.Namespace.create();
// Create our custom resolver so we can have Ember look up classes on multiple
// The spec might seem somewhat convoluted but it's because you can actually
// use reduce on anything array-like not just arrays.
// e.g. Array.prototype.reduce.call('abc', (acc, char) => char + acc); // "cba"
function reduce(callback, initialValue) {
// In "strict mode" calling this with either null or undefined will make
// this === null in either case, as per spec.
if (this === null) {
throw new TypeError('reduce called on null or undefined');
}
// noprotect
console.clear();
const second = 1;
const minute = second * 60;
const hour = minute * 60;
const day = hour * 24;
const year = day * 365;
const unitValues = [{