Skip to content

Instantly share code, notes, and snippets.

// 计算奶牛
// 初始 1 头奶牛,奶牛在 1 岁和 4 岁的时候生小牛(假设全部为母牛),5 岁时死亡,求给定的年数奶牛的数量。
// 以下是我演算的各个方法。
// 01
var YEARS = arguments.length > 0 && parseInt(arguments[0], 10) || 10;
var cows = {},
cow;
// 简单的验证 html 代码的闭合
var html = editor.val();
var html2 = html,
test_re = /<\/\w[\w1-6]{0,10}>|<\w[\w1-6]{0,10}[^>]*>/g;
html2 = html2.replace(/<!--(.|\n|\r\b)*?-->/g, '')
.replace(/<script(.|\n|\r\b)*?<\/script>/g, '');
// js
// double 节点内容(为连续滚动做准备)
var div = $('#someid')[0];
// method 1
var chls = div.childNodes,
chlsL = chls.length;
for (var i=0; i < chlsL; i++) {
# fetch and edit and save it back
curl http://blog.chlean.net/misc/resume-Kindy.lin.v3.html | mate -w - | godaddy "~/bin/cat2misc resume-Kindy.lin.v4.html"
<script type="text/javascript" src="/library/common/bpopup/main.js,.dss?oe=gb2312"></script>
<script type="text/javascript">
jQuery(function(jq){
var cfg={
width : 331,
height : 233,
minheight : 62,
closable : 1,
minable : 1,
bottom : 5,
# jquery/selector/dir
# 这样的东西很有智慧,跟 python/os.walk 一样
function dir( elem, dir ) {
var matched = [],
cur = elem[dir];
while ( cur && cur != document ) {
if ( cur.nodeType == 1 )
matched.push( cur );
cur = cur[dir];
# python/os.walk
def walk(top, topdown=True, onerror=None):
from os.path import join, isdir, islink
# We may not have read permission for top, in which case we can't
# get a list of the files the directory contains. os.path.walk
# always suppressed the exception then, rather than blow up for a
# minor reason when (say) a thousand readable directories are still
#!/bin/bash
# any2mp3.sh, :)
# http://ch-linghu.3322.org/temp/any2mp3.sh.txt
if [ $# == 0 ]; then
echo "USAGE: any2mp3 input [output]"
echo "if output is ignore, input name plus mp3 postfix will be used"
exit
fi
if [ $# == 1 ]; then
#!/usr/bin/env python
#web 资源、模板管理
schema = [
# user
Table('user', key=('id', 'username'))[
Column('id', auto_increment=True),
Column('username', type='varchar', size='50'),
Column('time', type='int'),
//模板解析
//http://kingcms.googlecode.com/svn/trunk/upload/system/lib/template.class.php
var s = /\{((\w+):([\w\.]+))([^}]*)\/\}|\{((\w+):([\w\.]+))([^}]*)\}(?:.|\n)*\{\/\5\}/g;
var st = '<p>\n来源:\n{king:_source}\n<a href="{king:val.2/}" target="_blank">{king:val.1/}</a>\n{/king:_source}\n\n<!--- 插入正常PHP代码,echo输出 ---->\n<?php\nif(\'{king:title/}\'){\n echo "<p>有标题</p>";\n}else{\n echo "<p>标题呢?<p>";\n}\n?>\n\n</p>';
st.match(s);
/*