Skip to content

Instantly share code, notes, and snippets.

View vincenting's full-sized avatar
:octocat:

Vincent Ding vincenting

:octocat:
View GitHub Profile
@vincenting
vincenting / github.py
Created March 10, 2015 13:50
github oauth2 for tornado.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import functools
import urllib.parse as urllib_parse
from tornado.concurrent import return_future
from tornado.auth import _auth_return_future, AuthError
from tornado import httpclient
from tornado.httputil import url_concat
@vincenting
vincenting / jinja2_tornado.py
Created March 10, 2015 10:01
Jinja2 support for tornado.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import posixpath
from jinja2 import Environment, FileSystemLoader
from tornado.template import BaseLoader
class Template(object):
def __init__(self, template):
@vincenting
vincenting / delayQueue.js
Created November 24, 2014 15:43
Delay queue for javascript.
$.queue = function(queue) {
var q = queue.sort(function(a, b) {
return a.delay - b.delay;
}),
next, pre = {
delay: 0
};
var run = function() {
next = q.shift();
if (!next) return;
@vincenting
vincenting / app.js
Last active August 29, 2015 14:04
var express = require('express');
var app = express();
var router = express.Router();
router.get('/', function (req, res) {
res.send('hello world');
});
router.get('/reset', function (req, res) {
@vincenting
vincenting / restart.sh
Last active August 29, 2015 14:03
Simple shell script for restart program.
#! /bin/bash
# Get server name source restart.sh sendclient.
servername=${1-'server'}
# Make logs dir if not exist.
mkdir -p logs
# If log file exist, rm and rename it.
if [ -f $servername.log ]; then
@vincenting
vincenting / evn.sh
Created April 27, 2014 12:15
golang init shell
# change gopath to current path
export GOPATH=$(pwd)
# create dirs if not exist
mkdir -p bin
mkdir -p src
mkdir -p pkg
# add current bin path to global path
export PATH=$PATH:$GOPATH/bin
@vincenting
vincenting / xiami.rb
Created February 22, 2014 03:15
虾米自动签到 beta
require 'patron'
require 'rufus-scheduler'
#TODO 异常触发后,将异常的具体内容通过邮件发送至管理员
module XiaMi
@login_url = 'http://www.xiami.com/web/login'
@index_url = 'http://www.xiami.com/web'
@sign_url = 'http://www.xiami.com/web/checkin/id/'
# coding: utf-8
require "faraday"
require "json"
LOGIN_EMAIL = '[email protected]'
LOGIN_PASSWORD = 'password here'
def send_req(url, params = {})
req_params = {
# coding: utf-8
require 'fiber'
def set_interval(millisec, &block)
Fiber.new do
end_time = Time.now.to_i + millisec
loop do
if Time.now.to_i > end_time
end_time = Time.now.to_i + millisec
@vincenting
vincenting / send_mail.rb
Last active January 1, 2016 17:49
A simple MTA Written in ruby.
require 'resolv'
require 'net/smtp'
require 'dkim'
Dkim::domain = 'domain.com'
Dkim::selector = 'mail'
Dkim::private_key = <<DKIM_KEY
-----BEGIN RSA PRIVATE KEY-----
Your Private Key Here.
-----END RSA PRIVATE KEY-----