*** How To Write a Pacman Game in JavaScript ***


, ,

“The game described here differs from the original “Pac-Man”™ by Namco™ <http://www.namco.com/> in some ways:

The original game uses only one layout populated by four ghosts, each ghost guided by a distinguished strategy and moving at its own speed. The various levels differ by the ghosts’ strategy and the speed of the game. Opposed to this, the game as described here will be populated by ghosts employing a shared set of movement strategies. (The speed will probably be the same as the speed of the pacman character or a fraction of it.) In order to entertain some difference to the game play each level will have its unique layout. This conforms with the typical appearance of a Pac-Man clone.

The original “Pac-Man” by Namco and its clones share the following features – as does the game described here: The player guides a little yellow ball (the pacman) through a maze-like labyrinth in order to clear all the food (embodied by tiny white dots) laid out in the passages of the labyrinth. His opponents are 4 ghosts of different color roaming the labyrinth in search for the pacman. If any of the ghosts comes in touch with the pacman, the pacman looses a life and is reset to its original position. Some of the food dots (usually four of them) are bit bigger and provide a reversed game play, when eaten by the pacman: For a limited amount of time the pacman now may haunt and eat the ghosts. (This phase is indicated by the ghosts’ color – usually a deep blue.) If the pacman manages to get grip of a ghost in this special phase, the ghost is not killed, but set to the central cage, from which it emerged at the beginning of the level.

Pac-Man™and Namco™ are trademarks of the specific vendor(s)...”


Immutable collections for JavaScript


, , ,

Immutable data cannot be changed once created, leading to much simpler application development, no defensive copying, and enabling advanced memoization and change detection techniques with simple logic. Persistent data presents a mutative API which does not update the data in-place, but instead always yields new updated data.

Immutable provides Persistent Immutable List, Stack, Map, OrderedMap, Set, OrderedSet and Record. They are highly efficient on modern JavaScript VMs by using structural sharing via hash maps tries and vector tries as popularized by Clojure and Scala, minimizing the need to copy or cache data.

Immutable also provides a lazy Seq, allowing efficient chaining of collection methods like map and filter without creating intermediate representations. Create some Seq with Range and Repeat…”


TCP/UDP/ICMP traffic over UDP tunneling


, ,

By default mobile provider blocks any packet but UDP packet, unless you pay for the service. My method consists in sending TCP/UDP/ICMP frames as payload of an UDP packet to a known host (your server). Your server reinjects these frames to Internet.

PC to Internet
PC -> Cellphone -> [limited Internet] -> Your server -> [Internet]

Internet to PC
[Internet] -> Your server -> [limited Internet] -> Cellphone -> PC


C++ is fun: tips and tricks


“C++ is not the language you learn in 12 lesson in one week. With the C++ standard spanning 1300 pages, you can still have things to learn after years of experience. I’d argue you could hardly count on your fingers the people that know everything the standard says.

In this article I will walk through several language features that are probably less known to many C++ developers. Some of them are more useful than other, some could only confuse fellow developers and should not be used in real code…”


A vim Tutorial and Primer



“There are dozens of vim references online, but most of them either go ninja straight away, or start basic and don’t go much deeper.

The goal of this tutorial is to take you through every stage of progression—from understanding the vim philosophy (which will stay with you forever), to surpassing your skill with your current editor, to becoming “one of those people”…”


Using imagemagick, awk and kmeans to find dominant colors in images


, , , , ,

“Some days ago I was reading “Using python to generate awesome linux desktop themes” and got impressed by a technique to obtain dominant colors from images, I went ahead and tried to run the examples but PIL proved difficult to install, so I looked around to see if I could replace it for some other utility and it turned out that convert (which is part of the imagemagick package) is powerful enough for the duty.

Besides resizing, convert can output the rgb values of any image, so I reimplemented the kmean algorithm on awk and that’s how dcolors was born. By default dcolor will resize (on RAM) the input image to 25×25 using a 1px deviation and 3 clusters for an average time of 1s per image, further customization are possible to increase quality, quantity or performance…”


Fast Memory Pool Allocators: Boost, Nginx & Tempesta FW


, , ,

“Memory Pools and Region-based Memory Management

Memory pools and region-based memory management allow you to improve your program performance by avoiding unnecessary memory freeing calls. Moreover, pure memory pools gain even more performance due to simpler internal mechanisms. The techniques are widely used in Web servers and using them you can do following (pseudo code for some imaginary Web server):

http_req->pool = pool_create();
while (read_request & parse_request) {
http_req->hdr[i] = pool_alloc(http_req->pool);
// Do other stuff, don’t free allocated memory.
// Send the request.
// Now destroy all allocated items at once.

This reduces number of memory allocator calls, simplifies its mechanisms (e.g. since you don’t free allocated memory chunks it doesn’t need to care about memory fragmentation and many other problems which common memory allocators must solve at relatively high cost) and makes the program run faster.

Probably, you’ve noticed that we call pool_alloc() in the example above without specifying allocation size. And here we go to the difference between memory pools and region-based memory management: memory pools can allocate memory chunks with only one fixed size while region-based memory allocators are able to allocate chunks with different size. Meantime, both of them allow you not to care about freeing memory and just drop all the allocated memory chunks at once…”


Hadoop filesystem at Twitter


, , ,

“Twitter runs multiple large Hadoop clusters that are among the biggest in the world. Hadoop is at the core of our data platform and provides vast storage for analytics of user actions on Twitter. In this post, we will highlight our contributions to ViewFs, the client-side Hadoop filesystem view, and its versatile usage here.

ViewFs makes the interaction with our HDFS infrastructure as simple as a single namespace spanning all datacenters and clusters. HDFS Federation helps with scaling the filesystem to our needs for number of files and directories while NameNode High Availability helps with reliability within a namespace. These features combined add significant complexity to managing and using our several large Hadoop clusters with varying versions. ViewFs removes the need for us to remember complicated URLs by using simple paths. Configuring ViewFs itself is a complex task at our scale. Thus, we run TwitterViewFs, a ViewFs extension we developed, that dynamically generates a new configuration so we have a simple holistic filesystem view…”


Cleaning up AWS with Boto3



“A common problem I come across when people are first getting started with AWS is that they fail to properly clean up after themselves. They’re like that roommate freshman year that has never lived on their own. You have this fantastic apartment but you’re so focused on trying out all the cool things in it that you forget to take out the trash, dust, and do some general cleaning up…”


Steven Wise: Chimps have feelings and thoughts. They should also have rights



“Chimpanzees are people too, you know. Ok, not exactly. But lawyer Steven Wise has spent the last 30 years working to change these animals’ status from “things” to “persons.” It’s not a matter of legal semantics; as he describes in this fascinating talk, recognizing that animals like chimps have extraordinary cognitive capabilities and rethinking the way we treat them — legally — is no less than a moral duty…”


Get every new post delivered to your Inbox.

Join 1,376 other followers