Skip to content

Instantly share code, notes, and snippets.

Hanging around.

Robert Lemon rlemon

Hanging around.
View GitHub Profile
View darkchat.css
body {
background-color : #000 !important;
background-image : url("") !important;
color : #ddd !important;
.messages {
background-color : #222 !important;
border : none !important;
color : #ddd !important;
View colorusers.user.js
// ==UserScript==
// @name SO Dark Chat + JS
// @author Robert Lemon
// @version 0.1.1
// @namespace
// @description adds colors to users messages and a whole bunch of other crap.
// @include*
// @include*
// ==/UserScript==
(function () {
View gist:fae999ad027207f7a381
function messageIdToRoomId (mid) {
return fetch(`${mid}/history`).then(function (res) {
return res.text();
}).then(function (html) {
return new DOMParser().parseFromString(html, 'text/html');
}).then(function (doc) {
return doc.querySelector(`a[name="${mid}"]`).getAttribute('href').match(/\d+/)[0];
rlemon /
Created Jan 19, 2012 — forked from Raynos/
Why you don't need jQuery

Why the jQuery Abstraction isn't needed.

(One needs some form of browser normalization so that modern features works, no-one is doubting that).

Abstractions that aren't needed


QSA works (shim=sizzle). Besides selectors are generally bad practice. Favour node traversal, gEBI, gEBTN and gEBCN. (shim=domShim)

rlemon / gist:3090947
Created Jul 11, 2012 — forked from Zirak/gist:3086939
xhr for dummies
View gist:3090947

So, you want to send a motherfucking XMLHttpRequest (XHR, or commonly and falsly known as AJAX.) Too bad, just ran out of motherfucking XMLHttpRequests; but I still have one regular. XHR is not magic. It does not autofuckinmagically send things the way you want them do be sent. It does not do the thinking for you. It just sends an Http Request.

You get a hold on such a prime beast like this:

rlemon / gist:4061754
Created Nov 12, 2012 — forked from ralt/gist:4061749
My Library when IE8 won't be supported anymore
View gist:4061754
NodeList.prototype.forEach = HTMLCollection.prototype.forEach = Array.prototype.forEach; = =;
NodeList.prototype.filter = HTMLCollection.prototype.filter = Array.prototype.filter;
NodeList.prototype.reduce = HTMLCollection.prototype.reduce = Array.prototype.reduce;
NodeList.prototype.every = HTMLCollection.prototype.every = Array.prototype.every;
NodeList.prototype.some = HTMLCollection.prototype.some = Array.prototype.some;
var By = {
id: function (id) { return document.getElementById(id) },
tag: function (tag, context) {
return (context || document).getElementsByTagName(tag)
View skeet.js
var style = document.createElement('style'); style.textContent = '.vote-count-container.stars span.img, span.img, span.img { background-image: url(""); background-position: 0px 0px; height: 16px; width: 16px;} .user-star span.img { outline: 1px solid #ff0; }'; document.head.appendChild(style);
This indirection was intended to make the language seem more familiar to classically trained programmers, but failed to do that, as we can see from the very low opinion Java programmers have of JavaScript. JavaScript's constructor pattern did not appeal to the classical crowd. It also obscured JavaScript's true prototypal nature. As a result, there are very few programmers who know how to use the language effectively.

~ Douglas Crockford, "Prototypal Inheritance"

The indirection Mr. Crockford refers to here is the Pseudo-Classical Pattern, also known as the Constructor Pattern. This is a way of simulating classical inheritance in JavaScript - a prototypal language.

If it wasn't obvious from both the title of this post, and from the frankly negative quote above, this is not my favorite object-oriented pattern in JavaScript. I'

View chat-frontend.js
$(function () {
"use strict";
// for better performance - to avoid searching in DOM
var content = $('#content');
var input = $('#input');
var status = $('#status');
// my color assigned by the server
var myColor = false;