Skip to content

Instantly share code, notes, and snippets.

@tonsh
tonsh / convert_relative_to_absolute.py
Last active December 18, 2015 04:39
Conver a relative path to absolute path with python!
#coding=utf-8
import urlparse
import unittest
def convert_relative_to_absolute(url, base_url):
base_url = base_url or ''
if not url:
return base_url
@tonsh
tonsh / ajax_form.coffee
Last active December 18, 2015 18:59
A class or plugin of ajax submit form with success callback method
# A class or plugin of ajax submit form with success callback method
class AjaxForm
#ajax submit class
constructor: (form) ->
@form = form
init: (callback) ->
@form.submit =>
@tonsh
tonsh / history_push.coffee
Last active December 18, 2015 20:29
Loader document with history.pushState and window.popstate; Refrence: http://rosspenman.com/pushstate-jquery/
$.fn.extend
historyPush: (options) ->
settings =
bind: ''
loader: ''
target: ''
callback: null
settings = $.extend settings, options
@tonsh
tonsh / bissexitil.py
Created June 25, 2013 07:07
Bissextil year!
"""
闰年: 四年一闰,百年不闰,四百年再闰
"""
def is_bissextil_year(year):
if (year % 4 == 0) and (year % 100 != 0):
return True
if year % 400 == 0:
return True
@tonsh
tonsh / pySingleton.py
Created July 10, 2013 13:08
Use diffrent way to implement singleton class with python
#coding=utf-8
import unittest
# 单例类
class MyClassA(object):
_instance = None
def __init__(self):
self._a = 0
@tonsh
tonsh / omytime.php
Last active December 19, 2015 18:29
<?php
/**
* 日期分段类
*/
abstract class DateStep {
const DAYTIME = 86400
const WEEKTIME = 86400 * 7
protected $startTime;
<?php
class MysqlConnectorError extends Exception {}
/**
* Mysql 连接管理类
*
* @author Sarah <tonshlee@gmail.com>
*
* <code>
* MysqlManager::instance()
@tonsh
tonsh / common_functions.php
Last active December 22, 2015 03:38
PHP Common Functions!
<?php
/**
* @author tonsh
*
* A set of common used functions
*/
/**
* 将数字字符串每3位添加一个逗号(从右向左)
# coding=utf-8
import datetime
import unittest
def strptime(date_str):
""" 不确定 date_str 格式的字符串与日期转换 """
if isinstance(date_str, datetime.datetime):
return date_str
@tonsh
tonsh / variable_addreess.c
Last active December 28, 2015 23:59
C语言整型变量地址测试!
#include<stdio.h>
int main() {
int a = 1;
printf("%p\n", &a); // --> 0x7fff614d1a74
a++;
printf("%p\n", &a); // --> 0x7fff614d1a74
int b = a;
printf("%p\n", &b); // --> 0x7fff658c8a70
return 0;