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 / 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 / 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)
@jayeye
jayeye / ubox.el
Created August 5, 2017 23:42
Unicode box drawing characters
; Light and heavy solid lines
;
; 2500 ─ BOX DRAWINGS LIGHT HORIZONTAL
; 2501 ━ BOX DRAWINGS HEAVY HORIZONTAL
; 2502 │ BOX DRAWINGS LIGHT VERTICAL
; 2503 ┃ BOX DRAWINGS HEAVY VERTICAL
;
; Light and heavy dashed lines
;
; 2504 ┄ BOX DRAWINGS LIGHT TRIPLE DASH HORIZONTAL
@jayeye
jayeye / vec.cc
Last active January 27, 2018 01:13
Demonstrate how vector<bool> uses much less space than one byte per entry
// * compile without optimization
// * run an inferior shell
// * type limit -d 2048 to restrict the data segment to 2 megs
// * ./a.out
// * profit!
#include <sys/resource.h>
#include <cstdint>
#include <iostream>