Skip to content

Instantly share code, notes, and snippets.

View nilium's full-sized avatar
🍉
internal screaming intensifies

Noel nilium

🍉
internal screaming intensifies
View GitHub Profile
#!/usr/bin/env sh
# TROUBLESHOOTING:
# If /bin/echo doesn't exist _and_ echo -n doesn't work, then this
# script fails. A more graceful fallback to not dropping the trailing
# newline in pipes would also work, but this hasn't been necessary yet.
usage () { cat <<'EOF' 1>&2
lsowners [OPTIONS] [--] [DIRS...]
@nilium
nilium / slackmsg
Last active February 21, 2017 20:26
Shell script to send Slack messages over its incoming webhooks
#!/usr/bin/env sh
usage () {
cat 1>&2 <<ENDUSAGE
Usage: slackmsg [OPTIONS] -t<URL> [--] MESSAGE
Options:
-t|--target URL The Slack URL to send a message to. (required)
-d|--dry-run Print the payload and curl request only.
-i|--stdin Read the MESSAGE from standard input.
@nilium
nilium / lsdep
Last active March 10, 2017 18:32
Quick bash script to list Go package dependencies outside the stdlib
#!/usr/bin/env bash
# Usage: lsdep [PACKAGE...]
#
# Example (list github.com/foo/bar and package dir deps [the . argument])
# $ lsdep github.com/foo/bar .
#
# By default, this will list dependencies (imports), test imports, and test
# dependencies (imports made by test imports). You can recurse further by
# setting TESTIMPORTS to an integer greater than one, or to skip test
# dependencies, set TESTIMPORTS to 0 or a negative integer.
@nilium
nilium / cd-vendor.sh
Last active January 24, 2017 20:14
Vendor cd functions for why did I do this
# To be sourced in either zsh or bash
# cdv works better if you use zsh and cd is synonymous with pushd
# vendor_subpath looks for any vendor directory in the current directory and in any directory above it. If found, it
# will search that directory first for an exact match and then the shortest inexact match for the path given (arg 1).
#
# E.g., vendor_subpath foo/bar will search first for an exact vendor/foo/bar directory. If none is found, it will then
# try to find vendor/*foo/bar* and pick the shortest.
vendor_subpath () {
(
// Copyright 2016 Noel Cower. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// at the end of the file.
// This file is intended to demonstrate writing a general-purpose HTTP handler
// where the input and output are known to be JSON, follow a particular error
// convention, and so on. It falls apart in particular with GET requests where
// request bodies are uncommon, at best.
//
// The responder handlers mimic gRPC's error code/response format, but does not
@nilium
nilium / stamp.vim
Created November 21, 2016 23:03
Stamp-over-word mapping / command
" Stamp
" Maps S (shift+s) to replace the current word under the cursor with whatever's
" in the given (or default) register.
function! s:Stamp(reg)
if a:reg == ""
let a:reg = v:register
endif
execute "let l:v = @" . a:reg
exec "norm! viw\"" . a:reg . "p"
@nilium
nilium / concurrency.go
Last active May 3, 2016 22:41 — forked from kevinburke/concurrency.go
Helping kevinburke
package main
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
@nilium
nilium / git-lab
Last active October 15, 2015 19:38
GitLab CLI tool (early days) — making it just because all the other CLI tools are apparently not intended for humans
#!/usr/bin/env bash
export API="${API:-$(git config gitlab.endpoint)}"
export TOKEN="${TOKEN:-$(git config gitlab.token)}"
export API="${API%*/}"
export self="${BASH_SOURCE[0]}"
if [[ -z "$API" ]] || [[ -z "$TOKEN" ]] ; then
cat <<-EOF 1>&2
API and TOKEN environment variables must be set, or you need to
@nilium
nilium / git-wordiness
Last active November 17, 2016 18:53
Pipe all commit messages per-author through wc and such to get wordiness by user.
#!/bin/bash
set_order () {
local oarg="$1"
case "$oarg" in
commits|c)
order=1
;;
lines|l)
order=2
type glogWriter func(...interface{})
func (fn glogWriter) Write(d []byte) (n int, err error) {
n = len(d)
if fn != nil {
fn(string(d))
}
return n, err
}