Skip to content

Instantly share code, notes, and snippets.

@wintercn
wintercn / adhocSort.js
Created September 30, 2013 03:19
假期前小玩意,ad-hoc排序
function shuffle(array){
for(var i = array.length-1; i > 0; i--) {
var rnd = Math.floor(Math.random() * (i+1));
var tmp = array[i];
array[i] = array[rnd];
array[rnd] = tmp;
}
}
function isInOrder(array) {
for(var i = 0; i < array.length-1; i++)
@wintercn
wintercn / template.html
Created September 29, 2013 14:52
一个简单的dom型模板示例
<div>
<a href="{{protocol}}//{{host}}{{pathname}}">{{protocol}}//{{host}}{{pathname}}</a>
</div>
<script>
function Template(node) {
var prototype = document.createDocumentFragment();
prototype.appendChild(node);
@wintercn
wintercn / pylexer.html
Created September 24, 2013 15:02
python词法分析
<body>
<style>
.number {
color:purple;
}
.keyword {
color:blue;
}
.string {
@wintercn
wintercn / gist:6666747
Created September 23, 2013 05:28
Web API里可以new的东西
//Chrome上能用的
["Image", "Audio", "MediaController", "TrackEvent", "Option", "PopStateEvent", "HashChangeEvent", "PageTransitionEvent", "Event", "CustomEvent", "MutationObserver", "Document", "FormData", "XMLHttpRequest", "FormData", "IDBVersionChangeEvent", "StorageEvent", "RTCSessionDescription", "RTCIceCandidate", "MediaStreamEvent", "Notification", "Blob", "FileReader", "ErrorEvent", "Worker", "SharedWorker", "TransitionEvent"]
//标准里有但是还不能用的
["RelatedEvent", "DragEvent", "AnonXMLHttpRequest", "RTCPeerConnection", "RTCPeerConnectionIceEvent", "DataChannelEvent", "ClipboardEvent", "FileReaderSync", "BlobBuilder", "FileSaver", "ParGroup", "SeqGroup", "Animation", "PseudoElementReference", "KeyframeAnimationEffect", "PathAnimationEffect", "TimingEvent", "AnimationEvent"]
function run(code,callback){
callback = callback || function(r){
//console.log(r);
};
function check(f){
if(f instanceof Function) {
@wintercn
wintercn / local.md
Created July 21, 2013 14:45
浅谈代码的局部性

我是JS中"就近声明"以及"允许多次var声明"的拥护者。

我持这样观点源自我对易读性的追求。

看一段代码:

function aFunc() {
    for(var i = 0; i < 100; i++) {
 doSth(i);
[
{
name:"HTML5",
uri:"http://www.w3.org/TR/html5/single-page.html",
category:"markup"
},
{
name:"HTML 5.1",
uri:"http://www.w3.org/TR/html51/single-page.html",
category:"markup"
@wintercn
wintercn / gist:5918272
Created July 3, 2013 14:18
CSS3 标准和属性对应数据
[
{
"spec name": "CSS Animations",
"uri": "http://www.w3.org/TR/css3-animations",
"category": "css-property",
"Name": "animation-name",
"Value": "<single-animation-name> [\n ‘,’ <single-animation-name> ]*",
"Initial": "‘none’",
"Applies To": "all elements, ::before and ::after pseudo-elements",
"Inherited": "no",
@wintercn
wintercn / HTMLLexicalParser.js
Last active August 5, 2019 11:16
HTML语法分析器模型
function StartTagToken(){
}
function EndTagToken(){
}
function Attribute(){
}
@wintercn
wintercn / showboxes.js
Created May 21, 2013 06:34
显示页面的盒结构
function randomColor(){
return "rgb("+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+")";
}
function showBoxes(window) {
var rects = [];
function getRects(node){
var range = window.document.createRange();
range.setStartBefore(node);
range.setEndAfter(node);