Skip to content

Instantly share code, notes, and snippets.

@tetrapus
tetrapus / rison.py
Created April 25, 2018 12:28
Simple python rison encoder
""" Simple RISON encoder. """
import re
def encode(obj) -> str:
""" Encode an object to a RISON string. """
# Objects
if isinstance(obj, dict):
return "({})".format(
@tetrapus
tetrapus / color-tabs.css
Last active July 2, 2018 13:20
Coloured tabs for TST
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
/* override base tab color */
:root:root {
--color-100: white;
}
/* Plain */
.tabbrowser-tab {
--color-main: var(--color-100);
@tetrapus
tetrapus / rawrabilities.py
Created January 6, 2014 21:36
Xchat script that does randomy things.
import xchat
import time
import re
import random
__module_name__ = "Rwarrr"
__module_version__ = "1.21"
__module_description__ = "Rawrabilities."
__module_author__ = "Lion"
query = sql.execute("SELECT DISTINCT name, prefix FROM commands ORDER BY name")
commands = {}
for key, value in query.fetchall():
if key in commands:
commands[key] += [value]
else:
commands[key] = [value]
commands = ["".join("\x03%.2d%s" % ([14, 12][i % 2], p) for i, p in enumerate(sorted(v))) + "\x0f" + k for k, v in sorted(commands.items())]
@tetrapus
tetrapus / gist:8078969
Created December 22, 2013 06:03
Competition: Reconstruct the image from the gcc output. Compiled with no options.
png.c:1:1: error: stray ‘\211’ in program
png.c:2:1: error: stray ‘\32’ in program
png.c:3:1: warning: null character(s) ignored [enabled by default]
png.c:1:2: error: unknown type name ‘PNG’
png.c:4:5: warning: null character(s) ignored [enabled by default]
png.c:4:1: error: stray ‘\226’ in program
png.c:4:9: warning: null character(s) ignored [enabled by default]
png.c:4:1: error: stray ‘\226’ in program
png.c:4:1: error: stray ‘\10’ in program
png.c:4:1: error: stray ‘\6’ in program
@tetrapus
tetrapus / reversedir.py
Created September 26, 2013 09:44
One line python script to recursively reverse filenames (but not extensions) in a directory.
(lambda p, f: [[__import__(str.join(str(),[chr(R+111) for R in (0,4)])).rename(chr(47).join((d,i)),chr(47).join((d,"%s.%s"%(str.join(chr(46),i.split(chr(46))[:-1])[::-1],i.split(chr(46))[-1])))) for i in F]+[__import__(str.join(str(),[chr(R+111) for R in (0,4)])).rename(chr(47).join((d,i)),chr(47).join([d,i[::-1]])) for i in D]+[f("%s/%s"%(d,i[::-1]),f) for i in D] for d,D,F in __import__(str.join(str(),(chr(R+111) for R in (0,4)))).walk(p)])(raw_input("gimme a directory\n"),(lambda p, f: [[__import__(str.join(str(),[chr(R+111) for R in (0, 4)])).rename(chr(47).join([d, i]), chr(47).join([d, "%s.%s"%(str.join(chr(46), i.split(chr(46))[:-1])[::-1], i.split(chr(46))[-1])])) for i in F] + [__import__(str.join(str(),[chr(R+111) for R in (0, 4)])).rename(chr(47).join([d, i]), chr(47).join([d, i[::-1]])) for i in D] + [f("%s/%s"%(d, i[::-1]), f) for i in D] for d, D, F in __import__(str.join(str(),[chr(R+111) for R in (0, 4)])).walk(p)]))
import random
e_ish = []
for i in range(10000):
e = []
while sum(e) < 1:
e.append(random.random())
e_ish.append(len(e))
print(sum(e_ish)/len(e_ish))