Skip to content

Instantly share code, notes, and snippets.

@nikcorg
nikcorg / tabkill.sh
Created June 14, 2014 22:22
Kill all Chrome tabs (except apps)
tabkill () {
ps ux | \
grep '[C]hrome Helper --type=renderer' | \
grep -vi "Canary" | \
grep -v extension-process | \
tr -s ' ' | \
cut -d ' ' -f2 | \
xargs kill
}
@nikcorg
nikcorg / sw.js
Last active August 29, 2015 14:06
Immediately returning response
this.addEventListener('fetch', function(event) {
var cachedResponse = caches.match(event.request).catch(function() {
return event.default().then(function(response) {
// With the assumption that this is an async operation...
// (who reads specs anyway, and besides it's returning a promise)
// ...store the response to the cache in parallel.
caches.get('v1').then(function(cache) {
cache.put(event.request, response.clone());
});
@nikcorg
nikcorg / README.md
Last active August 29, 2015 14:08
Docked MongoDB helpers

Some scripts for working with Boot2Docker and the Docker mongodb image (https://registry.hub.docker.com/u/dockerfile/mongodb/)

The scripts

mongo-cli.sh opens an interactive mongo shell

mongo-restore.sh will fetch a zip, unpack it and mongorestore a contained dump

prompt.sh will open an interactive shell in the running docker instance

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@nikcorg
nikcorg / blabla.js
Created December 10, 2014 12:15
testing 1...2...3
alert("hello world!");
@nikcorg
nikcorg / rot13.js
Last active August 29, 2015 14:11
ROT-13
String.prototype.map = function (fn) {
var input = this;
function step(acc, i, idx) {
return acc + fn(i, idx, input);
}
return Array.prototype.reduce.call(this, step, "");
};
@nikcorg
nikcorg / update-git-helpers.sh
Last active August 29, 2015 14:13
Git helper scripts updater
#!/bin/bash
# Usage: simply run the script,
# add -q for message suppression
# add -qq for all output suppression
# If you plan to run this script using cron and you feel unsure of
# your cron environment, uncomment the line below and edit the path
#HOME="<path to your home directory here>"
@nikcorg
nikcorg / ssh-complete.bash
Last active August 29, 2015 14:15
Tab completion for Host entries in `~/.ssh/config`
_find_all_ssh_hosts() {
grep "^Host " ~/.ssh/config | cut -d " " -f 2 | sort | uniq
}
_find_ssh_host() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
@nikcorg
nikcorg / index.html
Last active August 29, 2015 14:25
Tab key in Textarea
<!DOCTYPE html>
<html>
<head>
<title>Tab in form</title>
</head>
<body>
<form>
<textarea rows="15" cols="82">lorem ipsum
dolor sit amet
@nikcorg
nikcorg / lambda-bundle.sh
Last active August 29, 2015 14:25
Compile a self-contained bundle for use in AWS Lambda
#!/usr/bin/env bash
ERR_BROWSERIFY_NOT_FOUND=1
ERR_SOURCE_NOT_FOUND=2
AWS_STDLIBS="aws-sdk dynamodb-doc"
err_exit()
{
if [ "x$2" != "x" ]; then