Skip to content

Instantly share code, notes, and snippets.

@neilxp
neilxp / weiboPm.py
Created April 26, 2013 02:59
send weibo private message
#!/usr/bin/python
# $Id: weiboPm.py,v 1.0 2013/04/26 12:00:00 $
import sys,os,xmpp,time
USER=r"123456\40qq.com"
PASSWORD="secret"
RECEIVER=['123456@weibo.com']
def sendWeiboMsg(receivers, message):
jidparams={}
@neilxp
neilxp / msg2ios.py
Created January 7, 2013 14:49
Python program for sending message to iOS via APN
#!/usr/bin/python2.7
import socket
import ssl
import json
import struct
import argparse
APNS_HOST = ( 'gateway.sandbox.push.apple.com', 2195 )
@neilxp
neilxp / dumphex.hpp
Created January 5, 2013 13:20
Dump hex of a buffer, that the format is (almost) identical to the output of `xxd` in Linux, so the dumped text could be parsed by `xxd -r`
#ifndef __DUMP_HEX_HEADER__
#define __DUMP_HEX_HEADER__
#define DH_NUM_BYTES_PER_LINE 16
#define DH_HEX_POS 46
#define DH_HEX_OFFSET 6
#define DH_HEX_COLUMN_SIZE 8
#define DH_SEPERATOR ' '
#define DH_UNPRINTABLE '.'
@neilxp
neilxp / JeAllocator.hpp
Created October 24, 2012 13:00
JeAllocator
#ifndef __JeAllocator__HEADER__
#define __JeAllocator__HEADER__
#define JEMALLOC_NO_DEMANGLE 1
#include "jemalloc/jemalloc.h"
template<typename T>
class JeAllocator {
public :
// typedefs
@neilxp
neilxp / gist:3127577
Created July 17, 2012 06:24
proxy.pac
function regExpMatch(url, pattern) {
try { return new RegExp(pattern).test(url); } catch(ex) { return false; }
}
function FindProxyForURL(url, host) {
url = url.toLowerCase();
host = host.toLowerCase();
var proxy = "PROXY 1.1.1.1:8999";
@neilxp
neilxp / IOWatch.py
Created June 15, 2012 02:29
watch IO for process
#!/usr/bin/python
# Monitoring per-process disk I/O activity
# written by http://www.vpsee.com
import sys, os, time, signal, re
class DiskIO:
def __init__(self, pname=None, pid=None, reads=0, writes=0):
self.pname = pname
self.pid = pid
@neilxp
neilxp / dumpstack.sh
Created June 7, 2012 08:42
dumpstack
#!/bin/sh
if test $# -ne 1; then
echo "Usage: `basename $0 .sh` PROGRAM" 1>&2
exit 1
fi
GDB=${GDB:-gdb}
if $GDB -nx --quiet --batch --readnever > /dev/null 2>&1; then
@neilxp
neilxp / CAPTCHA.cpp
Created May 15, 2012 12:34
CPP CAPTCHA generator
#include <memory>
#include <time.h>
#include <vector>
#include <string>
#include <iterator>
#include <fstream>
#include <boost/shared_ptr.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
@neilxp
neilxp / credit.js
Created December 13, 2011 02:55
credit card number checking
CreditCard: {
TEST_NUMBERS: $w('378282246310005 371449635398431 378734493671000 30569309025904 38520000023237 6011111111111117 6011000990139424 5555555555554444 5105105105105100 4111111111111111 4012888888881881 4222222222222'),
isValid: function(number){
if (number.blank()) return false;
if (Braintree.CreditCard.TEST_NUMBERS.include(number)) return false;
var total = ($A(number).reverse().inject(0, function(a, n, index) {
return a + $A((parseInt(n) * [1, 2][index % 2]).toString()).inject(0, function(b, o) {
return b + parseInt(o);
@neilxp
neilxp / shaping.c
Created October 29, 2011 07:50
shaping
#include "shaping.h"
#ifdef LINUX
#include <sys/time.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#define OCT_CYCLES_PER_SECOND (1000000ull)