Skip to content

Instantly share code, notes, and snippets.

@tswaters
tswaters / git-subdirectory-tracking.md
Last active October 30, 2024 12:55
Adding subdirectory of a remote repo to a subdirectory in local repo

This is way more complicated than it should be. The following conditions need to be met :

  1. need to be able to track and merge in upstream changes
  2. don't want remote commit messages in master
  3. only interested in sub-directory of another repo
  4. needs to go in a subdirectory in my repo.

In this particular case, I'm interested in bringing in the 'default' template of jsdoc as a sub-directory in my project so I could potentially make changes to the markup it genereates while also being able to update from upstream if there are changes. Ideally their template should be a separate repo added to jsdoc via a submodule -- this way I could fork it and things would be much easier.... but, it is what it is.

After much struggling with git, subtree and git-subtree, I ended up finding this http://archive.h2ik.co/2011/03/having-fun-with-git-subtree/ -- it basically sets up separate branches from tracking remote, the particular sub-directory, and uses git subtree contrib module to pull it all togther. Following are

@tswaters
tswaters / stubbing-classes.md
Last active June 18, 2024 12:47
stubbing classes?

Stubbing Classes and their Constructors in Native ES6

It's getting to that point. All the major evergreen browsers have (mostly) functional class keyword. But what does this mean for unit tests and the ability to stub constructors? In short, the answer is 'no'.

Many will tell you that es6 classes are just sugar coated es5 functions with prototypal inheritance setup. Mostly true - but there are two considerations that make testing more difficult:

  • super is a magical keyword that calls the same method on the parent class. in cases with methods, easy enough to stub those, sinon.stub(parent.prototype, 'whatever') -- for super itself, there is no way to stub out the constructor call... normally not a huge deal, but...

  • classes are not added to the global scope. where once you could call sinon.stub(global, 'SomeFunction'), sinon.stub(global, 'SomeClass') (or under window in the browser), this will throw an error.

@tswaters
tswaters / .dockerignore
Last active October 10, 2022 22:57
node dockerfile
.git
node_modules
dist
public
@tswaters
tswaters / ddl.sql
Created August 31, 2022 21:33
crud operations using json_to_recordset
CREATE TABLE _table (
pk SERIAL PRIMARY KEY,
field1 TEXT,
field2 TEXT,
date_deleted TIMESTAMPTZ
);
@tswaters
tswaters / index.html
Created December 4, 2021 03:27
HOW TO: center text
<!DOCTYPE html>
<html>
<head>
<title>How to center text</title>
<meta charset="utf-8" />
</head>
<body>
<table style="width: 100%; height: 100%; position:absolute;">
<tr>
<td valign="middle" align="center">
@tswaters
tswaters / game-of-life.mjs
Created December 13, 2020 00:05
Terminal game of life
import readline from 'readline'
const w = process.stdout.columns
const h = process.stdout.rows
const init = () => Array.from({ length: w * h }).map(() => Math.round(Math.random()))
let state = init()
const deindex = (i) => [i % w, Math.floor(i / w)]
'use strict'
// error-prone work function
const _work = (name, failure_rate) => (thing) =>
new Promise((resolve, reject) => {
setTimeout(() => {
if (Math.random() < failure_rate) {
console.log(`${name} failed - ${JSON.stringify(thing)}`)
reject(new Error(`${name} hit above ${failure_rate}`))
} else {
@tswaters
tswaters / postgres-policy.sql
Last active February 7, 2020 05:08
postgres policy
SET SESSION app.id TO DEFAULT;
SET ROLE postgres;
SET search_path = 'public';
DROP TABLE IF EXISTS expenses CASCADE;
DROP TABLE IF EXISTS projects CASCADE;
DROP TABLE IF EXISTS users CASCADE;
CREATE TABLE users (
user_name text PRIMARY KEY NOT NULL,
### Keybase proof
I hereby claim:
* I am tswaters on github.
* I am tswaters (https://keybase.io/tswaters) on keybase.
* I have a public key ASAm_89GCHVXoI95zX9hNRCPpZH-qf9RlS2mR4qQBBHWOgo
To claim this, I am signing this object:
@tswaters
tswaters / bench.js
Last active September 13, 2019 05:49
seneca-web-adapter-express bench
'use strict'
const { runMain, show } = require('bench')
const express = require('express');
const Seneca = require('seneca');
const SenecaWeb = require('seneca-web');
const adapter = require('..');
const Request = require('request')