Skip to content

Instantly share code, notes, and snippets.

@partap
partap / test_import.mjs
Last active December 14, 2022 01:00
Trying to make postgres interpolate table name and columns with COPY
import postgres from 'postgres'
import { pipeline } from 'node:stream/promises'
import { Readable } from 'node:stream'
// Enter your local values
const connectUrl = 'postgres://user:password@host/db'
const sql = await postgres(connectUrl, { debug: true })
async function importData (tableName, data) {
@partap
partap / gist:4677744
Last active December 11, 2015 23:38
bash: parse number range from command line
#!/bin/bash
xmldebug=0
USAGE="Usage: $0 plateid1 [plateid2 ...]
(plateids can also be a range xxx-yyy)"
if [ "$#" == "0" ]; then
echo "$USAGE"
exit 1
fi
@partap
partap / gist:4588807
Last active December 11, 2015 10:48
Sequential loading with jquery Deferred
// a is a jquery collection
// fn is a function that returns a promise
function loadItems(a, fn) {
var d = $.Deferred();
var next = d.promise();
a.each(function () {
var that = this;
next = next.pipe(function () {