Skip to content

Instantly share code, notes, and snippets.

@ambar
ambar / teleport.html
Created August 23, 2011 07:21
teleport 无限卷动的内容
<html>
<head>
<title></title>
<style type="text/css">
#list{width:500px;height:auto;background-color: #eee;}
.ph{width:500px;height:600px;background-color: #cde;margin:2em 0;}
</style>
</head>
<body>
<div style="height:100px;background:#cde;">placeholder1</div>
@ambar
ambar / jQuery.data.compatibility.html
Created August 25, 2011 08:42
jQuery data compatibility
<html>
<head>
<title></title>
</head>
<body>
<div data-ID="3" data-blogId="4" data-comment-id="4" data-cat_id="5"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
@ambar
ambar / benchmark.js
Created September 22, 2011 08:31
detect size of call stack
/*
var iter = 100 * 100;
bm('instanceof',iter,function() {
f instanceof Function
})
bm('typeof',iter,function() {
typeof f === 'function'
})
*/
@ambar
ambar / throttle.js
Created October 23, 2011 04:55
throttle and debounce
/*
* 频率控制 返回函数连续调用时,action 执行频率限定为 次 / delay
* @param delay {number} 延迟时间,单位毫秒
* @param action {function} 请求关联函数,实际应用需要调用的函数
* @param tail? {bool} 是否在尾部用定时器补齐调用
* @return {function} 返回客户调用函数
*/
var throttle = function(delay,action,tail,debounce) {
var now = Date.now, last_call = 0, last_exec = 0, timer = null, curr, diff,
ctx, args, exec = function() {
// ==UserScript==
// @name Disguise Surfing
// @namespace anonymous
// @description 伪装上网模式
// @version 0.1
// @include *
// ==/UserScript==
// make array
var $A = function(obj) { return [].slice.call(obj) }
@ambar
ambar / ie6_crash.html
Created December 21, 2011 12:32
如何改善百度统计引入代码
<html>
<head>
<title></title>
</head>
<body>
<div>
<script>
document.body.appendChild( document.createElement('script') )
</script>
@ambar
ambar / gist:1534274
Created December 29, 2011 14:15 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@ambar
ambar / dabblet.css
Created January 5, 2012 13:40
❤ dabblet.com CSS3 playground!
/**
* ❤ dabblet.com CSS3 playground!
*/
html{
font-family: Monaco;
transform: scale(2,.5) rotate(30deg);
background-color: silver;
background-size: 58px 58px;
background-position: 0px 2px, 4px 35px, 29px 31px, 34px 6px;
@ambar
ambar / calc.md
Created January 9, 2012 07:24
sticky element
marginLeft = - ( $container.width() / 2 - parseInt($g.css('right')) - $g.innerWidth() ) = -(450 + 200 - 156)
@ambar
ambar / _.js
Created January 10, 2012 04:04
图片墙和 Bin Packing
var BinPacker = require('./binpacker')
var blocks = []
blocks.push(
// 宽的
{w: 300,h: 390},
{w: 300,h: 390},
// 窄的
{w: 150,h: 195},