Skip to content

Instantly share code, notes, and snippets.

@tynn
Last active January 1, 2016 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tynn/8160190 to your computer and use it in GitHub Desktop.
Save tynn/8160190 to your computer and use it in GitHub Desktop.
Python Snippets
from gi.repository import Gtk
window = Gtk.Window()
window.connect('delete-event', Gtk.main_quit)
window.show()
Gtk.main()
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_
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))
# default Ctrl-C behaviour
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
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