Posted in : Programming

The typing symbol hack

Introducing the symbolTyper js library ♥

Do you remember as a kid playing with the Wingdings font of Microsoft Word on Windows 95 ? Personally it’s one of my favourite memories. I used to always activate the font and type on the keyboard to discover which symbols appeared on the screen. Every key was hiding a symbol. I never really understood why this font even existed mixed in with Times New Roman and Arial. It was like a pirate in the navy, discarding any character encoding rule, outputting whatever it wanted, like a crazy font. It seemed very odd that engineers would come up with that since it follows no logic and the use is really not obvious. Anyway, I found it very fun to play with and always ended up making some posters or invites with it. In the end I would do something that approached this :

For some reason, I particularly loved the bomb symbol, it is very unique, I’ve never seen it in any other font. So this is what the hack I want to share today made me think of, typing symbols in my childhood. High moment of almost creativity.

Continue reading

By value, by reference in javascript

The pass by reference mechanism in javascript

Lately I have realized some useful facts about the pass by reference mechanism in javascript.
Let me share them here.

To cut to the chase, there is no such thing as passing a variable as reference in javascript. Variables are always passed as values in arguments. This means that what you can do in PHP for example when you do function test(&$val){} is not possible in javascript, there is no special keyword or symbol to do that.

However, there are some cases when you can “simulate” this behaviour in javascript. But before showing you how to do that, let’s make a recap.

Continue reading

Posted in Code, Programming, Wiki

Tagged

Binary Insert : How to keep an array sorted as you insert data in it ?

With javascript and recursion

Recently I played solving the overlapping rectangles problem. This problem is simple, it is about finding out among a set of rectangles laid out on a surface which are the ones that overlap, with code of course. I will certainly detail my solution later but since it is very big and requires a bit of work and graphics, I prefer starting by sharing small bricks of the solution now.

A brick of the solution involves scanning the x coordinates of each rectangles like you’re moving from left to right reading every x coordinate of a rectangle you encounter, both left and right side. In computing terms, this means you need a structure to put the x coordinates in, and the scanning means the structure needs to be sorted : first x coordinate is the first coordinate you encounter and therefore the smallest one, last x is the largest.

I picked an array as the data structure so I needed this array to be sorted at all times to track the x coordinates. In real life conditions, the rectangles are thrown at you in chaos order and you have to add the x coordinates to your array and keep it sorted. How would you do that? This is the very problem I intend to expose and solve in this article :

How to keep an array sorted as you insert data in it?

My code is in javascript but the reasoning I will describe is totally language agnostic, you can always apply it to your own language.
Continue reading

Posted in Code, Algorithms

Tagged ,

jGridder : how to fit elements in a sized grid

A recursion pattern for UI

Today I want to share about jGridder : https://github.com/eloone/jgridder.

jGridder is a javascript UI component that I developed to fit a number of elements in a sized html grid.
It solves this problem :

Given a height and width and a number of items, how do I place those items as squares in a grid that fits those dimensions?

To see what I mean, peek at the demo : http://eloone.net/jgridder/demo/.

In this post I will share my approach to design the script and tackle the problem, it’s not a tutorial about the code itself. But hopefully it will enlighten and help you regarding similar problems you might have in UI. The focus will be on the method.

Continue reading