Skip to content

Instantly share code, notes, and snippets.

View jed's full-sized avatar

Jed Schmidt jed

View GitHub Profile
@jed
jed / LICENSE.txt
Created May 9, 2011 16:22 — forked from 140bytes/LICENSE.txt
linkify @mentions and #hashtags in a tweet
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jed
jed / LICENSE.txt
Created May 10, 2011 16:39 — forked from 140bytes/LICENSE.txt
use anchor tags to parse URLs into components
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jed
jed / LICENSE.txt
Created June 24, 2011 10:06 — forked from 140bytes/LICENSE.txt
ES5-ish shim for Date.prototype.toISOString
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jed
jed / LICENSE.txt
Created May 9, 2011 16:17 — forked from 140bytes/LICENSE.txt
communicate with jsonp
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// per https://twitter.com/yoshuawuyts/status/1494119486429007879
// "In JavaScript, is there a function which takes N Promises, and returns an asyncIterator which yields N resolved values?"
let promises = Array.from({length: 10}, (n, i) => {
return new Promise(cb => setTimeout(cb, Math.random() * 1e3, i))
})
let iterator = iteratePromises(promises)
for await (let value of iterator) console.log(value)
export default (build, namespace = 'view-source') => ({
name: namespace,
setup({initialOptions, onLoad, onResolve}) {
let options = {...initialOptions, write: false}
let filter = new RegExp(`^${namespace}:`)
onResolve({filter}, ({path, importer}) => {
path = path.replace(filter, '')
try { importer = new URL(importer) }
catch (e) { importer = new URL(`${namespace}://${importer}`) }
@jed
jed / bookmarklet.js
Created April 28, 2011 08:57
dom tree caching performance: array v. linked list. see also: http://jsperf.com/dom-trees/
javascript:with(document)(body.appendChild(createElement('script')).src='https://gist.github.com/raw/946036/8b51f04a6f9dbe15f5c375ac872a9ae56d4b8732/domTrees.js')._
@jed
jed / rendering_templates_obsolete.md
Created October 19, 2012 05:07
Rendering templates obsolete

(tl;dr DOM builders like [domo][domo] trump HTML templates on the client.)

Like all web developers, I've used a lot of template engines. Like most, I've also written a few of them, some of which even [fit in a tweet][140].

The first open-source code I ever wrote was also one of the the first template engines for node.js, [a port][node-tmpl] of the mother of all JavaScript template engines, [John Resig][jresig]'s [micro-templates][tmpl]. Of course, these days you can't swing a dead cat without hitting a template engine; one in eight packages on npm ([2,220][npm templates] of 16,226 as of 10/19) involve templates.

John's implementation has since evolved and [lives on in Underscore.js][underscore], which means it's the default choice for templating in Backbone.js. And for a while, it's all I would ever use when building a client-side app.

But I can't really see the value in client-side HTML templates anymore.

@jed
jed / replacer.coffee
Created July 28, 2011 14:49
JSON.stringify replacer that sorts object keys
replacer = (key, val) ->
if val instanceof Object
keys = Object.keys(val).sort().map (key) ->
"\"#{key}\":#{JSON.stringify val[key], replacer}"
"{#{keys}}"
else val
@jed
jed / LICENSE.txt
Created August 15, 2011 16:10 — forked from 140bytes/LICENSE.txt
an animated loading DOM spinner
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE