Skip to content

Instantly share code, notes, and snippets.

@thorsummoner
thorsummoner / .gitignore
Last active May 4, 2022 09:49 — forked from cournape/gist:1077528
cython c++ example
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
@thorsummoner
thorsummoner / argparse-no-flags.py
Created April 22, 2016 21:09
argparse with --no-flag options
import argparse
class ActionFlagWithNo(argparse.Action):
"""
Allows a 'no' prefix to disable store_true actions.
For example, --debug will have an additional --no-debug to explicitly disable it.
"""
def __init__(self, opt_name, dest=None, default=True, required=False, help=None):
super(ActionFlagWithNo, self).__init__(
[
@thorsummoner
thorsummoner / pygtk3-acclerator-demo.py
Last active December 18, 2018 01:47
PyGTK3 Accelerator Demo
#!/usr/bin/env python2
import signal
from gi.repository import Gtk
def bind_accelerator(accelerators, widget, accelerator, signal='clicked'):
key, mod = Gtk.accelerator_parse(accelerator)
widget.add_accelerator(signal, accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
@thorsummoner
thorsummoner / RE.txt
Created November 30, 2015 06:01
Oniguruma Regular Expressions Version 5.9.1 2007/09/05
Oniguruma Regular Expressions Version 5.9.1 2007/09/05
syntax: ONIG_SYNTAX_RUBY (default)
1. Syntax elements
\ escape (enable or disable meta character meaning)
| alternation
(...) group
@thorsummoner
thorsummoner / percent.py
Created October 19, 2015 21:53
Example using the '%' (mod) operator to return percent.
import numbers
class Percent(float):
def __mod__(self, other):
"""Override the builtin % to give X * Y / 100.0 """
return self / other * 100.0
if __name__ == '__main__':
from pprint import pprint
pprint(
@thorsummoner
thorsummoner / warppointer.py
Last active October 10, 2015 07:36 — forked from keturn/warppointer.py
xwarppointer python script, updated to be more python, (and pylint passing)
#!/usr/bin/env python
"""Make the X cursor wrap-around.
Adapted from http://appdb.winehq.org/objectManager.php?sClass=version&iId=12599
to work around lack of relative mouse movement http://wiki.winehq.org/Bug6971
for Thief: Dark Shadows (and possibly others)
This version is a little kinder to your CPU than the shell script with
the busy-loop that starts a new process for every pointer query.
"""
@thorsummoner
thorsummoner / keepassx-xclip-adapter.py
Created September 4, 2015 21:11
Use this as a 'custom browser command' to 'open' urls with a copy to the clipboard
python -c "import sys, subprocess; p = subprocess.Popen(['xclip', '-selection', 'clipboard'], stdin=subprocess.PIPE); p.communicate(input=bytes((' '.join(sys.argv[1:]) + '\n').split('http://')[-1]))"
@thorsummoner
thorsummoner / sublime_build_service_respawner.py
Last active August 30, 2015 23:26
SublimeText build service respawner
#!/usr/bin/env python2
#
# LICENSE
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
@thorsummoner
thorsummoner / multiprocessing.py
Last active November 17, 2021 18:30
python multiprocessing example
#!/usr/bin/env python3
""" Example multiprocess based python file
"""
import multiprocessing
import argparse
import itertools
ARGP = argparse.ArgumentParser(
@thorsummoner
thorsummoner / dblhelix
Last active August 29, 2015 14:21
Double helix ascii printer
#!/usr/bin/env python2
"""
Double Helix Text
"""
import argparse
import math
import sys
import time