Skip to content

Instantly share code, notes, and snippets.

@yuest
yuest / ellipsis.js
Created March 27, 2011 11:56
A Text Ellipsis jQuery Plugin For Firefox
// A jQuery plugin to enable the text ellipsis in firefox.
// see http://yue.st/notes/code/js/ellipsis.en.html
// usage:
// $('.elementsNeedEllipsis').ellipsis();
// the elements should be block level ('display: block' or 'display: inline-block')
//
// I think you should take care of resize event by yourself,
// just call $('.elem').ellipsis() again after element resized.
$.fn.ellipsis = function () {
$(this).css({'white-space': 'nowrap', 'overflow': 'hidden'});
@yuest
yuest / non-blocking_gist_embed_code.js
Created March 27, 2011 12:57
Non-blocking gist embed code (jQuery implement)
// non-blocking GitHub Gist embed code jQuery plugin
// usage:
// 1. <div data-gist=your_gist_id><a href="http://gist.github.com/your_gist_id">your_gist_filename on GitHub Gist</a></div> in html
// 2. $('<div/>').embedGist(your_gist_id).appendTo('article'); in javascript
;(function ($) {
$.fn.embedGist = (function () {
var gistWriteFunc = {},
gistWrited = {},
addGist = function (gistId, $el) {
if (!gistWriteFunc[gistId]) {
@yuest
yuest / tamper.js
Created November 24, 2011 05:05
A simple online debug tool for frontend developer, like fiddler2 on Windows.
/*
* tamper.js -
*
* author: yuest
* description:
*
*/
var http = require('http'),
fs = require('fs'),
path = require('path'),
var rl = require('readline').createInterface(process.stdin, process.stdout)
, fs = require('fs')
, path = require('path')
, util = require('util')
function copyFileByPump (file, remainFiles, destDir) {
var destFile = path.join(destDir, file)
, streamIn = fs.createReadStream(file)
, streamOut = fs.createWriteStream(destFile)
util.pump(streamIn, streamOut, function (err) {
@yuest
yuest / dirs_files.js
Created March 1, 2012 09:33
列出目录下的所有目录和文件
exports.dirs_files = function dirs_files(dir, callback) {
var returned = false
, result = { dirs: [], files: [] }
, remaining = 1
if ('function' === typeof dir) {
callback = dir
dir = '.'
}
if ('.' === dir[0]) {
@yuest
yuest / document.getComments.js
Created March 1, 2012 11:12
获取文档中所有注释节点
document.getComments = function getComments(pnode, result) {
pnode = pnode || document.documentElement
result = result || []
var cnodes = pnode.childNodes
, cnode, i
for (i = -1; (cnode = cnodes[++i]); ) {
if (cnode.nodeType !== 8) {
getComments(cnode, result)
} else {
@yuest
yuest / fuckgfw.ico
Created August 12, 2012 04:36
在 Windows 7 上 建立 ssh -D 快捷方式 - blogist.yue.st
@yuest
yuest / readme.mkd
Created August 16, 2012 04:50
Lisp 之根本 - blogist.yue.st

大名鼎鼎的 Paul Graham 写过一篇《The Roots of Lisp》,讲解他对 Lisp 根源的理解。这篇文章我在很多年前就试图阅读,但是都不大能读懂,直到去年年末时候我读了几十年前的 Lisp 1.5 手册的相关部分,终于算是理解了。再读一遍 pg 的文章,也就完全能懂了。现在结合自己的理解尝试把这些概念重述一遍。这篇文章就是想以自己的话语阐述一遍这些基本概念。这里会偏重于数学式的思维训练而不是实用性的程序编写,所以和实际情况会稍有出入。计划写两部分,第一部分是7个原始操作,第二部分讲实现 Lisp 解释器。

在 lisp manual 里面,我看到 John 使用了一种数学人很喜欢的表述方式,就是先定义符号和规则,然后在这套规则下让我们来看看我们可以怎么玩。有一点数学基础的人可能就会觉得这样理解会很容易。

##基本定义

首先定义符号,为了简化,我在这篇文章里就定义可用的符号26 个小写字母、10个数字、空格、左右圆括号和单引号

然后我们定义原子(atom),原子就是由字母和数字组成序列并且只能由字母开头,比如 abc123,比如 foo 或 bar 都是原子。