Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kainy's full-sized avatar
:octocat:
Q Tiu HiuMiuLiu

Kainy Guo kainy

:octocat:
Q Tiu HiuMiuLiu
View GitHub Profile
@kainy
kainy / obfuscate.js
Created March 19, 2019 13:02 — forked from olastor/obfuscate.js
Simple algorithm to quickly obfuscate a string in javascript.
/**
* Obfuscate a plaintext string with a simple rotation algorithm similar to
* the rot13 cipher.
* @param {[type]} key rotation index between 0 and n
* @param {Number} n maximum char that will be affected by the algorithm
* @return {[type]} obfuscated string
*/
String.prototype.obfs = function(key, n = 126) {
// return String itself if the given parameters are invalid
if (!(typeof(key) === 'number' && key % 1 === 0)
@kainy
kainy / gulpfile.js
Created December 25, 2017 09:16
使用workbox生成SW脚本的gulpfile配置。
gulp.task('sw', ['copy', 'css', 'js', 'img'], () => {
return wbBuild.generateSW({
globDirectory: './www/',
swDest: './optimized/sw.js',
globPatterns: ["**/*.{css,jpg,png,js,html,shtml}"],
ignoreUrlParametersMatching: [/(v|t)/],
skipWaiting: true,
clientsClaim: true,
runtimeCaching: [{
urlPattern : 'https://API-Url/(.*)',
const path = require('path');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
let distConfig = require('./webpack.config');
distConfig.output.path = path.resolve(__dirname, 'public/cdn');
distConfig.output.publicPath = '//url.cn/';
distConfig.output.filename = '[chunkhash].js';
distConfig.resolve.alias = {
'moment': 'moment/min/moment.min.js',
@kainy
kainy / otitle.js
Last active April 29, 2016 03:21
显示页面上otitle埋点的元素(webtrends埋点验证)
javascript: (function() {
[].forEach.call(document.querySelectorAll('*[otitle]'), function(a) {
a.title= 'otitle内容:【 '+ a.getAttribute('otitle')+' 】';
setInterval(function(){
a.style.outline = "2px solid #" + (~~(Math.random() * (1 << 12))).toString(16)
}, 100)
}, 6);
})();
@kainy
kainy / harlem-shake.js
Last active December 27, 2015 09:14 — forked from commadelimited/harlem-shake.js
Harlem Shake Bookmarklet deconstructed
javascript: (function () {
function c() {
var e = document.createElement("link");
e.setAttribute("type", "text/css");
e.setAttribute("rel", "stylesheet");
e.setAttribute("href", f);
e.setAttribute("class", l);
document.body.appendChild(e)
}
function h() {
@kainy
kainy / ieImg.html
Created October 9, 2013 08:00
通过vml解决IE下图片缩小失真(有锯齿)的问题。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>解决IE下图片缩小失真(有锯齿)的问题_西山刀客</title>
<style>
img{ width:24px; height:24px;}
.ie7{-ms-interpolation-mode:bicubic;display:none;}

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta charset='UTF-8'>
<meta name='keywords' content='your, tags'>
<meta name='description' content='150 words'>
<meta name='subject' content='your website's subject'>
<meta name='copyright' content='company name'>
@kainy
kainy / gmail-scrollbars.css
Created November 14, 2012 15:43 — forked from jambu/gmail-scrollbars.css
New Gmail like scrollbars for webkit browsers
/* Gmail style scrollbar */
::-webkit-scrollbar {
height:16px;
overflow:visible;
width:16px
}
::-webkit-scrollbar-button {
height:0;
width:0
}
@kainy
kainy / gist:1142337
Created August 12, 2011 15:52
Incorrect ES5 fallbacks

Incorrect ES5 fallbacks

Over the weekend I implemented a few Array methods in plain JavaScript to avoid recently patched Rhino bugs. That got my thinking about ES5 fallback implementations in various JavaScript libs/frameworks/transpilers. I decided to compile a not-so-complete list of ES5 related discrepancies found in many of them. Differences in native vs. fallback implementations create cross-browser inconsistencies and increase the chance of usage errors. I hope this post will raise awareness of just how hard it is to follow spec (during my research I found a couple of issues in my own projects too). All library developers should to take a closer look at their code and make the small changes needed to follow the specification (especially if your code forks for native methods).

Common Issues

Most implementations suffer from the foll