Skip to content

Instantly share code, notes, and snippets.

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);
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%} "
//减法运算的函数. 修正了 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));
}
@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 / 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 / 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 / ace-autocomplete-plugin-usage.js
Last active December 15, 2015 08:29
给ACE编辑器创建的一个AutoComplete编码功能,方便编写代码。
// 初始化autocomplete dialog的各项功能
// items参数就是complete框默认可见多少项
// editor参数是ACE的实例化对象
var autocomplete = new AceAutoComplete(editor,{
items : 10
});
//来源:http://www.cnblogs.com/Random/archive/2013/03/29/2989789.html
function fireKeyEvent(el, evtType, keyCode){
var evtObj;
if(document.createEvent){
if( window.KeyEvent ) {
evtObj = document.createEvent('KeyEvents');
evtObj.initKeyEvent( evtType, true, true, window, false, false, false, false, keyCode, 0 );
} else {
evtObj = document.createEvent('UIEvents');
@supersha
supersha / transform-rotateY.js
Last active December 19, 2015 07:19
dev-park.com博客在iOS下的根据设备的螺旋仪在rotateY的倾斜效果
var DeviceOrientation = (function(win){
var targetElement = null,
isRotate = false;
function deviceOrientationHandler(eventData){
var lr = -Math.round(eventData.gamma),
maxRotateY = 15;
// 去燥
//should介词
should("xxx").be()
should("xxx").not()
should("xxx").and()
should("xxx").have()
should(xxx).has()
//should(xxx).have().property
should({name : 1}).have().property("name").fail(function(){
monitor.sendError("have not property");