Traffic Simulation

Traffic SimulationSome time ago I implemented a traffic simulation program in JavaScript, a little less advances than this one (non Java) but with full source disclosure. To make it part of eDesign.nl this is the post associated with it. Check it out for a one crossing simulation or a double crossing simulation using the same engine.

Share/Save/Bookmark No Comments

Virtual Switchboard

Switchboard in real lifeBack when I was in highschool, during some physics lessons we worked with ‘systeemborden‘ (Dutch for ‘system boards‘ or ’switchboards’). It was to learn basic logic gates. They were boards with component on them which you could wire, to make a system. For instance, you could connect a button to a led, which made that when you pressed the button, the led would turn on. You could also instead connect the button to an AND-component, along with a sound-sensor (microphone) and connect the output of the AND-port to the led. That way the led would show light when a sound is made and the button is pushed. There are a lot of other and more complex combinations possible with a lot more different components too. I thought to virtualize it in HTML5 and JavaScript. Have look and play with the switchboard I made (the source code is free and not obfuscated).

Share/Save/Bookmark No Comments

Flags for PHP

In my last post I wrote about the enumerated type (Enum) for PHP. In C# an Enum can have multiple values when it has the [Flags] attribute. A flags enum can be seen as a bitwise mask which can be used to combine boolean properties of an entity into one single integer property. This might come in handy when filtering on these properties. In this article I show my implementation for a flags enum in PHP and demonstrate the use of it in an example.

Read the rest of this entry »

Share/Save/Bookmark 1 Comment

The enumerated type for PHP

Enum

Whenever a procedure accepts a limited set of variables one could use an enumeration. Enumerations make for clearer and more readable code, particularly when meaningful names are used. A page at MSDN states the benefits of using an enumeration include:

  • reduction of errors caused by transposing or mistyping numbers,
  • simplify changing values in the future,
  • code is easier to read, which means it is less likely that errors will creep into it and/or
  • ensuring forward compatibility. With enumerations, your code is less likely to fail if in the future someone changes the values corresponding to the member names.

Enumerations are a must if your software solution spans across multiple projects and/or if the team you work is rather large. Read the rest of this entry »

Share/Save/Bookmark 1 Comment

HTML5 Canvas experiments

HTML5 Canvas element

HTML5 is supported by more and more browsers. It has a nice feature called the ‘canvas’ element. It is an element on which you can ‘paint’ using e.g. JavaScript. I experimented with this new canvas element. You can view the experiments (clock, 3D-axis and rotation, ray tracer) and view the source too! The ray tracer should be activated in Chrome or Safari as Firefox and Internet Explorer tend to be (very) slow.

Share/Save/Bookmark No Comments

Avoid becoming a spam source

The number one rule in programming is not to trust external data, especially not user data. One of the reasons not to trust user data is the threat of hackers searching for injection possibilities. When you start develloping web applications you’ll soon learn the dangers of SQL injection. This might be the most important form of injection, but by far it is not the only one out there: cross site scripting is another good example. If your application sends out mail, you might want to make sure you sanitize user input as well as the application could be a magnet for spammers who’ll send spam mail using your IP. Read the rest of this entry »

Share/Save/Bookmark No Comments

Decoration aid

When it comes to designing websites choosing what colors to use is one of the first steps. Nowadays online applications often let users personalize the look and feel of the site by offering a way to customize the colors the website wears. JavaScript and HTML can be used effectively to this end. A problem is arising for component developers using JavaScript: what framework to use? There is MooTools, ProtoType, YUI library, jQuery, etc, etc… This is the reason I developed a standalone color picker. It also works with every JavaScript framework, as it does not depend on one or interferes with one. It is one single .js file, no extra images, css, javascript or whatsoever.

Read the rest of this entry »

Share/Save/Bookmark No Comments

No robots beyond this line

Customs passport checkOnline communities are hot. Globally recognized examples are easy to give: websites like Facebook, LinkedIn and are very popular, manufacturers have online fora to have their customers support each other, newspapers let you leave comments on their articles on their websites and you can share everything with tools like Delicious, Digg and Reddit. This development on the Internet supports new possibilities which were unknown before. Of course this also counts for rogues. Spam is a commonly known phenomenon and global annoyance. Beside spamming unwanted messages by mail, spamming the comment boxes and fora is an issue web programmers have to deal with too. Spamming often is automated and this is a feature which can be used to counter spam. The goal is to identify a messenger being human or robot.

For this purpose the captcha was invented. Besides the fact that captcha sounds nice enough to be a buzz word it actually is short for Completely Automated Public Turing test to tell Computers and Humans Apart, although this is a bit contrived. This means that a captcha is a challenge response mechanism but it doesn’t need to be in the form of an image depicting distorted text which has to be copied in a text box which is the most common form of captchas. Creative new captchas can be found, like a transistor image which has to be read. Read the rest of this entry »

Share/Save/Bookmark No Comments

The Game of Office Decoration

Life LogoThis week I had a discussion with a colleague of mine about decoration for the new office rooms we hired. We thought of an Arduino based project, because it would just be cool to have some fun with the gadget.

We could make a giant board filled with buttons with a led in them. You’d press a button to toggle it. This board could be controlled by an Arduino and display several things on it. A clock for instance or news headlines from an arbitrary RSS feed or… since they’re buttons, Conway’s Game of Life! Read the rest of this entry »

Share/Save/Bookmark No Comments

Math behind a world sunlight map

World sunlight map fractionMy neighbour has a map of the world on the wall. You can see it from the street in front of his house. It has a backlight but that only illuminates half of the map. The transition from day to night is shaped like a sine wave most of the time. It actually is a physical world sunlight map. Of course, you can simulate this with a computer too. There even is an instance using Google maps.

As many roads lead to Rome multiple ways are possible to this simulation. One could model the sun, earth, maybe more and start ray tracing. This approach would include solar eclipses but is quite heavy by means of the load on the processor. Because of the number of calculations involved in ray tracing is quite high. The way I choose to describe fully in this article is one close to it. Using vectors pointing from a sphere (earth) to a point (sun) I map a Mercator projected map of the world on the sphere. The challenges included are the yearly orbit of earth around the sun and it’s 23.5° tilted 24 hour spin. Read the rest of this entry »

Share/Save/Bookmark 23 Comments