Skip to content

Instantly share code, notes, and snippets.

# ! /usr/bin/env python
# -*- coding: utf-8 -*-
class Pair:
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return 'Pair({0.x!r}, {0.y!r})'.format(self)
#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
@tao4yu
tao4yu / mysql_connect_model.py
Last active August 29, 2015 14:05
python 连接mysq
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb
import sys
def mysqlFunc():
try:
@tao4yu
tao4yu / insertAfter.js
Last active December 15, 2016 06:17
Javascript DOM: insertAfter方法实现
/*JaavaScript DOM 只提供了insertBefore方法:
* parentElement.insertBefore(newElement, targetElement)
* targetElement.parentNode.insertBefore(newElement, targetElement)
* 而没有提供insertAfter方法,可以利用DOM已有的属性和方法将其实现,如下。
*/
function insertAfter(newElement, targrtElement)
{
var parent = targetElement.parentNode;
if (parent.lastChild == targetElement)
@tao4yu
tao4yu / window_onLoad.js
Last active June 5, 2017 01:45
Javascript : window.onload 绑定多个事件
/*
*假设有2个函数firstFunction和secondFunction需要在网页加载完毕时执行, 需要绑定到window。onload。如果通过:
*
* window.onload = firstFunction;
* window.onload = secondFunction;
* 结果是只有secondFunction会执行,secondFunction会覆盖firstFunction。
*/
/*
*正确的方式是:
@tao4yu
tao4yu / createZhTbleName.py
Last active January 18, 2017 11:46
在MySQL中建立中文表名及中文字段名
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
# 在MySQL中建立中文表名及中文字段名
# MySQLdb 默认编码为 latin-1,改为utf-8
import MySQLdb as mdb
con = mdb.connect('localhost', 'root', 'root', 'testdb')
con.set_character_set('utf8')
@tao4yu
tao4yu / taskManual.py
Created December 26, 2013 07:18
Jinja2 startup 入门
from jinja2 import Environment, FileSystemLoader
import os
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
env = Environment(loader=FileSystemLoader(CURRENT_DIR), trim_blocks=True)
template = env.get_template("template.xml")
# 利用数据(字典数据文件或 key-value对)渲染模板
print template.render(taskData)
@tao4yu
tao4yu / UnicodeEncodeError_Frag.py
Created December 26, 2013 07:07
Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误的一种解决方法
# 加入如下代码片段, python2.7 默认为ascii编码,改为utf-8
import sys
default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
reload(sys)
sys.setdefaultencoding(default_encoding)
@tao4yu
tao4yu / getOuterHtml.js
Created November 13, 2013 03:05
jQuery get element outer HTML。
outer_html = $('selector').clone().wrap('<p>').parent().html();

Apple Wireless Keyboard via CSS3

Apple's wireless keyboard built entirely using css3. I could use code for the background, but currently gradients have really ugly banding. Regardless, enjoy! (:

A Pen by Dustin Cartwright on CodePen.

License.