Skip to content

Instantly share code, notes, and snippets.

View jayeye's full-sized avatar

jayeye

View GitHub Profile
@jayeye
jayeye / etherspeed
Created November 1, 2014 06:00
Quick-and-dirty program to show network traffic rate on a mac, updating once a second.
#!/usr/bin/env python2.7
from __future__ import print_function
import subprocess
import time
def netstat():
ifs0 = subprocess.check_output(['/usr/sbin/netstat', '-b', '-i'])
retval = dict()
for i in ifs0.splitlines():
@jayeye
jayeye / fil.py
Last active August 29, 2015 14:17
Convert filament length to filament weight and vice versa
PLA = 1.24
ABS = 1.03
def _normalize_density(d):
"""Density can be specified as g/cm^3 (common way) or kg/m^3 (SI way).
Assumes we are not dealing with degenerate matter!
"""
return (d < 25) and (d * 1000) or d
@jayeye
jayeye / fdtdump__sys_firmware_fdt
Last active May 12, 2016 19:07
I2S microphone input on Pi2/Pi3 woes
/dts-v1/;
// magic: 0xd00dfeed
// totalsize: 0x37b3 (14259)
// off_dt_struct: 0x38
// off_dt_strings: 0x31c0
// off_mem_rsvmap: 0x28
// version: 17
// last_comp_version: 16
// boot_cpuid_phys: 0x0
// size_dt_strings: 0x5f3
@jayeye
jayeye / mkvpc.py
Created September 10, 2016 06:16
Create a vpc with all its accoutrements
#!/usr/bin/env python3
from __future__ import print_function
import boto3
import ipaddress
import sys
import time
ec2 = boto3.client('ec2')
stat("/etc/fonts/fonts.conf", {st_mode=S_IFREG|0644, st_size=2339, ...}) = 0
stat("/etc/fonts/conf.d", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/etc/fonts/conf.d/00kde.conf", {st_mode=S_IFREG|0644, st_size=124, ...}) = 0
stat("/etc/fonts/conf.d/10-antialias.conf", {st_mode=S_IFREG|0644, st_size=223, ...}) = 0
stat("/etc/fonts/conf.d/10-hinting-slight.conf", {st_mode=S_IFREG|0644, st_size=229, ...}) = 0
stat("/etc/fonts/conf.d/10-hinting.conf", {st_mode=S_IFREG|0644, st_size=212, ...}) = 0
stat("/etc/fonts/conf.d/10-scale-bitmap-fonts.conf", {st_mode=S_IFREG|0644, st_size=2010, ...}) = 0
stat("/etc/fonts/conf.d/11-lcdfilter-default.conf", {st_mode=S_IFREG|0644, st_size=526, ...}) = 0
stat("/etc/fonts/conf.d/20-unhint-small-dejavu-lgc-sans-mono.conf", {st_mode=S_IFREG|0644, st_size=874, ...}) = 0
stat("/etc/fonts/conf.d/20-unhint-small-dejavu-lgc-sans.conf", {st_mode=S_IFREG|0644, st_size=864, ...}) = 0
@jayeye
jayeye / README.md
Created October 3, 2016 21:45
Setting up ISC dhclient on debian / ubuntu for prefix delegation

My ISP (Time Warner Cable) hands out IPv6 addresses with DHCPv6; it will delegate a /56 if asked. So long as I keep refreshing the lease, it won't renumber me. I have my cable modem set to bridge, and do all the firewalling, NATing, etc., on a Debian box. In what follows, eth0 is the internal interface.

The dhclient that ships with debian/ubuntu does not support asking for a prefix delegation, so I had to build one from sources.

@jayeye
jayeye / sti.c
Created December 8, 2016 03:31
Save buffers of a detached or otherwise inaccessible emacs process.
#include <err.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <termios.h>
const char* const kJesusSaves = "\025\033xsave-buffers-kill-emacs\n";
int main(int argc, char* argv[]) {
int fd = open(argv[1], O_WRONLY);
if (fd < 0) {
@jayeye
jayeye / gist:01eadaa8b679df6e52152ba02760d6cb
Created April 23, 2017 19:09
Hacky way of breaking out of an inner loop. Definitely better than having a flag and testing it.
class _iloop(Exception):
pass
try:
for i in range(2, 10):
for j in range(2, 10):
if i == j * j:
raise _iloop
print(i, j)
except _iloop:
@jayeye
jayeye / BUILD
Created April 27, 2017 05:00
stamping with build information. Obviously, replace _slash_ in the filenames with an actual slash!
package(default_visibility = ["//visibility:public"])
genrule(
name = "genpybuildinfo",
outs = [
"buildinfo.py",
],
stamp = 1,
cmd = "./$(location tools/mkpybuildinfo.sh) > \"$@\"",
tools = [
@jayeye
jayeye / grediting.el
Last active July 19, 2017 23:20
Emacs Lisp definitions for a Greek keyboard
;; DWIM key bindings when I have switched to a greek keyboard mapping
;; By <ji@tla.org>
;; If you fix something, email me.
(global-set-key (kbd "C-χ") ctl-x-map)
(global-set-key (kbd "M-χ") 'smex)
(global-set-key (kbd "C-α") 'move-beginning-of-line)
(global-set-key (kbd "C-β") 'backward-char)