Skip to content

Instantly share code, notes, and snippets.

View andykais's full-sized avatar

Andrew Kaiser andykais

View GitHub Profile
{
"0 debug pnpm:scope": {
"selected": 1,
"workspacePrefix": null
},
"1 debug pnpm": {
"isCaseSensitive": false,
"store": "/Users/andrew/.pnpm-store/2"
},
"2 debug pnpm:package-manifest": {
@andykais
andykais / optional_chaining.py
Last active July 11, 2019 15:56
details two optional chaining methods
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 16:59
A couple of handy timing functions I use often
// 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)
// current design
import ScrapePages from '../src'
import { normalizeConfig } from '../lib/normalize-config'
const config = { scrape: {} }
const options = {
input: {
username: 'bob'
},
optionsEach: {
gallery: {
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
*/
// 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 December 5, 2018 03:54
separate scraper-step definitions from the downloading structure for readability, still will compile down to inline structure: https://gist.github.com/andykais/04a02b61bb3b6d92aa3388c45ea816bd
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'