Skip to content

Instantly share code, notes, and snippets.

Michael Keller mhkeller

  • csv soundsytem, NY Times
  • New York, NY
View GitHub Profile
@mhkeller
mhkeller / throttle.js
Created Apr 17, 2019
Throttle requests
View throttle.js
const sleep = ms => new Promise(f => setTimeout(f, ms));
async function do_things() {
for (const thing of things) {
await Promise.all([
doThing(thing),
sleep(200)
});
}
}
@mhkeller
mhkeller / gist:01f408c1a4e11e0577eb052e35f526bf
Created Mar 23, 2019
use python 2.7 with a node install for node-gyp
View gist:01f408c1a4e11e0577eb052e35f526bf
`npm install --python=python2.7` and `npm config set python python2.7`
@mhkeller
mhkeller / deps.R
Created Mar 20, 2019
Loading some sweet R packages
View deps.R
pkgs <- c("packages")
check <- sapply(pkgs, require, warn.conflicts = TRUE, character.only = TRUE)
if(any(!check)) {
pkgs.missing <- pkgs[!check]
install.packages(pkgs.missing)
check <- sapply(pkgs.missing, require, warn.conflicts = TRUE, character.only = TRUE)
}
rm(pkgs, check)
@mhkeller
mhkeller / index.js
Last active Apr 3, 2019
Basic puppeteer setup
View index.js
const puppeteer = require('puppeteer');
main();
async function main () {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(`https://webpage.com`);
@mhkeller
mhkeller / pg-connect.js
Created Feb 26, 2019
boilerplate connect to database
View pg-connect.js
const { Pool } = require('pg');
const connectionString = require('./connection-string.json');
const pool = new Pool(connectionString);
async function main () {
const x = await pool.query('Select count(*) from my_table');
console.log(x.rows);
}
@mhkeller
mhkeller / wget.js
Created Feb 6, 2019
promisified wget
View wget.js
async function downloadPage (matches) {
for (let match of matches) {
const requestUrl = `tktk`;
const html = await wget(requestUrl);
}
}
async function wget (requestUrl) {
return new Promise((resolve, reject) => {
const cmd = `wget -q -O - '${requestUrl}'`;
@mhkeller
mhkeller / contact.md
Created Dec 17, 2018
Ways to get in touch
View contact.md
View query-to-csv.psql
\copy (SELECT * FROM persons) to 'C:\tmp\persons_client.csv' with (format csv, header)
View wait.js
const wait = ms => new Promise(f => setTimeout(f, ms));
// wait(500)
You can’t perform that action at this time.