Skip to content

Instantly share code, notes, and snippets.

View lucaswiman's full-sized avatar

[object Object] lucaswiman

View GitHub Profile
@lucaswiman
lucaswiman / foo.dot
Created May 31, 2016 06:21
networkx / graphviz example
digraph {
0 -> "*" [key=0,
label="[b]"];
1 -> "*" [key=0,
label="[d]"];
enter -> "*" [key=0,
label=ε];
"*" -> 0 [key=0,
label="[a]"];
"*" -> 1 [key=0,
@lucaswiman
lucaswiman / sudoku.py
Last active November 4, 2019 05:52
python-constraint sudoku solver
from constraint import *
ROWS = 'abcdefghi'
COLS = '123456789'
DIGITS = range(1, 10)
VARS = [row + col for row in ROWS for col in COLS]
ROWGROUPS = [[row + col for col in COLS] for row in ROWS]
COLGROUPS = [[row + col for row in ROWS] for col in COLS]
SQUAREGROUPS = [
[ROWS[3 * rowgroup + k] + COLS[3 * colgroup + j]
for j in range(3) for k in range(3)]
$ pbpaste | head -c $((5*1024)) > tale_of_two_cities.txt
$ head -c 200 tale_of_two_cities.txt
It was the best of times, it was the worst of times,
it was the age of wisdom, it was the age of foolishness,
it was the epoch of belief, it was the epoch of incredulity,
it was the season of Light, i
$ qrencode -o /tmp/long.png "`cat tale_of_two_cities.txt`"
Failed to encode the input data: Result too large
$ qrencode -o /tmp/long.png "`cat tale_of_two_cities.txt | gzip`"
@lucaswiman
lucaswiman / gist:13a101c0a9e787b8d9a8042236fff67e
Created August 31, 2016 04:25
Check if latest version of django still has a bug in django in Django 1.9
virtualenv foo
source foo/bin/activate
pip install git+https://github.com/django/django.git
pip install psycopg2
django-admin.py startproject example
cd example
./manage.py shell
from django.contrib.postgres.forms import SimpleArrayField
@lucaswiman
lucaswiman / upgrade.md
Last active September 14, 2016 02:04
Upgrading a simple package to python 3

How to make a library Python 3 compatible

Install:

  • tox, for running the test suite parameterized by multiple versions.
  • future, for doing some of the auto-conversion.
pip install tox future
HOLT: Our next segment is called “Securing America.” We want to start with a 19th century war happening every day in this country. Our institutions are under steam attack, and our secrets are being stolen. So my question is, who’s behind it? And how do we fight it?
Secretary Clinton, this answer goes to you.
CLINTON: Well, I think steam security, steam warfare will be one of the biggest challenges facing the next president, because clearly we’re facing at this point two different kinds of adversaries. There are the independent hacking groups that do it mostly for commercial reasons to try to steal information that they can use to make money.
But increasingly, we are seeing steam attacks coming from states, organs of states. The most recent and troubling of these has been Russia. There’s no doubt now that Russia has used steam attacks against all kinds of organizations in our country, and I am deeply concerned about this. I know Donald’s very praiseworthy of Vladimir Putin, but Putin is play
@lucaswiman
lucaswiman / __radd__.py
Created November 7, 2016 22:02
Python operator overloading example
from __future__ import unicode_literals, print_function
class Add(str):
def __add__(self, other):
print('__add__')
return super(Add, self).__add__(other)
class Radd(str):
def __radd__(self, other):
git fetch origin -p && git branch -a --merged remotes/origin/master | grep -v master | grep "remotes/origin/" | cut -d "/" -f 3 | xargs -n 1 --max-procs=4 echo git push --delete origin
@lucaswiman
lucaswiman / tox.ini
Last active December 20, 2016 00:52
pylint checking for python 3 compatibility
pylint counsyl/product --py3k --disable=no-absolute-import
function show-history() {
prevbranch="$(git rev-parse --abbrev-ref HEAD)"
echo $prevbranch
newbranch="$1"
echo $newbranch
echo "$newbranch = {"
for sha1 in $(git rev-list $newbranch) ; do
git checkout $sha1 &> /dev/null
echo " '$(git ls-files | sort | xargs sha1sum | sha1sum | cut -d' ' -f1)' : '$sha1',"
done