Skip to content

Instantly share code, notes, and snippets.

class DatabaseWrapper:
def __init__(self, params=None):
if params is None:
# read connection params from a config file (?)
params = self.config()
self.connection_params = params
self.connection = None
def config(self):
@embray
embray / demo.py
Created December 4, 2019 15:23
Demo
def positive(L, x):
c1 = -1
c2 = -1
for c in L:
if c1 >= 0 and c2 >= 0:
break
if c == x and c1 < 0:
continue
root@b554a1ceecf7:/# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS"
root@b554a1ceecf7:/# python3.6
Python 3.6.5 (default, May 3 2018, 10:08:28)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import signal
@embray
embray / foo.pyx
Last active April 11, 2016 11:19
Example Cython project with sharing between pyx file and plain C file
cdef public void hello():
print "Hello world!"
<HTML>
<TITLE>WebNow 6</TITLE>
<META CONTENT="0" HTTP-EQUIV="expires">
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK href="favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">
</HEAD>
<BODY leftmargin="0" marginheight="0" marginwidth="0" style="overflow-x:hidden;overflow-y:hidden" topmargin="0">
<SCRIPT LANGUAGE="JavaScript1.1">document.write('<APPLET archive="webnowapplet.jar" code="com.imagenow.webnow.applet.WebNow" height="100%" width="100%"><PARAM NAME="code" VALUE="com.imagenow.webnow.applet.WebNow"><PARAM NAME="java_version" VALUE="1.6* 1.7*"><PARAM NAME="archive" VALUE="webnowapplet.jar,lang.jar,TimingFramework-1.0.jar,jxlayer.jar,l2fprod-common-all.jar,icebrowser.jar,jniwrap-3.8.4.jar,comfyj-2.10.jar,winpack-3.8.4.jar,slf4j-api-1.5.8.jar,slf4j-simple-1.5.8.jar"><PARAM NAME="cache_archive" VALUE="webnowapplet.jar,lang.jar,TimingFramework-1.0.jar,jxlayer.jar,l2fprod-common-all.jar,icebrowser.jar,jniwrap-3.8.4.jar,comfyj-2.10.jar,winpack-3.8.4.jar,slf4j-api
Mock Version: 1.1.41
ENTER do(['bash', '--login', '-c', 'rpmbuild -bs --target i686 --nodeps builddir/build/SPECS/python-astropy.spec'], False, '/var/lib/mock/fedora-21-i386/root/', None, 0, True, False, 1000, 135, None, False, {'LANG': 'es_ES.utf8', 'TERM': 'vt100', 'SHELL': '/bin/bash', 'CCACHE_DIR': '/tmp/ccache', 'HOSTNAME': 'mock', 'PROMPT_COMMAND': 'echo -n "<mock-chroot>"', 'HOME': '/builddir', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'CCACHE_UMASK': '002'}, logger=<mockbuild.trace_decorator.getLog object at 0x13f9750>)
Executing command: ['bash', '--login', '-c', 'rpmbuild -bs --target i686 --nodeps builddir/build/SPECS/python-astropy.spec'] with env {'LANG': 'es_ES.utf8', 'TERM': 'vt100', 'SHELL': '/bin/bash', 'CCACHE_DIR': '/tmp/ccache', 'HOSTNAME': 'mock', 'PROMPT_COMMAND': 'echo -n "<mock-chroot>"', 'HOME': '/builddir', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'CCACHE_UMASK': '002'}
Construyendo las plataformas de destino: i686
Construyendo para el destino i686
Escrito: /builddir/build/SRPMS/pytho
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@embray
embray / gist:3dc1dcb0d264bce912fb
Created October 1, 2014 17:20
That time I reimplemented/replaced the raw_input builtin so I could log stdin.
PY3K = sys.version_info[:2] >= (3, 0)
# The global_logging system replaces the raw_input builtin (input on Python 3)
# for two reasons:
#
# 1) It's the easiest way to capture the raw_input prompt and subsequent user
# input to the log.
#
# 2) On Python 2.x raw_input() does not play nicely with GUI toolkits if
# sys.stdout has been replaced by a non-file object (as global_logging
# does). The default raw_input() implementation first checks that
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.