Skip to content

Instantly share code, notes, and snippets.

View earthday's full-sized avatar
🔋
Power~!

Bright Chen earthday

🔋
Power~!
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__)
# https://stackoverflow.com/questions/13484206/cherrypy-url-dispatcher
import cherrypy
class City:
def __init__(self, name):
self.name = name
self.population = 10000
@earthday
earthday / SnowFlakeIdWorker.java
Last active November 1, 2016 08:38
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;
@earthday
earthday / app.cpp
Created September 22, 2016 09:28
Run it online from http://cpp.sh/77sn5
#include <iostream>
#include <thread>
using namespace std;
int _id = 1;
class Person
{
public:
@earthday
earthday / SimpleVimrc
Created January 19, 2016 05:16
Simple vimrc for server
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
earthday / self-signed-ssl-certificate.txt
Created July 11, 2015 08:16
create a self-signed SSL certificate
# 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 server.key.secure && 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
earthday / convert_to_int_with_default_zero.js
Last active August 29, 2015 14:21
Convert to integer with a default value of 0.
(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
int fit = false;
this->testLabel->setText("");
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
earthday / html5.html
Created February 24, 2015 03:38
The template of html5 which is copied from http://m.kissyui.com/docs/quickstart
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>KISSY MINI Mobile Demo Template</title>
<!--
width=device-width:让文档的宽度与设备的宽度保持一致,且文档最大的宽度比例是1.0
initial-scale=1:初始的缩放比例
maximum-scale=1:允许用户缩放到的最大比例(对应还有个minimum-scale)
user-scalable=no:不允许用户手动缩放
@earthday
earthday / tox_example.ini
Created February 11, 2015 06:55
tox_example.ini
# Tox (http://tox.testrun.org/) 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.
[tox]
skipsdist = True