Skip to content

Instantly share code, notes, and snippets.

Avatar

Leo Horie lhorie

View GitHub Profile
View gist:3ae6ef45a96954b067217ecedb246026
//Expose plugin as an AMD module if AMD loader is present:
(function() {
'use strict';
var utils = (function() {
return {
extend: function(target, source) {
for (var key in source) target[key] = source[key];
return target;
},
createNode: function(html) {
@lhorie
lhorie / write-better-tests.md
Last active Jun 12, 2020
Write better tests with one neat trick
View write-better-tests.md

Write better tests with one neat trick

TL:DR; assert your input

If you write non-trivial code, inevitably you'll run into a situation where setting up a test is not super readable. Maybe you have to mock a bunch of things, or the input data is a data structure that spans dozens of LOC, or maybe you are testing with a large-ish fixture that was defined in another file because linting or whatever.

Due to the nature of my job, I happen to read a lot of other people's code, so you can imagine how mildly annoying it is when I'm code reviewing something, and the test looks something like this:

test('codemod does what it needs to', async () => {
@lhorie
lhorie / longest-keyword-sequence.md
Last active Nov 11, 2019
What's the longest keyword sequence in Javascript?
View longest-keyword-sequence.md
View gist:1204893c2f0e3ba3c14ac204b2df4b24
console.log(`%c ________________________________________
< mooooooooooooooooooooooooooooooooooooo >
----------------------------------------
\\ ^__^
\\ (oo)\\_______
(__)\\ )\\/\\
||----w |
|| ||`, "font-family:monospace")
View parser.js
var readtable = {
"(": form,
" ": space, "\t": space, "\n": space, "\r": space,
}
var white = " \t\n\r"
var atomEnd = " \t\n\r);"
var formEnd = ")"
var escape = "\\"
function parse(s) {
s.marker = s.cursor