News for hackers. Stuff that matters.

ahoge

Re:The Website Obesity Crisis on Friday January 01, 2016 @12:00AM (#10821141)
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.

Re:There's Math.random(), and then there's Math.random() on Thursday December 17, 2015 @02:36PM (#10753865)
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-...

Re:Angular 2 Beta released on Tuesday December 15, 2015 @05:31PM (#10740976)
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.

Re:Announcing TypeScript 1.7 on Monday November 30, 2015 @08:53PM (#10653211)
> 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

Re:Announcing TypeScript 1.7 on Monday November 30, 2015 @08:37PM (#10653158)
Edge 13 does support generators.

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

Re:Evidence-based programming language design (PhD thesis) on Tuesday November 24, 2015 @01:33PM (#10622530)
> 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.

Re:Visual Studio Code is now open source on Wednesday November 18, 2015 @04:24PM (#10590861)
Atom and VS Code are built on top of Electron.

http://electron.atom.io/

Re:Show HN: Caret – Better Markdown Editor for the Desktop on Wednesday November 18, 2015 @10:14AM (#10588114)
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).

Re:Resurrecting Duckhunt on Tuesday November 17, 2015 @09:03AM (#10581046)
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.

Re:Atom 1.2 on Sunday November 15, 2015 @02:33AM (#10568839)
> 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.

Re:How to blink a light in 10 different programming languages on Sunday November 08, 2015 @06:43AM (#10528247)
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

Re:How to blink a light in 10 different programming languages on Saturday November 07, 2015 @10:48PM (#10527377)
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.
Re:Goodbye CoffeeScript, Hello TypeScript on Wednesday October 21, 2015 @03:34AM (#10424119)
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);
Re:Goodbye CoffeeScript, Hello TypeScript on Tuesday October 20, 2015 @05:15PM (#10421851)

    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;
    }
Re:Web Fonts Collateral Damage of Ad Blockers on Sunday October 04, 2015 @01:40PM (#10328144)
> Web fonts done properly don't require JavaScript.

NoScript blocks fonts, video, audio, and JavaScript.

Re:Web Fonts Collateral Damage of Ad Blockers on Sunday October 04, 2015 @05:03AM (#10326975)
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.

Re:Firefox 41 can screenshot a single DOM element on Thursday October 01, 2015 @02:14AM (#10309518)
Safari 9 has the lowest score on HTML5test and the ES6 compat table. To make matters worse, Safari 9 isn't even out yet.
Re:Firefox 41 can screenshot a single DOM element on Wednesday September 30, 2015 @08:39PM (#10308463)
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...

Re:Mobile Ad Brokers as DDoS Distribution Vectors: A Case Study on Saturday September 26, 2015 @05:48AM (#10282656)
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.

Re:Vim setup for Markdown on Thursday September 24, 2015 @10:32AM (#10271809)
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.)

Re:Introducing Brotli: a new compression algorithm for the internet on Wednesday September 23, 2015 @11:34AM (#10265648)
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.

Re:Keep Out – A WebGL Game on Thursday September 17, 2015 @12:48PM (#10234498)
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.
Re:Keep Out – A WebGL Game on Thursday September 17, 2015 @08:00AM (#10232810)
Fun game. Works really well. However, after playing 4 or 5 levels with Firefox 40 the sound got really stuttery and it never recovered.
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.

Re:Show HN: WebGL Sprites Benchmark on Tuesday September 01, 2015 @09:45AM (#10152247)
Firefox's rAF implementation is currently hardcoded at 60 FPS.

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

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.

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.
Re:Writ – Opinionated, classless styles for semantic HTML on Tuesday August 25, 2015 @08:37AM (#10115982)
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">')

Older »