Skip to content

Instantly share code, notes, and snippets.

Make $$ return an array

Right now $$ returns a static (non-live) NodeList, but we want to use array functions on it. Let’s make it work.

Find where console functions live

third_party/WebKit/Source/core/inspector/InjectedScriptSource.js

Wrap the call

var res;
if (this._canQuerySelectorOnNode(opt_startNode))
    res = opt_startNode.querySelectorAll(selector);
function shouldParenthesize (code) {
try {
Function(code);
}
catch (e) {
if (e instanceof SyntaxError) {
try {
Function('(' + code + ')');
return true;
}
@Zirak
Zirak / extract.js
Created June 26, 2015 21:17
Top 50 starred messages in JS room
var stars = [],
max = null;
moarStars('http://chat.stackoverflow.com/rooms/info/17/javascript/?tab=stars');
function moarStars(href) {
var xhr = new XMLHttpRequest()
xhr.open('GET', href);
xhr.responseType = 'document';
xhr.onload = function () {
console.log('load', href);
var tree = xhr.response;
@Zirak
Zirak / main.go
Created September 15, 2015 11:06
package main
import (
"log"
"math/rand"
"os"
"strconv"
"bazil.org/fuse"
"bazil.org/fuse/fs"
@Zirak
Zirak / meh.js
Last active September 16, 2015 03:51
/*global Promise, Rx*/
/*global DOMParser, WebSocket, URL, fetch*/
/*global fkey*/
function fetchJson (url, options) {
// fetch closed up sending an object as a form. fak.
if (options.body === Object(options.body)) {
options.body = URL.stringify(options.body);
options.headers = options.headers || {};
var listener = function ( fun ) {
return function ( e ) {
//thank you IE for the wonderful fish
e = e || window.event;
e.target = e.target || e.srcElement;
e.stopPropagation = e.stopPropagation || function () {
this.cancelBubble = true;
};
e.preventDefault = e.preventDefault || function () {
this.returnValue = false;
@Zirak
Zirak / gist:1510466
Created December 22, 2011 14:25
Introduction to javascript
//a simple introduction to javascript
//javascript comments are C-style: inline-comments begin with two forward
//slashes //, and end when on EOL (End Of Line)
/* multi-line comments are also available, spanning from forward-slash asterisk /*
until an asterisk forward-slash */
//variable declaration
@Zirak
Zirak / IO.js
Created December 24, 2011 22:47
SO chat hangman bot
var IO = {
//event handling
events : {},
preventDefault : false,
//register for an event
register : function ( name, fun, thisArg ) {
if ( !this.events[name] ) {
this.events[ name ] = [];
}
@Zirak
Zirak / game-min.js
Created January 14, 2012 17:32
Chain Reaction in under 1k
m=Math;R=m.random;P=m.pow;D=c.width=c.height=600;t=12;T=D-t;O=256;l=e=E=N=0;setInterval(function(){if(!E&&(e>=N||L&&e<N&&l--))e=L=0,A=[],A.length=5*++l,N=l*(l+1)/2;a.fillStyle=e<N?"#778":"#eef";a.fillRect(0,0,D,D);a.strokeText(e+"/"+N,9,9);for(i=A.length;i--;)with(A[i]||(A[i]={s:L,d:L,M:40*R()+20,x:L?L.clientX:R()*T+6,y:L?L.clientY:R()*T+6,v:R()*t-6,z:R()*t-6,C:"rgb("+[R()*O|0,R()*O|0,R()*O|0].join()+")",r:6,t:30/l|0}))!d&&A.some(function(b){return b.d&&P(r+b.r,2)>P(x-b.x,2)+P(y-b.y,2)&&(s=d=1,E++,e++)}),s?t?2==s?t--:++r>M&&(s=2):--r||(A.splice(i,1),E--):(x+=v,y+=z,x<r|x+r>D&&(v=-v),y<r|y+r>D&&(z=-z)),a.beginPath(),a.fillStyle=C,a.arc(x,y,r,0,7),a.fill()},50);c.onclick=function(b){L||(L=b,E++,A.push(0))};
@Zirak
Zirak / a.js
Created January 24, 2012 18:00
ol reverse attribute polyfill
//a polyfill for the ordered-list reversed attribute
// http://www.whatwg.org/specs/web-apps/current-work/multipage/grouping-content.html#the-ol-element
// http://www.whatwg.org/specs/web-apps/current-work/multipage/grouping-content.html#dom-li-value
//uses these awesomeness:
// Array.prototype.forEach
// Element.prototype.children
//if you want support for older browsers *cough*IE8-*cough*, then use the other
// file provided
(function () {