Skip to content

Instantly share code, notes, and snippets.

@moschlar
moschlar / movie.py
Last active December 12, 2015 04:28
Customize sprox dropdown menus
class Genre(DeclarativeBase):
__tablename__ = "genres"
genre_id = Column(Integer, primary_key=True)
name = Column(String(100))
description = Column(String(200))
@property
def _name(self):
return '%s (%s)' % (self.name, self.description)
def add_error_middleware(self, global_conf, app):
"""Add middleware which handles errors and exceptions."""
from pylons.middleware import report_libs, StatusCodeRedirect
from tg.error import ErrorHandler
#from raven import Client
#from raven.middleware import Sentry as WSGISentry
#app = WSGISentry(app, Client(config.get('sentry.dsn')))
from raven.contrib.pylons import Sentry as PylonsSentry
app = PylonsSentry(app, config)
@moschlar
moschlar / timer.py
Created June 2, 2013 12:53
Python execution timing context manager class
import time
class Timer(object):
def __init__(self, echo=False):
self._start = 0.0
self._stop = 0.0
self.echo = echo
def __enter__(self):
self._start = time.time()
@moschlar
moschlar / awesomepythonpackages.md
Last active December 23, 2015 09:39
Collection of awesome Python packages. Just a personal notepad.
  • Arrow: better dates and times for Python
  • ftfy: fixes text for you
  • colors.py: Colors aren't that scary!
  • ordereddict: No need to include the ActiveState recipe anymore
  • argh: An unobtrusive argparse wrapper with natural syntax
  • billiard: Python multiprocessing fork with improvements and bugfixes
  • Unidecode: ASCII transliterations of Unicode text
  • anyjson: Wraps the best available JSON implementation available in a common interface

Keybase proof

I hereby claim:

  • I am moschlar on github.
  • I am moschlar (https://keybase.io/moschlar) on keybase.
  • I have a public key whose fingerprint is 19F9 B5A8 821A 081E FE92 D306 45D3 DBDD FBDD 8888

To claim this, I am signing this object:

@moschlar
moschlar / make.conf
Last active February 5, 2024 10:00
Run Gentoo Portage in a cpu cgroup
PORTAGE_IONICE_COMMAND="/usr/local/sbin/portage-cgroup \${PID}"
@moschlar
moschlar / sproxbug.py
Created November 12, 2014 11:09
Minimal working example to demonstrate issue TurboGears/sprox#4
'''Minimal working example to demonstrate issue TurboGears/sprox#4
Summary:
If the "many" side of a sqlalchemy relationship is also a required field
in sprox, the MultipleSelectField gets a UnicodeString validator, which
simply converts the value to a string, regardless of its type (in this
example, it leads to the repr string being used as the value). For
determining the selected options of the select field, the in operator
is then used on whatever string got generated first, leading to awkwardly
wrong selected values.
@moschlar
moschlar / README.md
Last active March 25, 2019 05:01
Build and install ShareLaTeX in Ubuntu 14.04 LTS

Since the official ShareLaTeX documentation is primarily written with Ubuntu 12.04 LTS in mind, I tried to re-build the provided .deb from scratch using Ubuntu 14.04 TLS with the least amount of non-standard or non-packaged software.

Here are all the steps that were required (with sudo since Ubuntu doesn't want you to be root).

First, install lots of packages - note that no additional repositories are required! (Dependencies):

$ sudo apt-get update
$ sudo apt-get install git build-essential curl python-software-properties zlib1g-dev zip unzip
$ sudo apt-get install ruby-dev
$ sudo apt-get install nodejs npm
@moschlar
moschlar / README.md
Last active August 29, 2015 14:09
NetBeans on Gentoo Linux

The Netbeans Launcher works not so well with Gentoo Linux' Java environment.

I did install Netbeans trough the Installer and OpenJDK via the package dev-java/icedtea-bin, which installs to e.g. /opt/icedtea-bin-7.2.5.3/.

Now the Netbeans Installer would hardcode netbeans_jdkhome="/opt/icedtea-bin-7.2.5.3" in the ~/.local/opt/netbeans-8.0.1/etc/netbeans.conf file. Of course, this path breaks on the next (minor) update of dev-java/icedtea-bin.

Simply commenting out the netbeans_jdkhome line does not work due to the way Gentoo uses its eselect mechanism for selecting a system/user Java VM implementation from a variety of installed ones. nbexecs autodetecting of the java executable fails because of the run-java-tool.bash script to which /usr/bin/java gets symlinked. I hope the symlinkery gets clear from the shell session below, if not, I'd be happy to supply more information.

@moschlar
moschlar / gitlab.sh-session
Created January 21, 2015 22:22
GitLab Omnibus bundling all dependencies
$ dpkg-deb -c gitlab_7.6.2-omnibus.5.3.0.ci.1-1_amd64.deb | grep -v '/opt/gitlab/'
drwx------ 0/0 0 2015-01-08 10:00 ./
drwxr-xr-x 0/0 0 2015-01-08 10:00 ./opt/
$ dpkg-deb -c gitlab_7.6.2-omnibus.5.3.0.ci.1-1_amd64.deb | grep '/bin/' | egrep -v 'gems?'
drwxr-xr-x 0/0 0 2015-01-08 10:00 ./opt/gitlab/bin/
-rwxr-xr-x 0/0 460 2015-01-08 09:45 ./opt/gitlab/bin/gitlab-ci-rake
-rwxr-xr-x 0/0 461 2015-01-08 09:45 ./opt/gitlab/bin/gitlab-ci-rails
-rwxr-xr-x 0/0 479 2015-01-08 09:57 ./opt/gitlab/bin/gitlab-rails
-rw-r--r-- 0/0 0 2015-01-08 09:11 ./opt/gitlab/bin/.gitkeep
-rwxr-xr-x 0/0 1121 2015-01-08 09:57 ./opt/gitlab/bin/gitlab-ctl