Skip to content

Instantly share code, notes, and snippets.

Nathan Rajlich TooTallNate

Block or report user

Report or block TooTallNate

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View add.sh
add() {
expr "$1" + "$2"
}
@TooTallNate
TooTallNate / test.sh
Created Aug 15, 2018
Running `shakedown` HTTP unit tests through `import`
View test.sh
#!/usr/bin/env bash
eval "`curl -sfLS import.pw`"
import "import.pw/robwhitby/shakedown" # load the framework
shakedown GET /foo # make a GET request
status 404 # assert on http status code
content_type 'text/html' # assert Content-Type header contains string
contains 'Not found' # assert body contains string
matches 'No.*' # assert body matches regex
@TooTallNate
TooTallNate / test.sh
Created Aug 14, 2018
Running `shunit2` shell script tests through `import`
View test.sh
#!/bin/sh
testEquality() {
assertEquals 1 2
}
# Load shUnit2.
eval "`curl -sfLS import.pw`"
import "import.pw/kward/shunit2"
@TooTallNate
TooTallNate / Dockerfile
Created Jul 17, 2018
Node.js + Dockerfile
View Dockerfile
# This is the "base image" which contains Alpine Linux and Node.js v10.x.x preinstalled
FROM mhart/alpine-node:10
# Use the `NPM_TOKEN` build arg to create the `~/.npmrc` file
ARG NPM_TOKEN
RUN echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
# Set the working direcrory to `/usr/src`
WORKDIR /usr/src
@TooTallNate
TooTallNate / add.sh
Created Jun 23, 2018
Basic "add" function for bash, for demonstration purposes
View add.sh
add() {
echo "$(( $1 + $2 ))"
}
@TooTallNate
TooTallNate / jsfunc.sh
Created Jun 20, 2018
Write JavaScript functions - use as bash functions
View jsfunc.sh
#!/bin/bash
jsfunc() {
local code="$(cat)"
local fn="$(cat <<EOFF
$1() {
node <(cat <<EOF
require('stream').Readable.prototype.then = function (...args) { return new Promise((res, rej) => { const bufs = []; this.on('error', rej).on('data', buf => bufs.push(buf)).on('end', () => res(Buffer.concat(bufs))); }).then(...args) };
(async () => {
${code}
})().then(val => typeof val !== 'undefined' && console.log(typeof val === 'string' ? val : JSON.stringify(val, null, 2))).catch(err => console.error(err.stack) || process.exit(1));
@TooTallNate
TooTallNate / config.js
Last active Aug 4, 2017
Ghost config.js file for the official Docker image
View config.js
// # Ghost Configuration
// Setup your Ghost install for deployment to Zeit Now.sh.
// This is a stripped down version of the default `config-example.js`
// file with only a single ("production") environment for simplicity.
// Full documentation can be found at http://support.ghost.org/config/
var path = require('path');
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);
}
You can’t perform that action at this time.