Skip to content

Instantly share code, notes, and snippets.

if __name__ == '__main__':
pid_file = cur_file_dir() + '/logstat.pid'
fp = open(pid_file, 'w')
try:
fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
# another instance is running
sys.exit(0)
@wjzhangq
wjzhangq / my_date.py
Created April 29, 2019 08:30
时间函数
def my_date(unixtime, format='%m/%d/%Y %H:%M'):
d = datetime.datetime.fromtimestamp(unixtime)
return d.strftime(format)
def cur_file_dir():
# 获取脚本路径
path = sys.path[0]
# 判断为脚本文件还是py2exe编译后的文件,如果是脚本文件,则返回的是脚本的目录,如果是py2exe编译后的文件,则返回的是编译后的文件路径
if os.path.isdir(path):
return path
elif os.path.isfile(path):
return os.path.dirname(path)
<?php
class Fib implements Iterator{
var $a = 0;
var $b = 1;
var $i = 0;
var $max = 100;
public function __construct($n=100){
$this->max = $n;
}
@wjzhangq
wjzhangq / yield.py
Created February 17, 2011 12:59
python yield 用法
class Fib:
def __init__(self, max):
self.max = max
def __iter__(self):
self.a = 0
self.b = 1
return self
def next(self):
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
<?php
// " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) ";
//"SHOW GLOBAL VARIABLES LIKE 'ft\\_min\\_word\\_len'";
class normalizeText{
var $mMinSearchLength;
var $strictMatching = true;
var $searchTerms = array();
var $ignorecase = true;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>cross 跨域</title>
</head>
<body>
<input type='button' value='开始测试' onclick='crossDomainRequest()' />
<div id="content"></div>
function getRangePos(obj){
var Pos = 0; //ie
if (document.selection){
obj.focus();
var Sel = document.selection.createRange();
Sel.moveStart('character', -obj.value.length);
Pos = Sel.text.length;
}else if (obj.selectionStart || obj.selectionStart == '0'){
Pos = obj.selectionStart;
}
#!/usr/bin/env python
#
# Copyright 2009 Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#