Skip to content

Instantly share code, notes, and snippets.

View yuanchuan's full-sized avatar

Yuan Chuan yuanchuan

View GitHub Profile
var imageList=(function(){
var _list=[],_head;
$('#imageList li').each(function(){
_list.push($(this));
});
_head=_list[0];
return {
(function(str){
var maxPalin='';
for(var i=0,len=str.length;i<len;++i){
var letter=str[i],substr;
for(var j=i;j<len;++j){
if(letter == str[j]){
maxPalin=(function(substr){
return (function(substr){
@yuanchuan
yuanchuan / Generate html tags in php.php
Created October 23, 2010 09:10
Generate html tags
<?php
/*
* 快速生成 html 标签
* version: 0.01
* Created: 2010/10/23
*
* TODO: 1.精简函数代码,一般单个函数的长度不超过一屏
* 2.增加容错处理
* 3.<link /> <img /> <br /> 没有考虑进去, 待补充,
/**
* Get random charactor from a given charset
*/
var getRandomChar = (function(str) {
var len = str.length;
return function() {
return str.charAt(Math.floor(Math.random() * len));
};
function new_array(/* length */ len, /* default */ value) {
var len = ~~len;
return value
? new Array ( len + 1 ).join( value ).split( '' )
: new Array ( len );
}
@yuanchuan
yuanchuan / gist:833201
Created February 18, 2011 03:25
An interesting question
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title> An interesting question</title>
<style>
table {
border-collapse:collapse;
border-spacing:0;
margin: 100px auto 0;
@yuanchuan
yuanchuan / gist:868937
Created March 14, 2011 09:30
self-closed iframe problem
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Test -- self-closed iframe problem</title>
<script>
/* quick and dirty */
function log(info) {
return window.console
? console.log.apply(console,arguments)
@yuanchuan
yuanchuan / gist:871830
Created March 16, 2011 00:58
rinting 1 to 1000 without loop or conditionals
//Printing 1 to 1000 without loop or conditionals
//http://stackoverflow.com/questions/4568645/printing-1-to-1000-without-loop-or-conditionals/4583502#4583502
// using replace
(function(max){
new Array(max + 1).join(' ').replace(/\s/g, function(c, i){
console.log(i + 1);
})
})(1000)
function range(start, stop, step) {
var range = [];
stop || (stop = start || 0, start = 0);
step || (step = 1);
while ((step > 0 && start < stop) || (step < 0 && start > stop)) {
range.push(start);
start += step;
}
return range;
};
@yuanchuan
yuanchuan / gist:985699
Created May 22, 2011 17:41
jQuery live('submit') and disabled submit button
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery live('submit') and disabled submit button </title>
<style>
form {margin-bottom:50px;}
</style>
</head>