I have cerated this GUID/UUID generator, which is short, simple and efficient. This post includes explanations of the algorithm below. The function is as simple as this: To test the performance, you can run this code: I’m sure most of you will understand what I did there, but maybe there is at least one person that will need an explanation: The algorithm: The Math.random() function returns a decimal number between 0 and 1 with 16 digits after the decimal fraction point (for example 0.4363923368509859). Then we take this number and convert it to a string with base 16 (from the example above we’ll get 0.6fb7687f).Math.random().toString(16). Then we cut off the 0. prefix (0.6fb7687f => 6fb7687f) and get a string with eight hexadecimal characters long.(Math.random().toString(16).substr(2,8). Sometimes the Math.random() function will return shorter number (for example 0.4363), due to zeros at the end (from the example above, actually the number is 0.4363000000000000).…

Read more

If you a web developer, maybe you encountered this annoying thing. Let’s say you need to write a list of choices, i.e. questions – answers. Let’s define that all the questions are optional and you can select just one answer per question. The way you should implement it, is using inputs with radio type, that’s fine and this how it should be.Example code is: But, as I said, the questions are optional. What’s happening now is when I check an option, I cannot uncheck it anymore! A problem. What is favorite time? Morning Noon Evening What is your preferable paying method? Credit Card Check Paypal Cash Here, I will show you how to solve this problem.There are two solutions to solve it, both involves JavaScript (and jQuery to ease the work): Convert all radio buttons to checkboxes: What is favorite time? Morning Noon Evening What is your preferable paying method?…

Read more

I spent hours to find out how to do it. And believe me or not, I found nothing on the whole internet about how to solve it. Actually there is a simple way to do that after the event “deviceready” has been triggered (as described on the PhoneGap’s API Docs), it is simple as: The “deviceready” trigger, tell us when all native components are loaded and ready to use. Which means, that there is no way to determine whether the page loaded from PhoneGap or not using the PhoneGap plugin itself. You can check the UserAgent, but it is not always true, because it is possible to open the page through the mobile’s browser which is the same UserAgent as loaded from PhoneGap. Let’s give a typical example, that describes the case better. Let’s say I want to perform an action when the device is ready and the document is…

Read more

3/3