Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env node
/**
* Usage:
*
* ./update-env.mjs \
* --KEY=value \
* --KEY2=value \
* --key3="Values with spaces need quotes" \
* --K "The assignment operator after a flag is optional"
@zachsa
zachsa / list-of-curl-options.txt
Created July 25, 2022 08:39 — forked from eneko/list-of-curl-options.txt
List of `curl` options
$ curl --help
Usage: curl [options...] <url>
--abstract-unix-socket <path> Connect via abstract Unix domain socket
--alt-svc <file name> Enable alt-svc with this cache file
--anyauth Pick any authentication method
-a, --append Append to target file when uploading
--basic Use HTTP Basic Authentication
--cacert <file> CA certificate to verify peer against
--capath <dir> CA directory to verify peer against
-E, --cert <certificate[:password]> Client certificate file and password
@zachsa
zachsa / Promise Experiment
Created September 27, 2020 16:28
Looking at the logic of what constitutes a JavaScript promise - I can see that it is a way of separating out callbacks from asynchronous code
function P (cb) {
var _nextFn
var _catchFn
/**
* User registers a callback via
* the 'then()' instance fn
*/
this.then = function (cb) {
_nextFn = cb
ssh-keygen -t rsa -C "email@work_mail.com" -f "id_rsa_work_user1"
@zachsa
zachsa / dataloader-batching-experiment.js
Last active September 23, 2019 06:15
Using graphql/dataloader as a reference, this is an experiment WRT how to implement code that does the same thing, with the same API
function DataLoader (_batchLoadingFn) {
this._timer
this._keys = []
this._batchLoadingFn = _batchLoadingFn
}
DataLoader.prototype.load = function(key) {
clearTimeout(this._timer)
const promisedValue = new Promise ( resolve => this._keys.push({key, resolve}) )
@zachsa
zachsa / pg-cursor iterator example.js
Last active June 23, 2021 20:38
Example of how to create a row iterator using pg-cursor
const createIterator = async sql => {
const client = await pool.connect()
const cursor = client.query(new Cursor(sql))
const batchSize = 100
return (async function getRows(client, cursor, batchSize) {
let done = false
// Get next rows
const rows = await new Promise((resolve, reject) =>
@zachsa
zachsa / React context example.jsx
Created August 27, 2019 11:13
The simplest POC I can think of to use the React Context API
import React, { Component } from 'react'
import { render } from 'react-dom'
import Hello from './Hello'
import './style.css'
const AppContext = React.createContext('app')
const Heading2 = props => (
<AppContext.Consumer>
{ context => (
@zachsa
zachsa / docker-host.sh
Created August 12, 2019 15:33
Create a temp container, and mount the docker host as a volume inside it
// https://nickjanetakis.com/blog/docker-tip-70-gain-access-to-the-mobylinux-vm-on-windows-or-macos
docker container run --rm -it -v /:/host alpine
chroot /host
@zachsa
zachsa / csv-parse-example.js
Created August 7, 2019 08:10
An example of iteratively reading a CSV file using the popular 'csv' library
// https://dev.to/maheshkay/read-csv-file-using-node-js-29oc
const parse = require('csv-parse')
const fs = require('fs')
const { createReadStream } = fs
module.exports = async FILEPATH => {
const contents = []
await new Promise((resolve, reject) => {
createReadStream(FILEPATH)
@zachsa
zachsa / gitlab-gc.sh
Created July 11, 2019 20:28 — forked from pbabics/gitlab-gc.sh
Manual garbage collector for gitlab registry, it removes old revisions that are not referenced by any tag
#!/bin/bash
BASE_PATH=/var/opt/gitlab/gitlab-rails/shared/registry/docker/registry/v2/repositories
DRY_RUN=0
KEEP_LAST_IMAGES=10
RUN_GARBAGE_COLLECTOR=0
GITLAB_CTL_COMMAND=`which gitlab-ctl`