Last active
January 1, 2016 14:49
-
-
Save tynn/8160190 to your computer and use it in GitHub Desktop.
Python Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gi.repository import Gtk | |
window = Gtk.Window() | |
window.connect('delete-event', Gtk.main_quit) | |
window.show() | |
Gtk.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from distutils.command import build_scripts | |
_basename = lambda path : os.path.splitext(_basename(path))[0] | |
class build_scripts_noext (build_scripts.build_scripts) : | |
def copy_scripts (self) : | |
_basename_ = os.path.basename | |
os.path.basename = _basename | |
build_scripts.build_scripts.copy_scripts(self) | |
os.path.basename = _basename_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from distutils.command import install | |
_noegg = lambda (key, _) : key != 'install_egg_info' | |
class install_noegg (install.install) : | |
sub_commands = list(filter(_noegg, install.install.sub_commands)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# default Ctrl-C behaviour | |
import signal | |
signal.signal(signal.SIGINT, signal.SIG_DFL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
# with Timer(): pass | |
class Timer (object) : | |
def __init__ (self, callback = None, clock = False) : | |
import time | |
self.clock = time.clock if clock else time.time | |
self.callback = print if callback is None else callback | |
def __enter__ (self) : | |
self.start = self.clock() | |
def __exit__ (self, type, value, traceback) : | |
self.stop = self.clock() | |
self.callback(self.stop - self.start) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment