Skip to content

Instantly share code, notes, and snippets.

Josh Goldberg JoshuaKGoldberg

Block or report user

Report or block JoshuaKGoldberg

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
@JoshuaKGoldberg
JoshuaKGoldberg / binary.ts
Last active Aug 6, 2019
Silly Binary Logic in TypeScript's Type System
View binary.ts
type Bit = 0 | 1;
type BitFlip<A> = A extends 0
? 1
: 0;
type BitOr<A, B> = [A, B] extends [0, 0]
? 0
: 1;
@JoshuaKGoldberg
JoshuaKGoldberg / my-esri.js
Created May 2, 2019
Wrapping and exporting an ambient @types module
View my-esri.js
// webpack/assets/javascripts/my-esri
// This file should be in that path 👆 but Gists don't allow subpaths...
// I'm not super sure this works the way I want it to
// In theory, this /// include should only import the types into *this* file's context, not the ambient context
// 🤷
/// <reference path="../../../node_modules/@types/esri/index.d.ts" />
export const Esri = window.Esri;
@JoshuaKGoldberg
JoshuaKGoldberg / esri.d.ts
Last active May 2, 2019
Replacing an incorrect @types definition
View esri.d.ts
// webpack/assets/javascripts/esri.d.ts
// This file should be in that path 👆 but Gists don't allow subpaths...
declare module "esri" {
const wat: string;
export wat;
}
@JoshuaKGoldberg
JoshuaKGoldberg / clipboard-polyfill.d.ts
Last active May 2, 2019
Removing an incorrect @types definition
View clipboard-polyfill.d.ts
// webpack/assets/javascripts/clipboard-polyfill.d.ts
// This file should be in that path 👆 but Gists don't allow subpaths...
// Overrides incorrect types in node_modules/clipboard-polyfill/build/clipboard-polyfill.d.ts
// See https://github.com/lgarron/clipboard-polyfill/issues/106
@JoshuaKGoldberg
JoshuaKGoldberg / LogicMathLol.ts
Last active Aug 5, 2019
Silly Binary Arithmetic in TypeScript's Type System
View LogicMathLol.ts
type Bit = 0 | 1;
type BitOr<A extends Bit, B extends Bit> =
[A, B] extends [0, 0] ? 0 :
[A, B] extends [0, 1] | [1, 0] | [1, 1] ? 1 :
Bit
;
type BitAnd<A extends Bit, B extends Bit> =
[A, B] extends [0, 0] | [1, 0] | [0, 1] ? 0 :
@JoshuaKGoldberg
JoshuaKGoldberg / test-event-emitting.ts
Created Jun 1, 2018
Sample of event listening with selenium-webdriver and squee
View test-event-emitting.ts
import { createEventEmitter, IEventReceiver } from "squee";
import * as Selenium from "selenium-webdriver";
// Put whatever you'd like in this...
interface IPostMessageData {
identifier: string;
}
declare const window: {
__MY_IS_EVENT_DATA_VALID__: (data: any) => data is IPostMessageData;
@JoshuaKGoldberg
JoshuaKGoldberg / download-selenium-drivers.ps1
Last active May 16, 2018
PowerShell script to download major browser WebDriver drivers for Selenium.
View download-selenium-drivers.ps1
[Net.ServicePointManager]::SecurityProtocol = "Ssl3, Tls, Tls11, Tls12";
$currentDir = (Get-Item -Path "./").FullName;
$driversDirName = Join-Path $currentDir ".drivers";
$isWindows = [System.Boolean](Get-CimInstance -ClassName Win32_OperatingSystem -ErrorAction SilentlyContinue);
$webClient = New-Object System.Net.WebClient;
function Ensure-Driver-Exists($browserName, $exeName, $download, $zipName) {
$localExeName = Join-Path $driversDirName $exeName;
if (Test-Path $localExeName) {
@JoshuaKGoldberg
JoshuaKGoldberg / CreateRouteDetails.ts
Last active May 25, 2018
🃏 Unit Tests: SOLID, Modern, Electric Boogaloo 🃏
View CreateRouteDetails.ts
export const createRouteDetails = (lookupId?: string): IRouteDetails => {
if (lookupId === undefined) {
return {
pageMode: PageMode.MySways,
};
}
return {
lookupId,
pageMode: PageMode.Document,
@JoshuaKGoldberg
JoshuaKGoldberg / npm-debug.log
Created Jan 17, 2018
Errors from npm i with an empty package-lock.json
View npm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\jogol\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'i' ]
2 info using npm@5.5.1
3 info using node@v8.8.1
4 verbose npm-session c1cc1bbe74c6487e
5 silly install runPreinstallTopLevelLifecycles
6 silly preinstall electric-boogaloo@0.1.0
7 info lifecycle electric-boogaloo@0.1.0~preinstall: electric-boogaloo@0.1.0
@JoshuaKGoldberg
JoshuaKGoldberg / component.ts
Created Dec 30, 2017
Ridiculously tiny IoC with almost no features
View component.ts
import { IComponentListing } from "./listings";
import { getFunctionName } from "../utils";
export const component = (componentFunction: any, initializer?: Function) => {
const componentFunctionName = getFunctionName(componentFunction);
return initializer === undefined
? createComponentClass(componentFunction, componentFunctionName)
: createComponentInitializer(componentFunction, componentFunctionName, initializer);
};
You can’t perform that action at this time.