Skip to content

Instantly share code, notes, and snippets.

View yuanchuan's full-sized avatar

Yuan Chuan yuanchuan

View GitHub Profile
@yuanchuan
yuanchuan / gist:2178390
Created March 24, 2012 04:51
The ring data structure
var Ring = (function() {
function Ring(list) {
this._list = [].slice.call(list, 0);
this._length = this._list.length;
this._curr = -1;
};
Ring.prototype = {
rollTo: function(idx) {
this._curr = idx % this._length;
if (this._curr < 0) this._curr += this._length;
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
/**
* 估算有多少人投票
*/
Math.round([].slice.call(
document.querySelectorAll(
'tbody td[bgcolor="#ffffff"]:nth-child(2)'
), 1)
.map(function(n){
return parseInt(
n.innerHTML.split(':(')[1]
@yuanchuan
yuanchuan / bad.js
Created December 28, 2011 03:37
get spark list
//bad
var sequence = (function(data, temp){
var len = data.length - 1;
for (var i = 0; i < len; ++i) {
temp.push(data[i+1] - data[i]);
}
return temp.join(',');
})((function(all, buf, user){
var len = all.length;
@yuanchuan
yuanchuan / index.html
Last active May 17, 2017 05:11
随机数
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<style>
body {
background: #333;
text-align: center;
}
#num {
@yuanchuan
yuanchuan / LICENSE.txt
Created December 22, 2011 01:36 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@yuanchuan
yuanchuan / build.py
Created December 10, 2011 06:09
document generator
#!/usr/bin/env python
# Get markdown module at: http://pypi.python.org/pypi/Markdown
from markdown import markdownFromFile
from string import Template
from datetime import datetime
import os
doc_path = 'document'
@yuanchuan
yuanchuan / gist:1330150
Created November 1, 2011 08:27
simple draggable using jquery
/**
* usage:
* $('div').draggable();
* $('*').draggable();
*/
$.fn.draggable = function() {
var $document = $(document)
, mouse = { update: function(e) {this.x = e.pageX; this.y = e.pageY;} };
@yuanchuan
yuanchuan / server.js
Created October 20, 2011 06:51
一个两小时的编程实践
#!/usr/bin/env node
var http = require('http')
, fs = require('fs')
, url = require('url')
, exec = require('child_process').exec
, qs = require('querystring')
, path = require('path');
@yuanchuan
yuanchuan / gist:1231163
Created September 21, 2011 03:29
login
#!/usr/bin/env node
var md5 = require('./md5.js').md5
, exec = require('child_process').exec
, username = process.argv[2] || ''
, password = process.argv[3] || ''
, getUrl = function(u, p) {
var href = '"http://xxx.xxx/xxx.php';
return href + '?uid=1&username=' + u + '&passwd=' + p + '&time=100192&flag=1"';
}