Skip to content

Instantly share code, notes, and snippets.

View kerryChen95's full-sized avatar

kerryChen95 kerryChen95

  • AutoX
  • Beijing, China
View GitHub Profile
@kerryChen95
kerryChen95 / regexp.js
Created December 2, 2013 11:14
RegExp for English & Chinese usual sentence. It was written when I change my fucking annotation style.
// RegExp for English & Chinese usual sentence, which is reuseable
[\s\w\。\,\、\`\:\~\`\!\@\#\$\%\^\&\*\(\)\-\_\+\=\{\}\[\]\|\;\:\"\'\<\>\,\.\/\?]*?\n
// Whole RegExp for change my fucking annotation style, which is:
// /**
// * balabala
// * foo
// **/
// search via it and replace with $1$3 **twice**, and than there is a new annotation style:
@kerryChen95
kerryChen95 / currentStackAndLine.js
Last active September 28, 2022 03:17
Get current stack and line number in JavaScript
// For V8:
// Define global variable `__stack__` and `__line`
// for current stack and line
(function(global){
Object.defineProperty(global, '__stack__', {
get: function(){
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack){ return stack; };
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
@kerryChen95
kerryChen95 / evaluateTeaching.js
Last active December 29, 2015 02:39
UESTC evaluate teaching script
(function evaluate(){
var ifr = document.querySelector('#iframeautoheight'),
ifrDoc = ifr.contentDocument,
selects = ifrDoc.querySelector('#DataGrid1').querySelectorAll('.select'),
i, l,
options,
submitBtn = ifrDoc.querySelector('#Button2');
if( submitBtn.value.search(/提\s*交/) === -1 ){
for(i = 0, l = selects.length; i < l; ++i){
.wrapper {
width:90%;
margin: auto;
overflow: hidden;
zoom: 1;
background: beige;
}
.nav {
float: left;
@kerryChen95
kerryChen95 / dabblet.css
Created May 16, 2013 18:29 — forked from kejun/dabblet.css
sample-1缺点 + 必须固定高度
body {
width: 600px;
font:normal 14px/1.62 arial, sans-serif;
}
.mod {
margin-bottom:100px;
background-color:#efc;
}
.pic {
margin-right: 20px;
function shuffle (source) {
return source.slice().sort(function (a, b) {
return Math.random() < 0.5 ? -1 : 1;
});
}
var arr = Array.apply(null, new Array(3 * 54))
.map(function (val, i) { return i; });
console.log( shuffle(arr) );
@kerryChen95
kerryChen95 / dabblet.css
Last active December 15, 2015 19:39
水平居中浮动元素
.box{
float:left;
position:relative;
left:50%;
}
p{
float:left;
position:relative;
right:50%;
}
function sendLog (urlWithLog) {
var img = new Image(), no, caches;
if (sendLog.count >= Number.MAX_VALUE) sendLog.count = 0;
no = 'no' + sendLog.count++;
caches = sendLog.caches;
// hold on reference, otherwise image object may be GCed and abort request that has not been send
caches[no] = img;
// delete reference
img.onload = img.onerror = img.onabort = function () {
@kerryChen95
kerryChen95 / funny.js
Created March 28, 2013 18:13
`Object` is instance of `Function` and `Object.toString` is inherited from `Function.prototype`
> Object.prototype.toString.call({foo: 'foo'})
"[object Object]"
> Object.prototype.toString.call('fff')
"[object String]"
> Object.prototype.toString.call([])
"[object Array]"
> Object.prototype.toString.call(function () {})
"[object Function]"
> Object.toString.call(function () {})
"function () {}"
function mul (a) {
return a * a;
}
console.log( mul.toString() );
/*
output:
function mul(a) {
return a * a;
}