Skip to content

Instantly share code, notes, and snippets.

Avatar

jayeye

View GitHub Profile
View kl.json
[
{
"name": "Stick",
"author": "JI",
"switchMount": "cherry",
"switchBrand": "cherry",
"switchType": "MX1A-L1Nx",
"pcb": true
},
[
@jayeye
jayeye / README
Created Mar 11, 2018
Run chrome in its own memory-limited cgroup
View README
Ugly hack to run chrome in a memory-limited cgroup so it does not kill your workstation
when it tries to consume all available memory.
Put this in /usr/local/bin/cchrome, add that to whatever menu system you are using.
You can verify it worked by running:
grep memory `ps ax | grep chrome | grep -v grep | awk '{printf "/proc/%s/cgroup\n", $1}'`
This has only been tested on kubuntu desktop. Obviously, if you have not enabled
passwordless-sudo for yourself, create and chmod the cgroup directory from some
@jayeye
jayeye / clocks.c
Created Feb 27, 2018
demonstrate high-res timers
View clocks.c
#include <stdio.h>
#include <time.h>
const int kSamples = 16;
int main(int argc, char* argv[]) {
struct timespec t[kSamples];
for (int i = 0; i < kSamples; ++i) {
clock_gettime(CLOCK_REALTIME, &t[i]);
}
@jayeye
jayeye / vec.cc
Last active Jan 27, 2018
Demonstrate how vector<bool> uses much less space than one byte per entry
View vec.cc
// * 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>
@jayeye
jayeye / ubox.el
Created Aug 5, 2017
Unicode box drawing characters
View ubox.el
; 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 / grediting.el
Last active Jul 19, 2017
Emacs Lisp definitions for a Greek keyboard
View grediting.el
;; 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 / BUILD
Created Apr 27, 2017
stamping with build information. Obviously, replace _slash_ in the filenames with an actual slash!
View BUILD
package(default_visibility = ["//visibility:public"])
genrule(
name = "genpybuildinfo",
outs = [
"buildinfo.py",
],
stamp = 1,
cmd = "./$(location tools/mkpybuildinfo.sh) > \"$@\"",
tools = [
@jayeye
jayeye / gist:01eadaa8b679df6e52152ba02760d6cb
Created Apr 23, 2017
Hacky way of breaking out of an inner loop. Definitely better than having a flag and testing it.
View gist:01eadaa8b679df6e52152ba02760d6cb
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 / sti.c
Created Dec 8, 2016
Save buffers of a detached or otherwise inaccessible emacs process.
View sti.c
#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 / README.md
Created Oct 3, 2016
Setting up ISC dhclient on debian / ubuntu for prefix delegation
View README.md

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.