Skip to content

Instantly share code, notes, and snippets.

@hax
hax / hi-bot.js
Created January 5, 2016 09:29
detect robot
void function () {
if (!window.tracker) {
return;
}
var events = ['scroll', 'click', 'mousemove', 'keydown', 'mousedown'];
for (var i = 0; i < events.length; i++) {
addHandler(document, events[i], detect);
}
function detect(event) {
for (var i = 0; i < events.length; i++) {
@hax
hax / class-fields-shanghai-meeting.md
Last active September 1, 2019 18:53
class fields 提案闭门研讨会(上海,2019年9月)
@hax
hax / readonly.js
Created December 4, 2018 10:32
readonly collections
void function () {
'use strict'
const targetSymbol = Symbol()
function createSafeMethod(method) {
return new Proxy(method, {
apply(target, thisArg, argArray) {
return Reflect.apply(target, thisArg[targetSymbol], argArray)
}
// See https://github.com/nodejs/node/issues/6456
import {platform} from 'os'
import {satisfies} from 'semver'
if (platform() === 'darwin' && satisfies(process.version, '>=6.0.0 <6.2.1')) {
for (const s of [process.stdout, process.stderr]) {
if (s && s.isTTY && s._handle && typeof s._handle.setBlocking === 'function') {
s._handle.setBlocking(true)
}
@hax
hax / index.js
Created December 7, 2016 19:32
log with calling location info in Node.js
const {main} = require('./main')
main()
@hax
hax / gist:3482308
Created August 26, 2012 18:22
How to create a naked Object in old Browsers (eg. IE 6,7,8) which not support Object.create(null) or {__proto__: null}
function nakedObject() {
var iframe = document.createElement('iframe')
iframe.width = iframe.height = 0
iframe.style.display = 'none'
document.appendChild(iframe)
iframe.src = 'javascript:'
var proto = iframe.contentWindow.Object.prototype
iframe.parentNode.removeChild(iframe)
iframe = null
@hax
hax / test-block-scope-performance.js
Created April 30, 2016 08:46
block scope optimization test
'use strict'
const Benchmark = require('benchmark')
function MASK() {
return 100
}
function MAX() {
@hax
hax / gist:3982309
Created October 30, 2012 19:07
modulelint 0.0.2 bug
D:\working\hax\mmclass [master]> modulelint -i .
C:\Users\Administrator\AppData\Roaming\npm\node_modules\modulelint\lib\checklist
\bom.js:22
var blackListReg = new RegExp(blackList.join("|"));
^
SyntaxError: Invalid regular expression: /\doc\|\.git\|\.svn\|\node_modules\/: \
at end of pattern
at new RegExp (unknown source)
at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modul
@hax
hax / show_more_groups_for_my_weibo
Created September 20, 2011 10:07
A bookmarklet to show more group links for the Sina Weibo v4 (Sep, 2011)
javascript:void function(){STK.sizzle('[node-type="feedGroupLayer"]')[0].style.display='block';STK.sizzle('[node-type="feedGroupLayer"] a[href]')[0].focus()}()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// See https://github.com/promises-aplus/promises-spec/issues/179