Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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:
#!/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
# ! /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)