Better HN
topnewbestaskshowjobs
Log inSign up

ahoge

1,026 karma · joined Dec 11, 2011 (14y ago) · 464 submissions

Submissions

comment 10y ago · link · parent

Most of the weight comes from images. The average website (Alexa top 1M) contains over 1.4 MB of image data:

http://httparchive.org/interesting.php

Be sure to pick the most suitable format and to optimize your images. You can also try to serve WebP to browsers which support it. When it replaces JPEG, you save about 30%. With PNG8, it's somewhere between 5 and 50%. And with PNG32, if you substitute it with a lossy WebP, easily 80%.

Scripts come 2nd with ~363 KB. ES6's will thankfully help with that. Creating the structure of your application declaratively enables better tooling. Not only does this make your editor a lot smarter, it also paves the way for tree-shaking.

If you tree-shake your application, only the actually used library features will be included in the shipped bundle.

comment 10y ago · link · parent

Those lines are showing up because the old algorithm can't produce all possible values in the 0-1 range. 32 bits of internal state simply aren't enough for that.

The problem is highlighted by the images in this article:

http://jandemooij.nl/blog/2015/11/27/math-random-and-32-bit-...

comment 10y ago · link · parent

You can write your Angular 2 application code in ES5, ES6, TypeScript, Dart, or to-JS languages like CoffeeScript.

TypeScript is pretty popular and it does work really well. Writing larger applications in a team is much easier if there is tooling to assist you. With most projects, about 80% of the work is maintenance and tooling does immensely help with that.

comment 10y ago · link · parent

> Want to bang up a quick solution, as in MVP? Use bare-bones Javascript

Actually, adding the bare minimum of type annotations (fields & function signatures) and type casts (e.g. casting whatever you get from querySelector into the concrete type of element) results in fewer key presses, because you can auto-complete everything and because you get additional machine-assistance like call tips and type checks.

So, you'll be actually faster if you add some types. Type inference does cover quite a lot. In practice, you'll need very few annotations and casts.

This Dart demo, for example, only needed a single type cast to be fully typed:

https://dartpad.dartlang.org/e23e4d137570c652591e

comment 10y ago · link · parent

Edge 13 does support generators.

http://kangax.github.io/compat-table/es6/

comment 11y ago · link · parent

https://quixdb.github.io/squash-benchmark/

comment 11y ago · link · parent

> Research found that the number one cause of errors in learning Python was its case-sensitivity

You don't make that kind of error in other case-sensitive languages which offer better tooling.

E.g. you start writing "canv" and auto-complete that to "CanvasElement". You just auto-complete everything. And if you actually do screw something up, you get a squiggly line and a hint.

Simply ignoring all kinds of errors does not make the language easier to use. In JavaScript, for example, there are many cases where semicolons can be omitted. However, they aren't actually optional. There is a list of exceptions. It didn't actually make the language any easier.

Another example are things which should be type errors (`'foo' - 123` and so forth), but you get NaN instead. Or when you go outside some array's bounds you just get undefined instead of an exception. This stuff does not make the language easier to use.

comment 11y ago · link · parent

Atom and VS Code are built on top of Electron.

http://electron.atom.io/

comment 11y ago · link · parent

I'm quite happy with VS Code and this Markdown CSS theme:

https://github.com/mahonnaise/vs-code-markdown-theme

The automatic table formatting was pretty cool though (even if it's purely cosmetic).

comment 11y ago · link · parent

The timing of the beam racing down the screen is used by the more modern guns which were used by the SNES, PlayStation, or the Dreamcast.

So, it's really not much of a "myth". Most light guns worked that way. The zapper is an outlier.

comment 11y ago · link · parent

> Any major complaints from users?

AltGr is still broken. The problem has been known for almost 2 years and there are about a hundred duplicates.

https://github.com/atom/atom-keymap/issues/35

If you aren't using an US keyboard layout, this might be a problem.

comment 11y ago · link · parent

That's string interpolation. That line writes either "00" or "01". It's essentially the same as `'0' + state`.

  'x: $x, y: $y'
is a lot easier to type than:

  'x: ' + x + ', y: ' + y
I actually had to triple check that line. Concatenation is very error-prone. I often mess it up.

String interpolation is a fairly popular feature nowadays:

https://en.wikipedia.org/wiki/String_interpolation

comment 11y ago · link · parent

Dart:

  import 'dart:async';
  import 'dart:io';
  main() {
    var file = new File('/sys/class/leds/beaglebone:green:usr0/brightness');
    var state = 0;
    new Timer.periodic(new Duration(seconds: 2), (_) {
      state = 1 - state;
      file.writeAsStringSync('0$state', flush: true);
    });
  }
While it's not the most concise version, it's certainly very readable. Everyone can clearly see that the duration is 2 seconds and that that boolean flag is for flushing, because that's exactly what the code says.

comment 11y ago · link · parent

The reduce one needs an initial value of 0 for that to work. Then both versions will return 0 if the array is empty.

    array.reduce((a, b) => a + b, 0);

comment 11y ago · link · parent

    function sum(array) {
      return array.reduce((a, b) => a + b);
    }
With a loop:

    function sum(array) {
      let acc = 0;
      for(let val of array) {
        acc += val;
      }
      return acc;
    }

comment 11y ago · link · parent

> Web fonts done properly don't require JavaScript.

NoScript blocks fonts, video, audio, and JavaScript.

comment 11y ago · link · parent

As a NoScript user, I rarely see web fonts and I prefer it this way. The text shows up instantaneously and the font will look great and be perfectly readable.

Most web fonts don't look that nice on Windows. Windows heavily relies on hinting and doing this properly is a lot of hard mind-numbing work.

Most web fonts also aren't that readable. Sure, your wide/thin/square font looks very modern and stuff, but it's not as readable as a Verdana or Arial. When I visit your site, I'm there for the text, not the font.

comment 11y ago · link · parent

Safari 9 has the lowest score on HTML5test and the ES6 compat table. To make matters worse, Safari 9 isn't even out yet.

comment 11y ago · link · parent

Non-standard:

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRende...

comment 11y ago · link · parent

Taking screenshots of the full page or individual elements was also possible before via Tools -> Web Developer -> Developer Toolbar (Shift + F2)... and then using the `screenshot --selector ...` command.

You also have access to part of this functionality via the non-standard drawWindow method:

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRende...

comment 11y ago · link · parent

In case anyone wonders about the `!+[1,]` bit:

In modern browsers, `[1,]` is the same as `[1]`. If you coerce it to number, you get 1. (You get "1" if you toString it.)

In IE8, `[1,]` is the same as creating an array with a length of 2 whose first slot contains 1 and whose second slot was left empty. It's kinda like `[1, undefined]`, but there is no "1" key. If you coerce it to number, you get NaN. (You get "1," if you toString it.)

If you coerce 1 to boolean and negate it, you get false.

If you coerce NaN to boolean and negate it, you get true.

So, basically, it just checks if trailing commas in array literals are handled incorrectly.

comment 11y ago · link · parent

As somone who doesn't like to configure and tweak stuff for hours, my favorite Markdown editor is VS Code. You only have to set "editor.wrappingColumn" to zero (viewport wrapping) and you're good to go.

You can use tables, fenced code blocks (there is syntax highlighting too), and images (I use viewBox'd SVGs for my diagrams). And of course there is the usual split view and a live preview on whichever side you prefer. You can also customize the CSS if you want, but the default one looks fine, really.

It does everything I need from a Markdown editor out of the box.

https://code.visualstudio.com/Docs/languages/markdown

(The right sidebar can be toggled with Ctrl+B.)

comment 11y ago · link · parent

Firefox's Brotli support is already done. Chrome's isn't.

By the way, new features are generally created this way. They are added to browsers way before they are standardized. You see, convincing the other browser vendors isn't easy. You need very compelling arguments.

Take WebP, for example. It provides massive benefits. Especially if you can use lossy RGBA instead of PNG32 (easily 80% smaller). And yet, Mozilla shows little interest in implementing it.

comment 11y ago · link · parent

The keyboard handling seems a bit off. If you hold S and then press C, you'll stop moving backwards even though you're still holding S. I often thought I was running into a wall or some other obstacle while in fact my input was simply being ignored.

comment 11y ago · link · parent

Fun game. Works really well. However, after playing 4 or 5 levels with Firefox 40 the sound got really stuttery and it never recovered.

comment 11y ago · link · parent

I bought several indie platformers. Super Meat Boy, Braid, Noitu Love 2, and a few others.

I also bought Deadlight.

I think there is a fairly huge market for platformers. However, it's certainly a very crowded one. There are over 500 platformers on Steam. Want to make one with pixel graphics? There are already 97 of those.

comment 11y ago · link · parent

Firefox's rAF implementation is currently hardcoded at 60 FPS.

https://bugzilla.mozilla.org/show_bug.cgi?id=707884

comment 11y ago · link · parent

For one, it's written in TypeScript. There is one codebase for ES5/6, TypeScript, and Dart. A big benefit of Angular 2 is the better tooling you get with TypeScript and Dart.

It uses things like classes, decorators, and the <template> tag. It uses a virtual DOM, which is still a fairly new concept. It can run in Web Workers and you can even use it for native applications which do not have a regular DOM.

It really is quite different from anything one could have started back in 2009. Even those odd-looking attribute might have not worked because HTML5, which specified a lot of those things more precisely, was far from being done.

Angular 1.x made pretty good use of the things which were available at the time.

comment 11y ago · link · parent

Browsers and JavaScript have changed quite a bit since 2009. You couldn't have created something like Angular 2 6 years ago or even 2 years ago for that matter. Angular 2 is possible today thanks to technological advancements.

comment 11y ago · link · parent

It would probably break some websites.

Run this on some websites and you'll see some things moving around:

  document.head.insertAdjacentHTML('afterbegin', '<link rel="stylesheet" href="https://cmcenroe.me/writ/writ.min.css">')
12345
16