Skip to content

Instantly share code, notes, and snippets.


Bright Chen earthday

View GitHub Profile
import logging
import cherrypy
from cherrypy.process import plugins
class ADPHttpFacetPlugin(plugins.SimplePlugin):
def __init__(self, bus):
plugins.SimplePlugin.__init__(self, bus)
self.logger = logging.getLogger(__name__)
import cherrypy
class City:
def __init__(self, name): = name
self.population = 10000
earthday /
Last active Nov 1, 2016
Copied from the internet. And maybe the twepoch should be 1288834974657L.
public class SnowFlakeIdWorker {
private final long workerId;
private final static long twepoch = 1390838400000L;
private Long sequence = 0L;
private final static long workerIdBits = 4L;
public final static long maxWorkerId = -1L ^ -1L << workerIdBits;
private final static long sequenceBits = 10L;
private final static long workerIdShift = sequenceBits;
private final static long timestampLeftShift = sequenceBits + workerIdBits;
View app.cpp
#include <iostream>
#include <thread>
using namespace std;
int _id = 1;
class Person
earthday / SimpleVimrc
Created Jan 19, 2016
Simple vimrc for server
View SimpleVimrc
set nu
set autochdir
set encoding=utf-8
set fileencoding=utf-8
set ai
set si
set ts=4
set st=4
set sw=4
set et
earthday / self-signed-ssl-certificate.txt
Created Jul 11, 2015
create a self-signed SSL certificate
View self-signed-ssl-certificate.txt
# Become root first !
$ mkdir /etc/ssl/self-signed && cd /etc/ssl/self-signed
$ openssl genrsa -des3 -out server.key 1024
$ openssl rsa -in server.key -out server.key.insecure
$ mv server.key && mv server.key.insecure server.key
$ openssl req -new -key server.key -out server.csr
$ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
earthday / convert_to_int_with_default_zero.js
Last active Aug 29, 2015
Convert to integer with a default value of 0.
View convert_to_int_with_default_zero.js
(function(priority) {console.log(priority); return priority && + priority | 0 || 0; })()
// undefined
// 0
(function(priority) {console.log(priority); return priority && + priority | 0 || 0; })(45)
// 45
// 45
(function(priority) {console.log(priority); return priority && + priority | 0 || 0; })('a')
// a
View dynamic_font_size_in_qlabel_based_on_text_length.cpp
int fit = false;
QLabel *myLabel = this->testLabel;
QFont myFont = myLabel->font();
QString str = "this is the new string. this is the new string. this is the new string. super long. don't fit. please please please overflow the box";
while (!fit)
earthday / html5.html
Created Feb 24, 2015
The template of html5 which is copied from
View html5.html
<!DOCTYPE html>
<meta charset="utf-8">
<title>KISSY MINI Mobile Demo Template</title>
View tox_example.ini
# Tox ( is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.
skipsdist = True