RegEx to match comma separated numbers with optional decimal part

This: \d{1,3}(,\d{3})*(\.\d\d)?|\.\d\d matches all of the following numbers: 1 12 .99 12.34 12,345.67 999,999,999,999,999.99 If you want to exclude numbers like 123a (street addresses for example), or 123.123 (numbers with more than 2 digits after the decimal point), try: (?<=\s|^)(\d{1,3}(,\d{3})*(\.\d\d)?|\.\d\d)(?=\s|$) A little demo (I guessed you’re using PHP): $text = “666a 1 fd 12 dfsa … Read more

How to deal with Number precision in Actionscript?

This is my generic solution for the problem (I have blogged about this here): var toFixed:Function = function(number:Number, factor:int) { return Math.round(number * factor)/factor; } For example: trace(toFixed(0.12345678, 10)); //0.1 Multiply 0.12345678 by 10; that gives us 1.2345678. When we round 1.2345678, we get 1.0, and finally, 1.0 divided by 10 equals 0.1. Another example: … Read more

What is the best way to get the minimum or maximum value from an Array of numbers?

The theoretical answers from everyone else are all neat, but let’s be pragmatic. ActionScript provides the tools you need so that you don’t even have to write a loop in this case! First, note that Math.min() and Math.max() can take any number of arguments. Also, it’s important to understand the apply() method available to Function … Read more

How to detect when a youtube video finishes playing?

This can be done through the youtube player API: http://jsfiddle.net/7Gznb/ Working example: <div id=”player”></div> <script src=”http://www.youtube.com/player_api”></script> <script> // create youtube player var player; function onYouTubePlayerAPIReady() { player = new YT.Player(‘player’, { width: ‘640’, height: ‘390’, videoId: ‘0Bmhjf0rKe8’, events: { onReady: onPlayerReady, onStateChange: onPlayerStateChange } }); } // autoplay video function onPlayerReady(event) { event.target.playVideo(); } // … Read more

What is the best way to stop people hacking the PHP-based highscore table of a Flash game

This is a classic problem with Internet games and contests. Your Flash code works with users to decide a score for a game. But users aren’t trusted, and the Flash code runs on the user’s computer. You’re SOL. There is nothing you can do to prevent an attacker from forging high scores: Flash is even … Read more

tech