Skip to content

Instantly share code, notes, and snippets.

def search_operators(str_):
matches = []
for thing in [[x, getattr(int, x).__doc__] for x in dir(int) if x.startswith('__')]:
print((">>>>", (thing[0], thing[1])))
if thing[1] is not None and "<==>" in thing[1]:
print(('<==>', thing[1].split(" <==> ")[::-1]))
if str_ in thing[1]:
matches.append(thing)
print('')
@westurner
westurner / parse_inputrc.py
Last active September 19, 2016 15:19
parse a readline .inputrc file with Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
"""
parse_inputrc -- parse a readline .inputrc file
.. note:: This probably only handles a subset of ``.inputrc`` syntax.
"""
Verifying that +westurner is my blockchain ID. https://onename.com/westurner
@westurner
westurner / loglevels.py
Created February 15, 2016 20:29
loglevels.py: logging._levelNames { (0) NOTSET ; (10) DEBUG ; (20) INFO ; (30) WARN / WARNING ; (40) ERROR ; (50) CRITICAL / FATAL }
#!/usr/bin/env python
from __future__ import print_function
import logging
###
def addLevelName__TRACE():
logging.addLevelName(8, 'TRACE')
###
@westurner
westurner / ordereddefaultdict.py
Created February 12, 2016 22:14
OrderedDefaultDict_.py
#!/usr/bin/env python
"""
ordereddefaultdict.OrderedDefaultDict
.. code:: bash
$ python ./ordereddefaultdict.py -t
$ nosetests ./ordereddefaultdict.py
$ py.test ./ordereddefaultdict.py
# :*_markdown_github[__html]
# :*_markdown_commonmark[__html]
# Markdown[HTML] > MarkdownGithub[HTML]
# Markdown[HTML] > MarkdownCommonmark[HTML]
rdfx:Markdown a rdfs:Datatype ;
.
rdfx:MarkdownGithub a rdfs:Datatype ;
@westurner
westurner / i3t.py
Last active April 26, 2021 15:59
i3wm <alt><tab> alternative
#!/usr/bin/env python
"""
i3t.py -- list i3wm windows, get next window id, wrap/loop around
Configuration (``.i3/config``)::
set $i3t_alt_tab ~/-dotfiles/src/i3t/i3t.py n
set $i3t_alt_shift_tab ~/-dotfiles/src/i3t/i3t.py p
bindsym Mod1+Tab exec exec $i3t_alt_tab
bindsym Mod1+Shift+Tab exec $i3t_alt_shift_tab
#!/bin/sh
## newtab.sh -- newtab(), newwin() functions and osascripts for OSX Terminal
## src: https://stackoverflow.com/questions/7171725/open-new-terminal-tab-from-command-line-mac-os-x/12147804#12147804
## license: Creative Commons cc by-sa 3.0
function newtab {
# newtab() -- Open a new tab in the current Terminal window and
# optionally run a command.
# When invoked via a function named 'newwin', opens a new Terminal *window* instead.
#!/usr/bin/env python
from __future__ import print_function
"""
Print psutil.Process.memory_info for processes with sockets open to
the specified ports.
"""
import psutil
import logging
def net_connection_memory_info(ports=[80, 443]):
@westurner
westurner / Makefile
Last active August 29, 2015 14:08
Given a CSV (TSV), compute aggregations with Pandas and NumPy, then generate an HTML report with Bootstrap, JQuery, jquery.tocify, and floathead
.PHONY: default test
default: test
test:
python ./transaction_charts.py
open:
open ./test.html