Skip to content

Instantly share code, notes, and snippets.

from concurrent.futures import ThreadPoolExecutor
from functools import partial, wraps
import time
import tornado.ioloop
import tornado.web
EXECUTOR = ThreadPoolExecutor(max_workers=4)

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.


mkyung /
Created February 7, 2015 07:52
An example of using Q.spawn with generator and yield a request
Q = require("q")
request = require("request")
# add a new GET method on top of the original GET
request.qget = (uri, options) ->
dfd = Q.defer()
request.get uri, options, (err, response, body) ->
if err


Dyn's free dynamic DNS service will be ending on Wednesday, May 7th, 2014.

CloudFlare, however, has a little known feature that will allow you to update your DNS records via API or a command line script called ddclient. This will give you the same result, and it's also free.

Unfortunately, ddclient does not work with CloudFlare out of the box. There is a patch available

import cv2
import as cv
def detect(img, cascade_fn='haarcascades/haarcascade_frontalface_alt.xml',
scaleFactor=1.3, minNeighbors=4, minSize=(20, 20),
cascade = cv2.CascadeClassifier(cascade_fn)
rects = cascade.detectMultiScale(img, scaleFactor=scaleFactor,
mkyung / aws_ips.rb
Created April 3, 2016 03:48 — forked from wbingli/aws_ips.rb
Calculate AWS total IPs
require 'open-uri'
require 'json'
data = JSON.load(open(""))
ip_total = data['prefixes'].reduce(0) do | sum, item |
sum += 2 ** (32 - item['ip_prefix'].split('/')[1].to_i)
puts "AWS Total IPs: #{ip_total}"
mkyung / Users.csv
Last active April 4, 2016 09:41 — forked from yesdevnull/Users.csv
Use this script to import users into an Open Directory domain on OS X Mavericks Server with users in a CSV. The Users.csv file is an example file to show you the structure expected.
Joe Smith 123456 147852
Bill Jones 987654 369852
Steve Miller 654321 852147
mkyung /
Created June 7, 2016 16:08 — forked from nepsilon/
Proper way to do backup (and restore!) with PostgreSQL 🐘
# Backup your database with:
# This is Postgres custom format
pg_dump -Fc dbname > filename
# And recover it with:
# First create the DB with:
createdb -O owner_user dbname
# And then populate it:
pg_restore -d dbname filename
mkyung / command
Created June 14, 2016 04:47
Linux TCP connection stats
netstat -tn | awk '/^tcp/ {t[$NF]++}END{for(state in t){print state, t[state]} }'
# Results:
# SYN_SENT 500