Skip to content

Instantly share code, notes, and snippets.

@dzhuang
dzhuang / deep_eq.py
Last active November 9, 2017 04:56 — forked from samuraisam/deep_eq.py
Deep Equality Test for Nested Python Structures
# Copyright (c) 2010-2013 Samuel Sutch [samuel.sutch@gmail.com]
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@dzhuang
dzhuang / create-docker-tls.sh
Last active September 8, 2017 19:13 — forked from Stono/create-docker-tls.sh
Creating and setting up Docker for TLS
#!/bin/bash
# This script will help you setup Docker for TLS authentication.
# Run it passing in the arguement for the FQDN of your docker server
#
# For example:
# ./create-docker-tls.sh myhost.docker.com
#
# The script will also create a profile.d (if it exists) entry
# which configures your docker client to use TLS
#
@dzhuang
dzhuang / example-output.md
Created November 1, 2016 09:41 — forked from bwbaugh/example-output.md
Generate a randomly connected graph with N nodes and E edges.

Example output

Minimum number of edges

python random_connected_graph.py -p -g names.gml names.txt

Console

@dzhuang
dzhuang / mail.py
Created September 8, 2016 15:51 — forked from niran/mail.py
Multiple email connections in Django
from django.conf import settings
import django.core.mail
class MissingConnectionException(Exception):
pass
def get_connection(label=None, **kwargs):
if label is None:
label = getattr(settings, 'EMAIL_CONNECTION_DEFAULT', None)
@dzhuang
dzhuang / transport.py
Last active September 28, 2021 01:35 — forked from bogdan-kulynych/transport.py
Transportation problem solver in Python
# -*- coding: utf-8 -*-
import numpy as np
from collections import Counter
def transport(supply, demand, costs, init_method="LCM"):
# Only solves balanced problem
assert sum(supply) == sum(demand)
@dzhuang
dzhuang / strip_comments.py
Last active April 16, 2023 18:14 — forked from amerberg/strip_comments.py
A script to remove comments from LaTeX source
import ply.lex, argparse, io
# modified from https://gist.github.com/amerberg/a273ca1e579ab573b499
#Usage
# python stripcomments.py input.tex > output.tex
# python stripcomments.py input.tex -e encoding > output.tex
# Modification:
# 1. Preserve "\n" at the end of line comment
@dzhuang
dzhuang / latex.py
Created April 25, 2016 15:43 — forked from sobelk/latex.py
"""
Django LaTeX custom template tag for equations (using amsmath).
Creates a .png in the project media directory and returns an img tag that references it.
Usage:
{% latex %}
x=\frac{-b \pm \sqrt {b^2-4ac}}{2a}
{% endlatex %}