Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Kaiser andykais

View GitHub Profile
View pnpm-debug.log
{
"0 debug pnpm:scope": {
"selected": 1,
"workspacePrefix": null
},
"1 debug pnpm": {
"isCaseSensitive": false,
"store": "/Users/andrew/.pnpm-store/2"
},
"2 debug pnpm:package-manifest": {
View api-extractor.test.md
View api-extractor.test.md
@andykais
andykais / optional_chaining.py
Last active Jul 11, 2019
details two optional chaining methods
View optional_chaining.py
empty = None
deep = dict(a=dict(b='c'))
def chain_optional(func, default_value=None):
try:
return func()
except AttributeError:
return default_value
except TypeError:
@andykais
andykais / timing-utils.js
Created May 16, 2019
A couple of handy timing functions I use often
View timing-utils.js
// async
const timeout = n => new Promise(resolve => setTimeout(resolve, n))
// sync
const sleep = n => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n)
// async
const scheduleAsync = startAtEpoch => async fn => {
const now = Date.now()
const millisecondsTillStartAt = startAtEpoch - now
await timeout(millisecondsTillStartAt)
View api-proposal.js
// current design
import ScrapePages from '../src'
import { normalizeConfig } from '../lib/normalize-config'
const config = { scrape: {} }
const options = {
input: {
username: 'bob'
},
optionsEach: {
gallery: {
View example-log-transport.js
import * as Rx from 'rxjs'
import * as ops from 'rxjs/operators'
import fs from 'fs'
import VError from 'verror'
/**
* for now, there can only be one transport at a time
* the cli will have to handle an option to directly log to terminal while also including a
* "terminal ui" output default (progress bars, queued, in progress, completed, etc)
* this can be accomplished by log options being done directly as command line args
*/
View placeholder magic.js
// index.js
const objectPath = Symbol("object-path");
const objectCrawler = Symbol("object-crawler");
const handler = {
get: (object, prop) => {
if (prop === objectPath) {
return object[objectPath];
} else if (String(prop) === "Symbol(util.inspect.custom)") {
return object;
@andykais
andykais / example-defs-scraper.config.yml
Created Dec 5, 2018
separate scraper-step definitions from the downloading structure for readability, still will compile down to inline structure: https://gist.github.com/andykais/04a02b61bb3b6d92aa3388c45ea816bd
View example-defs-scraper.config.yml
input: 'username'
defs:
- name: 'home'
download: 'https://ifunny.co/user/{{ username }}'
parse:
name: 'batch-id'
selector: '.stream__item:first-child'
attribute: 'data-next'
- name: 'gallery'