While working on FileReader.js Web Worker file processing with FileReaderSync, I needed to figure out what was going on with the script inside a web worker. It can be very difficult to track down errors without standard developer tool support, like logging and debugging. Luckily, in Chrome Devtools, this is possible.
How to do it
It can be a little tricky to find, but click over to the ‘Scripts’ panel, and expand the ‘Workers’ accordion on the right. Then check the ‘Pause on Start’ checkbox and you will enter the debugging mode once the worker gets fired up. Here is a screenshot of the relevant checkbox:
Screencast
Here is a screencast of me playing with this feature:
Ever want to load a JavaScript Web Worker without specifying an external JavaScript file? There are a couple of different ways to do this by creating a blog and object URL – I wrapped this functionality up into a little plugin to share.
Here is the code. Or checkout out a working jsfiddle demo
It can be annoying that when you drag out images of a browser window, they are named png.png (or something equally useless). I was playing around with fixing this – it is a little inconvenience in my CSS Sprite Generator that would be nice to have working (naming the file based on their input). Here is what I came up with (no library dependancies):
You just need to specify the alt attribute on the image or canvas to specify your name (along with the draggable attribute on canvas elements) and the script should handle the rest.
Browser Support
I am not 100% sure on browser support. This used to be Chrome only according to this HTML5rocks article, but maybe other browsers have picked it up by now. It is a neat little addition when available though.
I’ve been working on updating my A* Graph Search Algorithm (A* on Github) and toying with the idea of adding variable costs to the grid, also known as weighted paths.
I opened an issue to add weighting to graph nodes a while ago, but am a little stuck on the implementation details. My initial thought was to change the semantics of the graph. Right now, here is a sample graph:
var GraphNodeType ={OPEN:0,
WALL:1};// 0 represents an open node, 1 represents a wall var graph =new Graph([[0,0,0,0],[1,0,0,1],[1,1,0,0]]);
My initial plan for adding weighting was something like this:
var GraphNodeType ={
WALL:0,};// Anything > 0 represents the cost to travel to that node, 0 represents a wallvar graph =new Graph([[2,1,3,4],[0,1,1,0],[0,0,3,10]]);
One major issue with that is that it breaks backwards compatibility with the plugin. A user, spellfork, on the Github issue came up with a neat solution, basically passing in two separate arrays to the graph function, where one represents the “obstacle map” (walls), and the second represents the “terrain map” (costs).
// First array: 0 represents an open node, 1 represents a wall // Second array: movement costs are represented by numeric value var graph =new Graph([[0,0,0,0],[1,0,0,1],[1,1,0,0]],[[2,1,3,4],[0,1,1,0],[0,0,3,10]]);
This is nice because the terrain map is optional, but not as nice if you need to do a lot of work to generate the two separate maps.
Maybe there is a better solution that I am not thinking of? Any ideas about the best way to implement this? Drop a comment here or over in the Github issue to help get this implemented!
I think it’s a pretty cool plugin that is a lot nicer than using the standard hacks for keeping textarea heights up to date. And it works really well with proportional widths, custom fonts, and min/max heights!
Here is a screenshot (which also links to the demo):
I put together a screencast explaining the colorpicker functionality recently added into WebKit Web Inspector (aka Chrome DevTools for brevity). For some backstory on how this got implemented, check out my initial colorpicker concept video or the description of the implementation.
Here is a quick screencast showing off the colorpicking functionality (currently running in Chrome Canary):
Oh, and the jQuery plugin I am working with is called unmodal.
I have been working a browser based gradient generator. I’ve never had the best experience using gradient generators, so I decided to see if I could do better.
It is a prototype right now (a weekend project), but I am hoping to do more with it as time permits.
Features
It outputs to CSS, Canvas, and SVG
Allows for separate color and alpha stops
Keyboard support (left, shift+left, right, shift+right, ctrl+c, ctrl+v)
Given a parent rectangle and a collection of children rectangles on a 2D plane, how do you find a collection of non-overlapping rectangles that cover the inverse of the original set?
For instance, given the container rectangle along with the set [A, B] -> we want an output similar to [1, 2, 3, 4, 5].