Skip to content

Instantly share code, notes, and snippets.

@StuPig
StuPig / truck_v2.js
Created February 16, 2014 07:40
转换为标准路径
/**
* 路径转换为标准路径
* @param path
* @return {String|XML}
*/
getRealPath: function (path) {
var DOT_RE = /\/\.\//g,
DOUBLE_DOT_RE = /\/[^\/]+\/\.\.\//;
// /a/b/./c/./d ==> /a/b/c/d
@StuPig
StuPig / water_ripple_canvas.js
Created February 8, 2014 02:27
Use JavaScript and canvas to create water ripple effect
/*
* Water Canvas by Almer Thie (http://code.almeros.com).
* Description: A realtime water ripple effect on an HTML5 canvas.
* Copyright 2010 Almer Thie. All rights reserved.
*
* Example: http://code.almeros.com/code-examples/water-effect-canvas/
* Tutorial: http://code.almeros.com/water-ripple-canvas-and-javascript
*/
@StuPig
StuPig / google.md
Created December 12, 2013 14:59
1. 解决google搜索结果页二次跳转的问题 2. 解决google被墙的问题
  1. 使用AdBlock去广告扩展的人,增加一条规则,变成多功能扩展,屏蔽香港域名跳转加入以下自订规则: ||google.com.hk$script,这样点搜索结果时就不会自动在url里加入google的链接了。注意根据你的搜索引擎是否是hk来去掉规则里面的hk
  2. 打开Chrome,在地址栏键入chrome://net-internals/,在HSTS选项卡下的Domain中输入你想要实现这个强制跳转的域名,例如你Chrome的默认搜索引擎是www.google.com,就在add domain里填写www.google.com,记得在下面的include subdomains打对勾,确保google的二级域名也是加密的,这样跳转结果页也是加密的,然后就可以打开结果页面了
  3. 将搜索引擎改为googlestable.com
@StuPig
StuPig / cache.js
Last active December 28, 2015 23:18
require localStorage plugin
/**
* USAGE:
* 外部定义全局变量 RSINFO = { 'path': 'version' }
*/
(function (win) {
var rslist,
RSLIST_KEY = 'rslist',
RSINFO = win.RSINFO || {},
isLocalStorageSupported = (function() {
@StuPig
StuPig / shell_scripts.sh
Last active December 28, 2015 17:48
shell 小脚本
# 查找当前文件夹及其子文件夹下包含某个字符串的某类型文件
# From http://www.ai7.org/wp/html/653.html
find . -name "*.js"|xargs grep require
@StuPig
StuPig / changeAlinks4iOS.html
Last active December 26, 2015 20:28
Prevent links in standalone web apps opening Mobile Safari. Reference: https://gist.github.com/kylebarrow/1042026#comment-37145 https://gist.github.com/irae/1042167
// add this inlined to <head> and before all <links>
<script>
(function(document,navigator,standalone) {
// prevents links from apps from oppening in mobile safari
// this javascript must be the first script in your <head>
if ((standalone in navigator) && navigator[standalone]) {
var curnode, location=document.location, stop=/^(a|html)$/i;
document.addEventListener('click', function(e) {
curnode=e.target;
while (!(stop).test(curnode.nodeName)) {
@StuPig
StuPig / dataStorage.js
Created October 12, 2013 12:21
localSorage封装,api借鉴了store.js,加入过期机制,和安全插入
/*jslint debug: true,
undef: false */
;(function(win, doc){
var localStorageName = 'localStorage';
var _util = {
isLocalStorageNameSupported: function() {
// 加try{}catch(){}的为了防止Firefox浏览器改配置dom.Storage = false时crash掉
try { return (localStorageName in win && win[localStorageName]) }
catch(err) { return false }
},
@StuPig
StuPig / parrallax_library_bookmark.markdown
Created September 3, 2013 03:03
视差动画库收集 A collection of parallax scrolling library bookmarks
@StuPig
StuPig / throttle.js
Created August 28, 2013 02:42
js方法执行频次限制(时间)
function throttle( fn, time ) {
var t = 0;
return function() {
var args = arguments, ctx = this;
clearTimeout(t);
t = setTimeout( function() {
fn.apply( ctx, args );
}, time );
};
@StuPig
StuPig / require.cache.js
Last active December 20, 2015 01:59
use ajax to load script
define(['module'], function (module) {
'use strict';
var storage = (function(){
var uid = new Date,
result;
try {
localStorage.setItem(uid, uid);
result = localStorage.getItem(uid) == uid;
localStorage.removeItem(uid);