Skip to content

Instantly share code, notes, and snippets.

@ambar
ambar / gist:1030979
Created June 17, 2011 06:55
如何保持chrome扩展选项tab唯一
// 打开chrome扩展选项tab
var option_url = chrome.extension.getURL('options/index.html');
chrome.tabs.getAllInWindow(null,function(tabs){
var option_tab = tabs.filter(function(t) { return t.url === option_url });
if(option_tab.length){
// 已经打开,直接激活
chrome.tabs.update(option_tab[0].id,{selected:true});
}else{
chrome.tabs.create({url:option_url,selected:true})
}
@ambar
ambar / browser_client.html
Created July 6, 2011 03:08
websocket的node实现笔记,http和tcp两版
<html>
<head>
<title>WebSocket Demo</title>
</head>
<style type="text/css">
textarea{width:400px;height:150px;display:block;overflow-y:scroll;}
#output{width:600px;height:400px;background:whiteSmoke;padding:1em .5em;color:#000;border:none;}
button{padding:.2em 1em;}
</style>
<link href="layout.css" rel="stylesheet" type="text/css" />
@ambar
ambar / a.js
Created July 18, 2011 06:54
如何在浏览器中动态插入的 JavaScript 文件中获取当前文件名?
var scripts = document.getElementsByTagName('script');
console.log('a.js',' >>> ',scripts[scripts.length -1].src);
console.log(__filename);
@ambar
ambar / emotion.html
Created August 4, 2011 04:48
jQuery.fn.emotion
<html>
<head>
<title>$.fn.emotion</title>
<style type="text/css">
/* comment (笑) */
</style>
</head>
<body>
@ambar
ambar / teleport.js
Created August 8, 2011 03:39
传送
var $anim = $(document[$.browser.webkit ? 'body' : 'documentElement']);
$btn.click(function() {
$anim.animate({scrollTop: 0});
return false;
});
@ambar
ambar / whatsthis.html
Created August 8, 2011 04:56
whatsthis
<html>
<head>
<title></title>
</head>
<body>
<script>
/*
jQuery.proxy和Function.prototype.bind作用一模一样。
@ambar
ambar / methods.js
Created August 10, 2011 09:35
$.validator.methods
$.validator.addMethod("phrange", function (value, element) {
if( $(element).attr('placeholder') === value ){
return true;
}
return $.validator.methods.range.apply(this,arguments);
}, "");
$.validator.addMethod("qq", function (value, element) {
if( $(element).attr('placeholder') === value ){
return true;
@ambar
ambar / getMaxZ.js
Created August 11, 2011 07:01
get max z-index under certain element
var getMaxZ = function(el) {
return Math.max.apply(null, $(el||document.body).children().map(function(){ return $(this).css('zIndex')>>>0; }).get())
};
@ambar
ambar / MantisEasyAssign.user.js
Created August 12, 2011 06:07
mantis human select, 安装(chrome,firefox):点击文件右边的"raw"按钮
// ==UserScript==
// @name MantisEasyAssign
// @author sean && ambar
// @namespace https://gist.github.com/1141552
// @version 1.3.0
// @description 友好的select,更容易把Bug扔给别人,哈哈
// @include http://mantis.dos123.com/view.php?id=*
// @include http://192.168.202.98/view.php?id=*
// @include http://mantis.dos123.com/view_all_bug_page.php*
// @include http://192.168.202.98/view_all_bug_page.php*
@ambar
ambar / about.md
Created August 12, 2011 09:51 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer