Skip to content

Instantly share code, notes, and snippets.

@supersha
supersha / scrollbar.js
Last active January 25, 2016 07:52
总是让浏览器显示滚动条,但是页面又不能滚动的问题
// 有时候的场景是,弹窗之后,页面不能滚动,但是如果在有滚动条的情况下,滚动条消失,页面会左右晃动
// 要让滚动条一直都存在,解决的办法如下:
// 在某个元素focus的时候,设置document.documentElement.style.overflow = 'hidden'; 但是设置document.body.style.overflow = 'scroll';
// 在元素blur的时候,再重置回来auto
ue.addListener('focus', function(editor){
$(document.body).css('overflow', 'scroll');
document.documentElement.style.overflow = 'hidden';
});
@supersha
supersha / 0 - README.md
Created September 23, 2015 02:47 — forked from JamesMGreene/0 - README.md
PhantomJS: Conceptual implementation of a short-term shim to establish the window.postMessage API for IPC

Topic

Providing an inter-process communication (IPC) mechanism such that a WebPage can explicitly signal back to PhantomJS as a push, thus eliminating/minimizing the need for users to setup polling functions, etc.

In PhantomJS 1.6, @detro added a WebPage onCallback handler that could be triggered from a webpage client by invoking the specially attached window.callPhantom function. However, @ariya expressed some discontent with this approach and so the three of us began discussing utilizing an existing API for cross-domain messaging instead: window.postMessage. (See Discussion for more info.)

Problems

PhantomJS currently only allows for a single handler per signal (a separate problem I'm working on over here). As such, automatically attaching internal handler may prevent users from attaching their own handlers for onInitialized (tha

@supersha
supersha / cache.js
Last active August 29, 2015 14:26 — forked from bshamric/cache.js
I like phantomjs, but it doesn't directly support getting images from webpages without requesting them separately like in casperjs. I went through QTNetworking code in the phantomjs repo until I figured out where the cache was. To use this, have all three files in the same directory. Then modify test.js for whatever you need. Call phantom js wit…
var fs = require('fs');
//this is the path that QTNetwork classes uses for caching files for it's http client
//the path should be the one that has 16 folders labeled 0,1,2,3,...,F
exports.cachePath = '/path/to/phantomjs/cache/data/folder';
//this is the extension used for files in the cache path
exports.cacheExtension = "d";
//the resources that are to be saved
@supersha
supersha / ip.js
Created July 20, 2014 15:19
获取mac下的ip地址
#! /usr/bin/env node
var exec = require("child_process").exec;
exec("ifconfig", function(err, stdout){
if(err){ console.log(err); return; }
var string = stdout;
//inet 10.68.141.98 netmask 0xfffffc00 broadcast 10.68.143.255
@supersha
supersha / publish.sh
Last active December 24, 2015 19:02
命令行直接发布当前的git分支到日常/线上
#! /bin/bash
gitStatus=`git status | grep -E 'On branch daily\/(\d+\.\d+\.\d+)'`
currentBranch=${gitStatus/On branch daily\//}
while getopts "v:m:o" arg
do
case $arg in
v)
#echo "v's arg:$OPTARG"
//减法运算的函数. 修正了 js的减法运算. 但小数位不得超过6位 否则toFixed 可能会舍去超出部分 除非前6位中至少有1位具备有效数字
function sub(arg1, arg2) {
var r1, r2, m, n;
try { r1 = arg1.toString().split('.')[1].length } catch (e) { r1 = 0 }
try { r2 = arg2.toString().split('.')[1].length } catch (e) { r2 = 0 }
m = Math.pow(10, Math.max(r1, r2));
//动态控制精度长度
n = (r1 >= r2) ? r1 : r2;
return parseFloat(((arg1 * m - arg2 * m) / m).toFixed(n));
}
local ret_status="%(?:%{$fg_bold[green]%}?~^~\ :%{$fg_bold[red]%}?~^~\ %s)"
PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}?~\~W%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})%{$fg[green]%} ?~\~T %{$reset_color%}"
ZSH_THEME_GIT_PROMPT_ADDED="%{$FG[082]%}?~\~Z%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_MODIFIED="%{$FG[166]%}?~\?%{$reset_color%} "
var walk = function(path) {
fs.readdirSync(path).forEach(function(file) {
var newPath = path + '/' + file;
var stat = fs.statSync(newPath);
if (stat.isFile()) {
if (/(.*)\.(js$|coffee$)/.test(file)) {
require(newPath);
}
} else if (stat.isDirectory()) {
walk(newPath);
@supersha
supersha / router-express-usage.js
Last active December 29, 2015 05:39
给express的router封装一下,使得可以按照目录指定router,这样之后就可以直接在相应的目录下直接添加文件,就可以访问,而无需关注router的问题。
var routerExpress = require("router-express"),
express = require("express");
var app = express();
routerExpress.express(app);
routerExpress.add("/restart")
.add("/api/*.json", "app/api")
.add("/tool/*", "app/tool")
// cross-browser events
function addEvent(object, event, method) {
if (object.addEventListener)
object.addEventListener(event, method, false);
else if(object.attachEvent)
object.attachEvent('on'+event, function(){ method(window.event) });
};