Skip to content

Instantly share code, notes, and snippets.

View mhkeller's full-sized avatar

Michael Keller mhkeller

View GitHub Profile
@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;'
}
}
}
@mhkeller
mhkeller / concat.bash
Created October 22, 2018 15:09
Concatenate csv files
# Adapted from https://unix.stackexchange.com/questions/60577/concatenate-multiple-files-with-same-header#170692
# `head -1` gets first line of the file of the file and stashes them as the header row into `all.txt`
# `tail -n +2 -q *.csv >> all.txt` grabs every csv file from the second row down and stashes them into `all.txt`
# `all.txt` is a csv file but we use the txt extension to avoid it being captured in the `*.csv` glob.
# You could also output to a csv file by having your input files share a naming convention such as `file-001.csv` and glob on `file*.csv`
# But renaming `all.txt` to `all.csv` is sometimes easier than worrying about a naming convention and txt and csvs are the same thing
head -1 my-csv-01.csv > all.txt; tail -n +2 -q *.csv >> all.txt