All posts by sole

Shadow DOM in Firefox!

Wow, this has been a nice surprise to start the year :-)

If you want to start creating shadow roots like there’s no tomorrow, you’ll need two things:

  1. An updated version of Firefox Nightly. Get one from the Nightlies website.
  2. Manually enabling web components, because they’re disabled by default. Go to about:config, look for dom.webcomponents.enabled and double click the property to toggle it to true.

No restart was required (at least on my case), and BAM! I could start doing things such as…

var container = document.createElement('div');

But all the examples in the world use webkitCreateShadowRoot()!!!

Worry not. Following established monkey patching traditions, I’ve created an small shim that monkey patches browsers that only implement webkitCreateShadowRoot so they can use createShadowRoot instead. Here’s WebComponentsMonkeyPatch in all its glory. Once you include it in your projects, you can start writing future-proof code today (and updating older webkit- based code to use unprefixed methods).

I have also written this simple example demonstrating how to create unprefixed Shadow Roots like there’s no tomorrow.

The umbrella bug for tracking Web Components work in Firefox is still not resolved, which means that this might not work totally as you’d expect when you get excited and start playing with this. In which case, please file bugs and help us make Firefox better ^_^

npm scripts

npm can do much more than just installing packages and resolving dependencies for installing packages. One of the things it can do is running scripts! You might have seen that already:

npm test
npm start

It has a series of defaults. For example:

npm start

will attempt to run

node server.js

You can, of course, redefine those defaults by specifying them in the scripts field in package.json. Suppose my script for launching the server doesn’t live in the root of the project, then I’d have to modify the start script entry consequently. Imagine this very minimal package.json:

  "scripts": {
    "start": "node server/main.js"

The defaults can be called with just npm something, and there’s a list of default scripts npm recognises in the script documentation page. Some are very handy because they get called automatically before some scripts are executed. For example, if you run npm test, the pre-test script will also be automatically run before (if it has been specified). You could use that to make sure your bundles are updated before testing them.

If you want to run a script whose key is not one of the defaults, you have to invoke it in a slightly different manner. Suppose it’s specified here in your scripts:

  "scripts": {
    "my-specially-named-script": "echo \"NICE\""

You would then run it with

npm run my-specially-named-script

As you can see it’s not too complicated, and the whole thing is very minimal and obvious, which I like.

If you want to learn more about “advanced” uses of npm and scripts, be sure to read the excellent Task automation with npm run from the always inspiring substack.

Goodbye 2013, hello 2014!

I’m writing this under the influence of medicine to fight a fever and massive sneezing. I have a cold again, maybe a flu. I’ll run the easy joke for you: I hope it’s not the Spanish flu.

It’s my third big cold in less than a month, probably due to flying to diverse far away places in cold weather so I’ve put my body under stress. Tut, tut. It’s definitely not the way I wanted to start a new year, but hey, what can you do when your body prefers to get ill?
Continue reading

Demozoo is back!

After years of delays and unfulfilled promises, Demozoo is finally out there again! It was once out there already, but got pulled back I-don’t-know-why, until now. Yay!

Wait—you may not understand my excitement. Demozoo is meant to be the catalog of catalogs, without comments or trolls. Just a catalog. Just the facts, i.e. the demoscene productions.

I evidently looked for my own profile, and I must admit I got really impressed by the amount of demoscene stuff I have made. Some things I didn’t even remember being involved with! And some are missing. I might add them, since it’s a wiki-style website :-)

Funny fact 1: I found that demozoo had been released because I saw gasman opensourcing the project in my GitHub timeline. You should follow him too, if you’re into mental code such as Spectrum emulators or MIDI players in JavaScript. See, it will be insanely good.

Funny fact 2: The site is built with Django now. It used to be built with Ruby on Rails, and if I remember correctly Gasman went as far as writing (and proposing to core) new ActiveRecord features that he needed for Demozoo. Not sure if they ever made it to upstream, though! Gasman, please comment on this! :D


HEY: English version here.

HEY HEY HEY: por si alguien no se había dado cuenta, esto es una broma. Una broma que compila a JavaScript, pero broma al fin y al cabo. O en otras palabras: ¡INOCENTE, INOCENTE!

Olvídense de dogecoin, perriscript es lo que mola.

Los principales autores de navegadores han estado trabajando con nuestro tremendamente distribuido equipo (de tan sólo una persona) para asegurarse de que el modo perriscript está ACTIVADO por defecto cuando se ejecute un navegador traducido al español. No se necesita ni tan siquiera incluir una perrictiva, tal que

'use perri';

que sí necesitarías si quisieras entrar en el modo Strict o asm.js—tu navegador localizado en español ya respira perriscript desde el mismo preciso instante en que lo arrancas.

El resto de navegadores simplemente ejecutarán código perriscript a un 1% de velocidad, para reflejar la confusion en que se sumirá el intérprete de JavaScript cuando se enfrente a código .PJS (“¿querían decir PiJama Script o qué? ¿Lo Just-In-Time-eo o lanzo una excepción?”).

Algunos de los primeros testers han informado acerca de apariciones intermitentes de un huevo de Pascua cada vez que ladraban “GUAU GUAU GUAU” a la webcam con suficiente ferocidad mientras al mismo tiempo se concentraban en proyectar la imagen mental de un doge en el triángulo formado por sus cejas y el espacio sobre sus narices, pero nadie ha sido capaz de confirmar la veracidad de, o negar categóricamente estas afirmaciones.

Por favor, creen un bug si son capaces de reproducir dichos incidentes, puesto que los huevos de chocolate no son buenos para los doges y aún menos para los perris.

Mientras tanto, no dejen de disfrutar perriscript en el GUAUser.

vaya ladrido mucho fulanito menganito zutanito
    porfi consola.ladra con fulanito
    vaya anidado
        porfi consola.ladra con ['hala', 'guau']
    porfi anidado
guau fulanito

~~~~ ENGLISH ~~~~

HEY HEY HEY: just in case someone didn’t notice, this is a joke. A joke that compiles to JavaScript, but a joke after all. 28th of December is the day when we celebrate “the Feast of the Holy Innocents” in Spain and it’s basically our excuse to come up with pranks and jokes. Think April’s Fools.

Forget dogecoin, perriscript is where it’s at.

Major browser vendors have already been working with our massively distributed team (of just one person) to ensure perriscript mode is ON by default when you run a browser localised to Spanish. You don’t even need to include a perrictive, as in

'use perri';

as you would need to when willing to enter Strict or asm.js mode—your Spanish localised browser already breaths perriscript from the very instant you launch it.

All other browser versions will just run perriscript code at 1% of speed, to account for the confusion the JavaScript engine will incur on when confronted with .PJS code (“did they mean Pyjama Script or what? do I JIT it or throw an exception?”).

Some early testers have reported intermittent happenings of an Easter egg whenever they barked “GUAU GUAU GUAU” at their webcams ferociously enough while also focusing on projecting the mental image of a doge in the triangle formed by their eyebrows and the space about their noses, but no one has been able to confirm the truth of, or categorically deny, these statements.

Please file a bug if you are able to reproduce such incident, as chocolate eggs are not suitable for doges and even less for perris.

In the meantime, please feel free to enjoy perriscript in the GUAUser.