Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Rajlich TooTallNate

View GitHub Profile
View gist:f53a012c24b6a85f22e629c3263007c3
/home/nowuser $ env
SHLVL=7
HOME=/home/nowuser
NOW=1
TEMP=/tmp
TERM=xterm-256color
PATH=/home/nowuser/src/node_modules/.bin:/home/nowuser/bin://usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/node_modules/@zeit/ace/build/node_modules/.bin
DEPLOYMENT_ID=<redacted>
AUTH_TOKEN=<redacted>
PWD=/home/nowuser
@TooTallNate
TooTallNate / updater.sh
Last active May 23, 2019
Google Domains Dynamic DNS record update script - syncs a host to a target (pseudo-ALIAS)
View updater.sh
#!/usr/bin/env sh
#
# Usage:
# USERNAME=abcd12345 PASSWORD=ghij67890 HOST=n8.io TARGET=alias.zeit.co ./updater.sh
URL="https://domains.google.com/nic/update"
HOST_IP=$(dig @8.8.8.8 +short A "$HOST" | sort | tail -1)
TARGET_IP=$(dig @8.8.8.8 +short A "$TARGET" | sort | tail -1)
@TooTallNate
TooTallNate / http-error.js
Created Aug 3, 2016
HTTPError class for JavaScript HTTP errors
View http-error.js
import { format } from 'url';
import { STATUS_CODES } from 'http';
import uppercamelcase from 'uppercamelcase';
class HTTPError extends Error {
constructor(code, message, extras) {
super(message || STATUS_CODES[code]);
if (arguments.length >= 3 && extras) {
Object.assign(this, extras);
}
View deferred-promise-use-case.js
// These theoretical API requests are deferred promises;
// Not executed until `.then()` is invoked.
let a = new Request('/foo');
let b = new Request('/bar');
let c = new Request('/baz');
// If invoked directly, then issue 3 direct HTTP requests:
Promise.all([ a, b, b ]).then((results) => {
// GET /foo
// GET /bar
@TooTallNate
TooTallNate / example.js
Created Mar 29, 2016
LazyPromise implementation. Doesn't invoke the executor function until `.then()` is called.
View example.js
'use strict';
const Lazy = require('./lazy-promise');
class TimerPromise extends Lazy(Promise) {
constructor() {
const start = new Date();
super((resolve, reject) => resolve(new Date() - start));
}
}
@TooTallNate
TooTallNate / pbedit.sh
Created Mar 18, 2016
`pbedit` command: Edit the clipboard in your $EDITOR
View pbedit.sh
# Edit the clipboard in your $EDITOR
# Add this to your `.bashrc` file
function pbedit () {
local tmpfile=`mktemp`
pbpaste > $tmpfile
$EDITOR $tmpfile
pbcopy < $tmpfile
rm -f $tmpmfile
}
export -f pbedit
@TooTallNate
TooTallNate / install.sh
Created Jan 13, 2016
Install Node.js one-liner
View install.sh
curl https://nodejs.org/dist/v4.2.4/node-v4.2.4-linux-x64.tar.gz | tar xzvf - --exclude CHANGELOG.md --exclude LICENSE --exclude README.md --strip-components 1 -C /usr/local/
@TooTallNate
TooTallNate / MatchIterator.js
Created Nov 16, 2015
for (let match of /foo/g.exec('foo bar baz')) console.log(match);
View MatchIterator.js
function *MatchIterator (string, regexp, match) {
if (match) yield match;
match = regexp.exec(string);
while (match != null) {
yield match;
match = regexp.exec(string);
}
};
module.exports = MatchIterator;
@TooTallNate
TooTallNate / line-iterator.js
Last active Jul 4, 2016
ES6 String iterator that parses line-by-line off of \n
View line-iterator.js
'use strict';
function *LineIterator (str) {
let pos = 0;
let delimiter = '\n';
while (true) {
let index = str.indexOf(delimiter, pos);
if (index === -1) break;
yield str.substring(pos, index);
pos = index + delimiter.length;
View screen_info.js
const fs = require('fs');
const ffi = require('ffi');
const ref = require('ref');
const Struct = require('ref-struct');
const ArrayType = require('ref-array');
const ioctl = ffi.ForeignFunction(
ffi.DynamicLibrary().get('ioctl'),
'int', ['int', 'int', 'void*']
);
You can’t perform that action at this time.