Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- number



  Why you should be careful about optimizations

In one of my current javascript projects, I have to deal with 3D voxel coordinates. And, sometimes, I have floating points coordinates which must be converted to integers in order to convert them into proper array index. Javascript is a wonderful language, really. However, implementations are sometimes weird, and the way to do something can sometimes have very huge impacts on the performances. Worse, sometimes the classical way is more expensive than the tricky one. So, some peo...

   JavaScript,Bitwise,Floor,Trick,Optimization     2012-05-02 11:29:20

  Demo on creating worker pool in GoLang

A worker pool is a pool where a specified number of workers(usually goroutine) created and run to pick up tasks. This can allow multiple tasks to be ran at the same time while keeping the number of workers a fixed number to avoid overuse of resource in the program. There are usually two approaches of creating worker pool. One is with fixed number of workers pre-created One is creating worker when needed until the max number of workers created In this post, we will cover the demonstration of cr...

   WORKER POOL,GOLANG,GOROUTINE     2021-01-24 05:04:00

  C Preprocessor Hell

Lisp programmers should stop reading right now because they'll likely suffer severe injury of the jaw muscles as they laugh themselves silly at how hard it is to do some things in C. The C language has a pre-processor (typically called cpp) that is both infuriating and powerful. How powerful is usually best described as 'just too little' and it has happened more than once that I found myself almost - but not quite - able to do what I wanted to do. The frustration can run very deep at ti...

   C,Preprocessor,Lisp,Hell     2012-01-19 10:22:31

  Automatically post to Facebook from PHP script

Facebook is currently on of the most important publishing and traffic generating sources for many websites. Manually Cross publishing content on your own site and Facebook seems like a lot of extra work. This post guides you through the creation of a Facebook application that can automatically post messages and other types of content on your Facebook wall. Getting started Building a php script that automatically posts status updates on your wall requires the following steps: Download Faceboo...

   PHP,Facebook,API,Auto post,OAuth     2012-02-27 09:03:00

  Tricks with Direct Memory Access in Java

Java was initially designed as a safe managed environment. Nevertheless, Java HotSpot VM contains a “backdoor” that provides a number of low-level operations to manipulate memory and threads directly. This backdoor – sun.misc.Unsafe â€“ is widely used by JDK itself in packages like java.nio or java.util.concurrent. It is hard to imagine a Java developer that uses this backdoor in any regular development because this API is extremely dangerous...

   Java,Directly memory access,Tricks,JVM     2012-02-13 05:31:19

  mysql_fetch_array(),mysql_fetch_assoc() and mysql_fetch_row()

In PHP MySQL mannual. There are three functions which need to be clarified for some users who may get confused when choosing which one to use to get the result. mysql_fetch_array() : by seeting the different parameters, there are three ways to return the result set. MYSQL_ASSOC(Result set with field names as the associative indexs.It means you can use the field name as the index to get value of the specified cell). MYSQL_NUM(Result set with field names as the number indices). Or MYSQL_BOTH(...

   PHP,MySQL,resultset,comparison,mysql_fet     2011-08-05 04:53:09

  Dividing any number By 9, 90, 900 and so on

The technique for Dividing any number by 9 mentally is simply to reduce a complex division to a very simple addition. The technique can be applied from both ends i.e. from right-most digit or from left-most digit. Dividing by 9 into a mixed number from right-most digit uses the Divisibility Rules for 9: 1.     First, add all the digits together and divide by 9, keeping in mind the whole number and the remainder. 2.     Write the remainder o...

   9,90,division,algorithm     2012-03-07 05:15:06

  JavaScript's Two Zeros

JavaScript has two zeros: -0 and +0. This post explains why that is and where it matters in practice. The signed zero Numbers always need to be encoded to be stored digitally. Why do some encodings have two zeros? As an example, let’s look at encoding integers as 4-digit binary numbers, via the sign-and-magnitude method. There, one uses one bit for the sign (0 if positive, 1 if negative) and the remaining bits for the magnitude (absolute value). Therefore, -2 and +2 are encoded as f...

   JavaScript,zeros     2012-03-24 05:21:49

  Can a === 1 && a === 2 && a === 3 be true in JavaScript?

Lots of you may be aware that there is famous interview question which asks whether a == 1 && a == 2 && a == 3 can be true in JavaScript. And the answer to this question is YES. The reason is that == will do a non-strict comparison which will evaluate a to a number and this provides the possibility of dynamically return the value when every time a is accessed. Have you ever wondered whether a === 1 && a === 2 && a === 3 can be true? At first glance, it seems this ...

   JAVASCRIPT,===,STRICT COMPARISON     2018-04-06 12:17:29

  Accurate floating point number calculation in JavaScript

In JavaScript, since floating point is defined with IEEE754,there will be some accuracy issues while doing floating point number arithmetic. Here is a function which can resolve the accuracy issue. var calc = function(num1,operator,num2,len){    var numFixs = function(num){        var arr = num.toFixed(len).toString().split('.');        return parseInt(arr.join(''));    }    switch(operator){...

   JavaScript, floating point,IEEE 754,accuracy     2012-12-27 11:07:49