Skip to content

Instantly share code, notes, and snippets.

@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 / storage-usage.js
Last active January 3, 2019 04:06
支持localStorage设置过期时间功能的封装代码
// expires方法的参数是以秒为单位的,其他的方法跟localStorage的相同
// 方法有:getItem/setItem/removeItem/clear/expires
// 30秒后过期
storage.setItem("test","hello world").expires(30);
storage.setItem("test","hello world");
storage.expires(30);
// clear全部由storage创建的localStorage
@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");
@supersha
supersha / safy-selenium-python-driver-usage.js
Created July 5, 2013 07:16
Safy平台中,为QA准备的selenium python的driver API,因为QA都习惯使用python在selenium中写单侧,所以创建JS版本的,方便QA写单侧。
//driver这个对象是内置的,在编写单侧代码的时候直接调用即可,它包含上面罗列的方法,上面的方法调用后,
//返回一个webElement的对象,webElement还可以继续调用上面的方法,获取子元素、获取属性值、each、click、submit等更多的操作
//driver.find_element_by_id()
var input = driver.find_element_by_id("kw");
should(input.get_attribute("value")).be().equal("123").error("xxxx");
//driver.find_element_by_name()
//获取一个name
var input = driver.find_element_by_name("kw");
@supersha
supersha / page-checker-usage.js
Last active December 19, 2015 19:38
检查页面不符合最佳实践的方面
//检查全部
inspect.check();
//检查指定的任务
inspect.check("check-meta-charset");
//检查多个任务
inspect.check(["check-meta-charset","check-doctype"]);
@supersha
supersha / nohup.js
Created October 10, 2013 05:56
nohup run node.js
var fs = require('fs'),
exec = require('child_process').exec,
isWin = process.platform.indexOf('win') === 0;
function nohup(cmd, options, callback){
if(typeof options === 'function'){
callback = options;
options = null;
}
if(isWin){
// 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) });
};
@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")