Skip to content

Instantly share code, notes, and snippets.

Avatar

David Alsh alshdavid

View GitHub Profile
View http-client.ts
export interface IHTTPClient {
request(requset: Request): Promise<Response>
}
export class HTTPClient implements IHTTPClient {
private _fetch: window['fetch']
constructor(
fetch: window['fetch']
) {
View readme.md
@alshdavid
alshdavid / inject.js
Last active Jun 24, 2021
romsie.com paginator and downloader
View inject.js
(async () => {
document.body.head = ''
const second = 1000
const minute = second * 60
const hour = minute * 60
const day = hour * 24
const linkCache = {
set(page, value) {
View placement-response.json
{
"pageContext": {
"roktTagId": "roktTagId",
"pageInstanceGuid": "pageInstanceGuid",
"pageId": "pageId"
},
"placements": [
{
"plugin": {
"targetElementSelector": "body",
View dependency-container.ts
export type Token = string | Symbol
export enum DependencyContainerErrors {
NoDependencyWithToken = 'NoDependencyWithToken'
}
export class DependencyContainer {
private _dependencies: Map<Token, any> = new Map()
public provide(token: Token, dependency: any): void {
View observable.ts
export type Callback<T extends Array<any> = [], U = void> = (...args: T) => U
export interface Subscriber<T> {
subscribe(
value: Callback<[T], any>,
error?: Callback<[unknown], any>,
complete?: Callback<[], any>
): Unsubscriber
}
View Reactive.1.2kb.js
const Reactive={};(()=>{const e="[[ReactiveState]]",t=e=>{e.o.n();for(const r of e.c)t(r)},r=(e,t,r)=>Array.isArray(t)?s(e,t,r):o(e,t,r),s=(e,r,n)=>new Proxy(r,{get:(t,r)=>Array.isArray(t[r])?s(e,t[r],n):"object"==typeof t[r]?o(e,t[r],n):t[r],set:(e,r,s)=>e[r]===s||(e[r]=s,t(n),!0)}),o=(r,n,i)=>{const c={};for(const f in n)if(f!==e&&"toJSON"!==f){if(n[f][e])n[f][e].c.push(i);else if(Array.isArray(n[f]))n[f]=s(r,n[f],i);else if("object"==typeof n[f])n[f]=o(r,n[f],i);else if(i.p.includes(f))continue;c[f]=n[f],Object.defineProperty(n,f,{enumerable:!0,get:()=>c[f],set:e=>c[f]===e||(c[f]=e,t(i),!0)}),i.p.push(f)}return n};Reactive.observe=((t,r,s=[])=>{const o=[];for(const e of s)o.push(e());const n=t[e].o.s(()=>{if(0!==s.length)for(let e=0;e<s.length;e++){const n=s[e]();if(o[e]!==n)return o[e]=n,void r(t)}else r(t)});return()=>n.u()}),Reactive.create=(t=>{if(t[e])return r(t,t,t[e]);const s={o:new class{constructor(){this._s=[]}s(e){return this._s.push(e),{u:()=>this._ss=this._s.filter(t=>t!==e)}}n(e){for(const t
View mock-interface.ts
export type MatcherFn<T> = (actualValue: T) => boolean;
export interface CalledWithMock<T, Y extends Array<any>> extends jest.Mock<T, Y> {
calledWith: (...args: Y) => jest.Mock<T, Y>;
}
export type MockedInterface<T> = {
[K in keyof T]: T[K] extends (...args: infer A) => infer B
? CalledWithMock<B, A> & T[K]
: MockedInterface<T[K]> & T[K];
View basic.test.ts
import puppeteer from 'puppeteer-core'
import express from 'express'
import * as http from 'http'
let browser: puppeteer.Browser
let app: express.Application
let server: http.Server
beforeAll(async () => {
// Open browser up using chrome installed on the machine
View basic.test.ts
import puppeteer from 'puppeteer-core'
import express from 'express'
import * as http from 'http'
let browser: puppeteer.Browser
let app: express.Application
let server: http.Server
beforeAll(async () => {
// Open browser up using chrome installed on the machine