Skip to content

Instantly share code, notes, and snippets.

@chshouyu
chshouyu / surge_main.conf
Created October 26, 2015 15:20 — forked from jason5ng32/surge.conf
Surge Configs ( Both 2 files are needed )
[General]
loglevel = notify
skip-proxy = 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12,127.0.0.0/24,100.64.0.0/10
bypass-tun = 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12,127.0.0.0/24,100.64.0.0/10
// DNS OVERRIDE, REMOVE # IF YOU NEED
# dns-server = 223.6.6.6,223.5.5.5,114.114.114.114,114.114.115.115
[Rule]
@chshouyu
chshouyu / formatjson.js
Created April 1, 2014 05:10
格式化json原理
function output(inp) {
document.body.appendChild(document.createElement('pre')).innerHTML = inp;
}
function syntaxHighlight(json) {
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
@chshouyu
chshouyu / Decare.js
Created November 27, 2013 07:13
各种牛逼闪闪的效果
// 笛卡尔心形线
(function(window, document, undefined) {
var middle = {}, r = 60,
R = 50,
ctx = (function getContext(width, height) {
var c = document.createElement('canvas');
c.width = width;
c.height = height;
middle.x = width / 2;
middle.y = height / 2;
@chshouyu
chshouyu / ie6.html
Created November 13, 2013 08:51
ie6 css sprites重复避免加载
<!--[if IE 6]>
<script type="text/javascript">
document.execCommand("BackgroundImageCache",false,true);
</script>
<![endif]-->
@chshouyu
chshouyu / addFavorite.js
Created November 13, 2013 07:56
加入收藏和设置首页
function addFavorite() {
if(document.all) {
try {
window.external.addFavorite(window.location.href, document.title);
} catch(e) {
alert("加入收藏失败,请使用Ctrl+D进行添加");
}
} else if(window.sidebar) {
window.sidebar.addPanel(document.title, window.location.href, "");
@chshouyu
chshouyu / index.html
Created November 13, 2013 07:19
纯CSS无表达式实现图片等比缩放(支持IE7及以上)
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>JavaScript实现图片等比缩放</title>
</head>
<body>
<script type="text/javascript">
function resize(element, maxWidth, maxHeight){
if(element.width > maxWidth || element.height > maxHeight){
@chshouyu
chshouyu / undefined.js
Created November 12, 2013 13:19
// 防止外部undefined被修改
// 防止外部undefined被修改
// 方法1
var undefined = 123;
(function(something, foo, undefined) {
// 局部作用域里的 undefined 变量重新获得了 `undefined` 值
})('Hello World', 42);
// 方法2
var undefined = 123;
(function(something, foo) {
@chshouyu
chshouyu / chrome-util.js
Created November 12, 2013 06:56
chrome浏览器里摘出来的 主要看点: 1.函数写法 2.变量命名 3.每行基本控制在80字符之内等等
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Utilities for rendering most visited thumbnails and titles.
*/
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function NewGuid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
function repeat(fn, times, delay) {
return function() {
if(times-- > 0) {
fn.apply(null, arguments);
var args = Array.prototype.slice.call(arguments);
var self = arguments.callee;
setTimeout(function(){self.apply(null,args)}, delay);
}
};
}