This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.
publish message to foo
channel from user nickname
.
$ python pub.py foo nickname
PUBLISH to channel #foo
In [1]: import mailbox | |
In [2]: mbox = mailbox.mbox('/tmp/mbox/INBOX') | |
In [3]: maildir = mailbox.Maildir('/tmp/maildir/') | |
In [4]: for msg in mbox.itervalues(): | |
...: maildir.add(msg) |
from __future__ import unicode_literals | |
from os.path import splitext | |
from django.core import serializers | |
from django.db.migrations.operations.base import Operation | |
############################################################################### | |
# # | |
# In order to make the following code work, the model serializers and # |
class MaterializedViewOperationMixin(object): | |
def get_schema_editor(self, app_label, schema_editor): | |
if app_label in {'app1', 'app2'}: | |
return CustomSchemaEditor() | |
return schema_editor | |
class MaterializedViewCreateModel(MaterializedViewOperationMixin, CreateModel): | |
def database_forwards(self, app_label, schema_editor, from_state, to_state): | |
schema_editor = self.get_schema_editor(app_label, schema_editor) |
#!/bin/sh | |
branch="$(git rev-parse --abbrev-ref HEAD)" | |
if [[ ${branch} == stable/* ]] ; then | |
branch=${branch#stable/} | |
head -n1 .git/COMMIT_EDITMSG | grep -qP "\[\d\.\d\.x\]" | |
has_marker=$? | |
if [[ $has_marker == 0 ]] ; then | |
echo "[${branch}] " | cat - "${1}" > /tmp/tmpmessage | |
mv /tmp/tmpmessage "${1}" |
$ ssh -i .ssh/id_rsa testsshuser@localhost | |
PTY allocation request failed | |
Login at | |
http://localhost:8000/sshlogin/vbDkI7K4cD7y6cgOuJptjY5gxiDi3QevWZpXE74P5Gqu0YdefDVTFxjBqRGaRSGffhYa321pcNwSw64HvTdFRbVWKrBVnOkvyq83wsoR1Dd43EscUUlwg2V8XNcuACCqzSOgYEoDcySZgYPn1k0RHeBYLCZw2KLcPNa9yL6FKeSCUcG4rzjqe5gU2dYfXtrQ1okLnpK3cFl8fvgc0YL5MZrTIlV3mXHIKyM3V7tHVxZeyOulah6zp3o8plKGpZ/ | |
Shared connection to localhost closed. |
\newcounter{mycounter} | |
\newenvironment{myenv}[2][]{ | |
\begin{adjustwidth}{30pt}{30pt}\widowpenalties 1 10000 | |
\refstepcounter{mycounter} | |
\begingroup | |
\GetTitleStringSetup{expand}% | |
\subsubsection*{Foo~\arabic{mycounter}: {#2}}% | |
\ifthenelse{\equal{#1}{}}{}{\label{foo:#1}}\vspace{-7.5pt} | |
\endgroup |
for mig in $(python manage.py showmigrations --plan | awk '{split($0, a, " "); print a[2]}') ; do python manage.py sqlmigrate ${mig%.*} ${mig#*.} ; done |
def require_group(group_name): | |
def wrapper(user): | |
return user.groups.filter(name=group_name).exists() | |
return wrapper | |
@user_passes_test(require_group('Group 1')) | |
def view1(request): | |
# ... |
from random import randint | |
from node import init_list | |
def get_random(ll): | |
rand_pos = randint(0, len(ll)) | |
i = 0 | |
node = None | |
for n in ll: |