Skip to content

Instantly share code, notes, and snippets.

View issa-tseng's full-sized avatar

issa marie tseng issa-tseng

  • seattle
View GitHub Profile
require('knex')({
client: 'pg',
connection: { host: 'localhost', user: 'jubilant', password: 'jubilant', database: 'jubilant_test' }
}).transaction(async (db) => {
await db.schema.createTable('xyz', (xyz) => {
xyz.increments('id');
});
/* attempt 1
for await (const row of db.select('*').from('xyz').stream())
@issa-tseng
issa-tseng / latent.js
Created August 14, 2019 23:41
a really dumb quick node.js proxy to introduce artificial latency to a local port
// node latent.js fromport toport delay
// where fromport is the port of the service and toport is the port to serve the proxy on
const { createServer, request } = require('http');
const [ , , fromport, toport, delaystr = 1000 ] = process.argv;
const delay = parseInt(delaystr);
createServer((req, res) => {
setTimeout(() => {

Keybase proof

I hereby claim:

  • I am issa-tseng on github.
  • I am cxlt (https://keybase.io/cxlt) on keybase.
  • I have a public key whose fingerprint is 71DC D5D5 1BC9 E6A7 ECF2 7E75 A8CA 5F38 7C55 6C7F

To claim this, I am signing this object:

// Copyright 2017 ODK Central Developers
// See the NOTICE file at the top-level directory of this distribution and at
// https://github.com/opendatakit/central-backend/blob/master/NOTICE.
// This file is part of ODK Central. It is subject to the license terms in
// the LICENSE file found in the top-level directory of this distribution and at
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.
const hparser = require('htmlparser2');
{
"name": "scorebox",
"version": "0.1.0",
"private": true,
"dependencies": {
"livescript": "~1.5.0",
"prelude-ls": "~1.1.2",
"request": "~2.81.0",
"jquery": "~3.2.1",
"jsdom": "~11.1.0"
@issa-tseng
issa-tseng / sorter.js
Last active November 9, 2016 03:22
fivethirtyeight election sorter
// press cmd+option+i (or right-click and select inspect element), go to the console, and paste this in:
(function() {
var value = function(elem) { return ((elem.className.indexOf('close') > 0) ? 1000 : ((elem.className.indexOf('call') > 0) ? -1000 : ((elem.className.indexOf('watch') > 0) ? 1000 : 0))) - $(elem).attr('data-state').charCodeAt(0); };
var dim = function(elem) { if (elem.className.indexOf('call') > 0) $(elem).css('opacity', 0.3); }
var go = function() { var states = $('.sparklines .state').get(); states.sort(function(a, b) { return value(b) - value(a); }); var container = $('.sparklines'); states.forEach(function(elem) { container.append(elem); dim(elem); }); };
window.setInterval(go, 30000);
$('.switch-toggle').click(function() { window.setTimeout(go, 0); });
go();
})();
var fs = require('fs');
var soda = require('soda-js');
var moment = require('moment');
var trim = function(str) { return str.replace(/^\s+|\s+$/g, ''); }
// following is from http://stackoverflow.com/questions/8493195/how-can-i-parse-a-csv-string-with-javascript
function csvToArray(text) {
var re_valid = /^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;
var re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g;
// create a soda producer based on our configuration
var producer = new soda.Producer(update.cname, update.credentials);
// perform the actual insert based on our parse and our configurations
producer.operation()
.withDataset(update.id)
.add(importData)
.on('success', function(result) { console.log('Successfully wrote ' + importData.length + ' rows from ' + update.file + ' to ' + update.id + '.'); })
.on('error', function(error) { console.error('Error writing ' + importData.length + ' rows from ' + update.file + ' to ' + update.id + '!'); });
// iterate through each row of the dataset
for (var j = 0; j < parsedData.length; j++)
{
// create a js key/value hash object
var datum = {};
// fetch the row we're processing
var row = parsedData[j];
// iterate through each column of the row
var fs = require('fs');
var soda = require('soda-js');
var moment = require('moment');
var update = /* some configuration we load in from a local JSON file */;
// read in our csv
fs.readFile(update.file, function(error, data)
{
if (error) { console.error(error); return; }