Skip to content

Instantly share code, notes, and snippets.

View benley's full-sized avatar
🐈

Benjamin Staffin benley

🐈
View GitHub Profile
#!/usr/bin/env bash
# Copyright 2016 Postmates Inc.
#
# Author: Benjamin Staffin
#
# Logging library for bash scripts
#
# Features:
# * Nicely formatted messages with timestamp, source file and line number
# * Stack traces on abnormal exits, similar to Python
@benley
benley / jq.BUILD
Created June 21, 2017 20:55
bazel build jq
licenses(["notice"])
cc_binary(
name = "jq",
visibility = ["//visibility:public"],
srcs = glob([
"*.h",
"*.c",
]),
copts = [
abutinniana
achlida
acila
adelin
adrie
aduna
adusto
aima
albria
alisa
@benley
benley / plantnames.txt
Created July 2, 2017 03:22
generated plant names
American Bluet
Anchadeleaf Sunflower
Appalachian Toathlea
Apupamper Milkweed
Arethean Yevile
Arthallia
Beeded Beary
Bellflowel Purtlefon
Bent Lilyius
Betce-Hel Pelil
@benley
benley / bazel.sh
Last active July 13, 2017 16:43
handy dandy bazel-in-docker wrapper
#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
CONTAINER_NAME="bazel-$USER"
IMAGE="bazel-$USER"
function log {
echo "(wrapper) $*" 1>&2
@benley
benley / nvim-client
Created August 14, 2017 05:04 — forked from rf-/nvim-client
#!/usr/bin/env python
import neovim, os, re, sys, time
# Get a list of buffers that haven't been deleted. `nvim.buffers` includes
# buffers that have had `:bdelete` called on them and aren't in the buffer
# list, so we have to filter those out.
def get_listed_buffers(nvim):
return set(buf.number for buf in nvim.buffers \
if nvim.eval('buflisted(%d)' % buf.number))
#!/usr/bin/env python
"""Send desktop notifications when AC power status changes."""
from __future__ import print_function
import dbus
from dbus.mainloop import glib
import gobject
onMessage="Power plugged in!"
@benley
benley / wat
Created October 10, 2017 01:33
Oct 09 21:32:05 alnitak kernel: ------------[ cut here ]------------
Oct 09 21:32:05 alnitak kernel: WARNING: CPU: 0 PID: 0 at /tmp/nix-build-linux-4.13.5.drv-0/linux-4.13.5/net/core/dev.c:5504 net_rx_action+0x237/0x350
Oct 09 21:32:05 alnitak kernel: Modules linked in: snd_usb_audio snd_usbmidi_lib snd_rawmidi snd_seq_device igb ptp thunderbolt pps_core dca nls_utf8 ntfs asix usbnet mii libphy ctr ccm rfcomm af_packet ipt_MASQUERADE nf_nat_masquerade_ipv4 nf_conntrack_netlink nfnetlink xfrm_user xfrm_algo xt_addrtype br_netfilter bridge stp llc cmac bnep msr zram zsmalloc snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic hid_rmi rmi_core 8250_dw i2c_designware_platform i2c_designware_core efi_pstore pstore x86_pkg_temp_thermal intel_powerclamp coretemp crct10dif_pclmul crc32_pclmul ghash_clmulni_intel intel_cstate intel_uncore intel_rapl_perf efivars snd_soc_skl snd_soc_skl_ipc snd_soc_sst_ipc snd_soc_sst_dsp snd_hda_ext_core snd_soc_sst_match tpm_crb hid_multitouch mousedev joydev snd_soc_core
// Helper functions and stuff related to unit conversions
{
// Parse a k8s memory resource value and return it in bytes as an integer
//
// From the Kubernetes API docs:
// > You can express memory as a plain integer or as a fixed-point integer using
// > one of these suffixes: E, P, T, G, M, K. You can also use the power-of-two
// > equivalents: Ei, Pi, Ti, Gi, Mi, Ki.
parseMemory(x)::
def _check_call(repo_ctx, cmd_and_args):
"""
Execute a command with arguments, fail if it returns non-zero.
Similar to subprocess.check_call.
"""
result = repo_ctx.execute(cmd_and_args, timeout=10)
if result.return_code != 0:
fail(("Non-zero return code({1}) when executing '{0}':\n" + "Stdout: {2}\n"
+ "Stderr: {3}").format(" ".join(cmd_and_args), result.return_code,