Skip to content

Instantly share code, notes, and snippets.

View pcdinh's full-sized avatar

Pham Cong Dinh pcdinh

View GitHub Profile
@pcdinh
pcdinh / slave_gevent.py
Created January 22, 2012 19:34 — forked from gleicon/slave_gevent.py
gevent+kombu actor/mailbox using decorators
from __future__ import with_statement
from kombu import BrokerConnection
from collections import defaultdict
import gevent
from gevent import monkey
monkey.patch_all()
class WorkerHub():
"""
WorkerHub controls the local mailboxes that the @worker decorator assigns.
@pcdinh
pcdinh / gist:1743283
Created February 5, 2012 05:49 — forked from srid/gist:1502656
Asynchronous run command lazily yielding command output (Python gevent)
def run_seq(cmd):
"""Run `cmd` and yield its output lazily"""
p = subprocess.Popen(
cmd, shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
# make STDIN and STDOUT non-blocking
fcntl.fcntl(p.stdin, fcntl.F_SETFL, os.O_NONBLOCK)
@pcdinh
pcdinh / pinhole.py
Created August 2, 2012 07:22 — forked from xiocode/pinhole.py
A simple port multiplexer
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# author: mayli <mayli.he@gmail.com>
#
# Modified from Pinhole, and the original code is found here:
# {{{ http://code.activestate.com/recipes/114642/ (r1)
#
"""
usage: pinhole
@pcdinh
pcdinh / postgis_timezone_db.markdown
Created November 22, 2012 10:42 — forked from robcowie/postgis_timezone_db.markdown
Create a postgis-compatible timezone database

Create a Postgis timezone DB

See https://gist.github.com/3449216

Create a timezone db from shapefiles

$ curl -O http://efele.net/maps/tz/world/tz_world.zip
$ wget http://efele.net/maps/tz/us/tz_us.zip
$ open tz_world.zip
@pcdinh
pcdinh / stripe-keys-and-ids.tsv
Created September 24, 2020 09:27 — forked from fnky/stripe-keys-and-ids.tsv
Stripe keys and IDs
Prefix Description Notes
sk_live_ Live secret key Secret key in a live environment.
pk_live_ Live public key Public key in a live environment.
pst_live_ Live Connection token Connection token in a live environment.
sk_test_ Test secret key Pecret key in a test environment.
pk_test_ Test public key Public key in a test environment.
pst_test_ Test Connection token Connection token in a test environment.
ac_ Platform Client ID Identifier for an auth code/client id.
acct_ Account ID Identifier for an Account object.
ch_ Charge ID Identifier for a Charge object.
@pcdinh
pcdinh / 1_stripe-schema.md
Created September 24, 2020 08:18 — forked from FGRibreau/1_stripe-schema.md
Stripe database schema (extracted from their sigma product) as of 2019-10-09
jqn -r markdown-table 'map(x => "## " + x.name + "\n\n" + markdownTable(x.columns.map(y => [y.name, y.type]))  ) | join("\n\n")' < /tmp/stripe.json

accounts

id varchar
business_name varchar
business_url varchar
@pcdinh
pcdinh / ttf-vista-fonts-installer.sh
Created December 30, 2019 09:32 — forked from maxwelleite/ttf-vista-fonts-installer.sh
Script to install Microsoft Vista TrueType Fonts (TTF) aka Microsoft’s ClearType fonts on Ubuntu distros
#!/bin/bash
# Author: Maxwel Leite
# Website: http://needforbits.wordpress.com/
# Description: Script to install Microsoft Vista TrueType Fonts (TTF) aka Microsoft’s ClearType fonts on Ubuntu distros
# Microsoft added a group of new "ClearType Fonts" to Windows with Windows Vista and Office 2007.
# These fonts are named Constantia, Corbel, Calibri, Cambria (and Cambria Math), Candara, and Consolas.
# Calibri became the default font on Microsoft Word 2007, and it’s still the default font on Word 2016 today.
# Dependencies: wget, fontforge and cabextract
# Note: Microsoft no longer provides the PowerPoint Viewer 2007 (v12.0.4518.1014) or any version anymore for download
# Tested: Ubuntu Saucy/Trusty/Xenial/Bionic
@pcdinh
pcdinh / uploader.py
Created September 9, 2012 18:44 — forked from JordanReiter/uploader.py
Python snippet for uploading file to another server
import errno
import os
import paramiko
class Uploader(object):
def __init__(self, host, basepath='', username=None, password=None, keyfile=None, *args, **kwargs):
self.host = host
self.basepath = basepath
self.username = username
@pcdinh
pcdinh / decorators.py
Created April 29, 2012 18:05
Flask login_required decorator
from flask import request, g
from functools import wraps
def login_required(f=None, url="public.login", next=None):
"""
Check if user is logged or redirect to a certain page.
By default go to public login.
"""
def outer_decorator(decorated_fn):