Skip to content

Instantly share code, notes, and snippets.

View yuanchuan's full-sized avatar

Yuan Chuan yuanchuan

View GitHub Profile
@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 / index.html
Created December 26, 2019 03:32
Matrix digital rain (animated version)
<main></main>
@yuanchuan
yuanchuan / index.html
Last active October 19, 2018 07:31
Alien land
<css-doodle>
:doodle {
@grid: 20x1 / 60vmin;
overflow: hidden;
}
:container {
transform: scale(25);
filter: @svg-filter(<svg>
<filter>
<feTurbulence baseFrequency="@r(.016, .056, .001)" seed="@r(100)" numOctaves="@r(8, 15)" />
@yuanchuan
yuanchuan / pattern-matching.js
Last active January 12, 2018 15:14
Erlang-like pattern matching in JavaScript
const MARK = {
symbol: {
name: '__mark__',
type: 'condition',
},
add(fn) {
let { name, type } = this.symbol;
let addon = { [name]: type };
return Object.assign((...args) => fn(...args), addon);
},
@yuanchuan
yuanchuan / lambda.js
Last active October 28, 2017 06:28
fun
const assert = require('assert');
const cons = (a, list) => _cons => _cons(a, list);
const car = list => list(head => head);
const cdr = list => list((_, tail) => tail);
const nil = () => null;
const is_nil = list => car(list) === nil();
const length = list =>
is_nil(list) ? 0 : 1 + length(cdr(list));
@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 / gist:2586540
Created May 3, 2012 15:33
Watch a directory recursively
/**
* Watch a directory recursively
*
* @param {String} dir
* @param {Function} cb
*
* watchRecursive('directory', function(current) {
* console.log(current, ' changed');
* });
*/
@yuanchuan
yuanchuan / gist:5641197
Created May 24, 2013 03:54
note for ie8 quirks
/* Both */
li:last-child, li.last-child {
border: none;
}
/* AND */
li.last-child, li:last-child {
border: none;
/**
* 1. 打开百姓网首页,http://www.baixing.com
* 2. 把下面这段代码复制到控制台并运行(需要chrome :D),
* 3. 然后鼠标移动到 LOGO 上可以看到效果
*/
(function() {
if (!document.createElement('canvas').getContext) return false;
/**
例如 prezero(200) 返回 0200
*/
var prezero = function(number) {
var str = number.toString(10);
var len = str.length;
while((len++) < 4) {
str = '0' + str;