Skip to content

Instantly share code, notes, and snippets.

View mhkeller's full-sized avatar

Michael Keller mhkeller

View GitHub Profile
@mhkeller
mhkeller / index.js
Last active May 1, 2019 14:03
Basic puppeteer setup
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`, { waitUntil: 'load' });
@mhkeller
mhkeller / pg-connect.js
Created February 26, 2019 22:16
boilerplate connect to database
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 February 6, 2019 22:23
promisified wget
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 December 17, 2018 18:55
Ways to get in touch
\copy (SELECT * FROM persons) to 'C:\tmp\persons_client.csv' with (format csv, header)
const wait = ms => new Promise(f => setTimeout(f, ms));
// wait(500)
@mhkeller
mhkeller / README.md
Created November 18, 2018 18:22 — forked from jstcki/README.md
Polylinear Time Scale

When creating a polylinear time scale, the tricky part is to know to which value in the range the intermediate dates should map.

Let's say we want to "zoom in" on 4 particular days and make them appear with the size of 10 days each. Because these days now take up more space (36 or (factor - 1) * n), we need to create a linear time scale where the domain ends at 36 days later than we want to show. This scale is then used to determine the intermediary range values of the polylinear scale.

@mhkeller
mhkeller / _db.js
Last active November 3, 2018 04:02
Basic node-pg connection setup
import { Pool } from 'pg';
export default function db (connectionString) {
const pool = new Pool(connectionString);
pool.on('error', err => {
console.error(err);
});
return pool;
<h1 style="opacity: 0.25;{color}">Hello {name}!</h1>
<script>
export default {
data () {
return {
color: 'color: #fc0;'
}
}
}