Skip to content

Instantly share code, notes, and snippets.

View assaf's full-sized avatar

Assaf Arkin assaf

View GitHub Profile
@assaf
assaf / nvmish
Created March 24, 2015 15:43
nvm use <package.json>
#!/usr/bin/env bash
#
# Run nvmish in your current project directory to use the version of io.js/Node
# as specified in package.json. It will also install that version, if not
# already installed.
#
# If package.json specifies engines.iojs, uses the corresponding version of
# io.js, otherwise, if package.json specifies engines.node, uses the
# corresponding version of Node.js.
#
@assaf
assaf / stream.ts
Last active December 23, 2022 03:54
Read status updates from Mastodon streaming API
type StreamEvent =
| { event: "update"; status: Status }
| { event: "status.update"; status: Status }
| { event: "delete"; id: string; status?: never };
/**
* Use like this:
* const { events } = await stream(`https://${instance}/api/v1/streaming/public`);
* for await (const { id, status } of events) {
* if (status) … do something …
@assaf
assaf / gist:ebd81856ca725f080c52
Created November 11, 2014 20:24
Zero downtime deploy with Dokku (original blog post)

Dokku is a wonderful tool for quickly deploying apps to production, but it's missing zero downtime deploys. Not anymore!

Even our svelte Node.js app needs a few seconds to fully load the main code, and open connections to back-ends servers, before it can start handling requests.

The thing with Dokku: it switches traffic over to the new container before the server loads complete, so each deploy has several seconds of downtime.

That's best case scenario. When we screw deployment (usually some configuration issue that's different in production), even the quickest hands in the west, you still get a few minutes of downtime.

And so it became necessary that I learn how to catch and handle exceptions in Bash (yay, traps!) and shift a few lines of code around.

@assaf
assaf / truncate.test.ts
Created December 11, 2020 01:39
Truncate long strings, but don't break in middle of a short word
import truncate from "./truncate";
describe("Truncate string", () => {
test("empty string returns self", () => expect(truncate("")).toBe(""));
test("short string returns self", () => {
expect(truncate("word", 8)).toBe("word");
expect(truncate("too long", 8)).toBe("too long");
});
@assaf
assaf / deploy.sh
Created February 16, 2012 00:02
Deploy using chef-solo
# Run command(s) over SSH
run() {
ssh deploy@${HOST} -t $* || exit 1
}
# Transfer all the specified files/directories to working directory
upload() {
tar czf - $* | ssh deploy@${HOST} tar xzf - -C /etc/chef || exit 1
}
@assaf
assaf / .vimrc
Created May 21, 2013 19:50
.vimrc
version 7.0
if &cp | set nocp | endif
let s:cpo_save=&cpo
set cpo&vim
let &cpo=s:cpo_save
unlet s:cpo_save
set cscopeprg=/usr/bin/cscope
set cscopetag
set cscopeverbose
set fileencodings=utf-8,latin1
@assaf
assaf / .inputrc
Created May 21, 2013 19:46
.inputrc
set horizontal-scroll-mode off
set mark-modified-lines on
"\C-J": menu-complete
"\C-r": redraw-current-line
# By default up/down are bound to previous-history
# and next-history respectively. The following does the
# same but gives the extra functionality where if you
# type any text (or more accurately, if there is any text
# between the start of the line and the cursor),
@assaf
assaf / .bashrc
Created May 21, 2013 19:45
.bashrc
# ----------------------------------------------------------------------
# SHELL OPTIONS
# ----------------------------------------------------------------------
# notify of bg job completion immediately
set -o notify
# Prevents history expansion, so commit -m "Yay!" will work.
set +o histexpand
# Warn when trying to overwrite file.
set -o noclobber
@assaf
assaf / gist:2002956
Created March 8, 2012 19:47
.gitignore
*.swp
*~
*.DS_Store
.svn
tags
CVS/
@assaf
assaf / gist:2002917
Created March 8, 2012 19:40
.gitconfig
[color]
branch = auto
diff = auto
status = auto
sh = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]