Skip to content

Instantly share code, notes, and snippets.

View drocco007's full-sized avatar

Daniel Rocco drocco007

  • BrightLink Technology
  • Atlanta, GA
View GitHub Profile
@drocco007
drocco007 / better_transpose.py
Last active August 29, 2015 14:15
Sublime Text 3 plugin to replace the default transpose command with something that behaves more like bash/emacs. Drop in to ~/.config/sublime-text-3/Packages/User to use.
import sublime, sublime_plugin
class Transpose(sublime_plugin.TextCommand):
"""Improve Sublime's transpose command.
Make Sublime's transpose command behave more like bash/emacs.
For each point:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<script src="profile.js"></script>
</head>
<body>
<pre id="output"></pre>
# coding: utf-8
@drocco007
drocco007 / .gitignore
Last active May 27, 2018 09:08
Postgres/WebSocket demo
*.html
@drocco007
drocco007 / py❤gdb.rst
Last active August 29, 2015 14:02
Notes from my PyAtl talk, June 12, 2014

py❤gdb

http://img.izismile.com/img/img6/20130913/640/prepare_to_panic_now_640_02.jpg

tl;dr

Attach to a running Python process using gdb:

@drocco007
drocco007 / eight_queens.py
Last active August 29, 2015 14:00
Eight queens solver (single solution). Adapted from Wirth's pseudo-Algol 60 algorithm presented in *Program Development by Stepwise Refinement*. http://oberoncore.ru/_media/library/wirth_program_development_by_stepwise_refinement2.pdf
"""Eight queens solver (single solution)
Adapted from Wirth's pseudo-Algol 60 algorithm presented in *Program
Development by Stepwise Refinement*.
http://oberoncore.ru/_media/library/wirth_program_development_by_stepwise_refinement2.pdf
"""

When I need to remember the spelling for a list comprehension with more than one loop in Python, I find the following mnemonic helpful:

write the for statements in the same order you would write a nested loop

For example, suppose we have a nested list that we wish to flatten:

>>> nested_list = [[1, 2, '5!'], (3, 'sir!')]
"""pywin32 native dialog demo
Explanation here: http://auralbits.blogspot.com/2014/02/a-native-win32-application-in-python.html #noqa
The core of this demo comes from the pywin32 win32gui_dialog demo:
http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/tip/win32/Demos/win32gui_dialog.py # noqa
"""
# ∅MQ multi-publisher message bus
#
# modeled on http://zguide.zeromq.org/py:msgqueue but with XPUB/XSUB instead
# of ROUTER/DEALER
#
# usage: julia bus.jl <inbound_port> <outbound_port>
#
using ZMQ
@drocco007
drocco007 / conftest.py
Last active January 25, 2016 22:45
py.test + SQLAlchemy transactional testing
import pytest
from turbogears.database import get_engine, session
@pytest.fixture(autouse=True)
def wrap_transaction(request):
"""Automatically wrap test cases in a transaction, rolled back on
completion. Uses an "external," non-ORM transaction that is durable
against inner transactions used by the ORM. Thanks to @sontek