Skip to content

Instantly share code, notes, and snippets.

@jaseg
jaseg / gist:5296519
Last active March 23, 2016 10:08
zsh unicode table using only zsnexpn(1) in <140 characters

The following line produces a unicode table (decimal value and unicode characters) using only zsh * expansion, * substitution and the print-builtin.

setopt extendedglob histsubstpattern multibyte
print -ac ${${(A)=u::={5126..5743}}:s/#%(#b)(*)/'${(r:6:m)match[1]}${(#mr:4:)match[1]}'/}

Output:

import struct
def deltaify(list_of_tuples):
return list_of_tuples[0], [ tuple( b-a for a,b in zip(tup1, tup2) ) for tup1, tup2 in zip(list_of_tuples[:-1], list_of_tuples[1:]) ]
smallest_format = lambda num: 'b' if num < 2**7 else 'h' if num < 2**15 else 'i' if num < 2**31 else 'q'
make_format = lambda es: ''.join(smallest_format(e) for e in es)
def pack(list_of_tuples):
offx, deltas = deltaify(list_of_tuples)
import sqlite3
import itertools
import lzma
import threading
import functools
class Stringstore:
def __init__(self, dbfile, max_block_size=262144):
self.db = sqlite3.connect(dbfile)
@jaseg
jaseg / blobstore.py
Last active January 9, 2016 23:32
little python experiment
import pathlib
import itertools
import lzma
import threading
import functools
class Blobstore:
def __init__(self, path, create_if_missing=False, validate=True, blobid_len=4):
p = self._path_obj = pathlib.Path(path)
self._blobid_len, self._fmt_blobid = blobid_len, lambda blobid: ('{:0'+str(self._blobid_len)+'x}').format(blobid)
@jaseg
jaseg / ruby-test.py
Created January 5, 2016 11:44
Fooling around with furigana on a terminal.
#!/usr/bin/env python3
import unicodedata, textwrap
print('\033[38;5;250m ニホンゴ\n\033[0m日本語', end='\n\n')
# I could not find any terminal actually rendering this. urxvt just ignores the escapes, which is kind of sane. gnome terminal et al. print it literally, replacing the \e with a replacement character which looks garbage.
print('foo\033[1\\bar\033[2\\baz\033[0\\fnord', end='\n\n')
FW_TO_HW_MAP = {
@jaseg
jaseg / setkeyboard
Last active January 3, 2016 00:48
My xkb setup
#!/bin/bash
# Remaps [TAB] to mean [ESCAPE] (nice for vim) and properly assigns the "Windows
# key" to MOD4 (nice for the awesome window manager)
# Also, sprinkles some unicode over unused or poorly used keys.
# <LGST> is that key next to left shift that is not found on US keyboards
xkbcomp - $DISPLAY<<EOF
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwertz)"};
xkb_types { include "complete"};
xkb_compat { include "complete"};
@jaseg
jaseg / gist:8314578
Created January 8, 2014 10:14
sed script to put `quoted strings` in text in {braces}

:0;s/`/{/;s/`/}/;t0

Because sed does more than just s///

@jaseg
jaseg / README.md
Last active December 14, 2015 11:08
Greet your shell users like they were Kim Jong-il!

Put the following line in /etc/profile and put the attached titles file in /etc/.

echo Welcome `id -un`, `sort -R</etc/titles|head -n 1`!

The next time someone logs in, there will be an appropriate greeting:

/home/jaseg
&lt;3 ssh kim@my-awesome-server.example.net
@jaseg
jaseg / article-style.css
Last active November 20, 2015 00:30
Goldendict style sheet for use with JMdict/EPWing dictionaries
body
{
/* font-family: Sazanami Mincho; */
font-family: Source Han Sans JP;
font-weight: 100;
font-size: 16px;
}
h3
{
# Modified cd that also displays the directory's contents if the listing is less than 5 lines long
function cd
if test -n "$argv"
if test -e $argv -a ! -d (realpath $argv)
set argv (dirname $argv)
end
end
builtin cd $argv
and test (ls -C -w $COLUMNS |wc -l) -le 5; and ls
end