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

SEARCH KEYWORD -- Return



  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

  How regular expression works

Rob Pike wrote 30 lines of codes to realize a simple regular expression matcher in his book The practice of Programming. This piece of code is really cool. Let's take a look at the code.Meaning of different characters.Character Meaning c General character . Match any single character ^ Match start of a string $ Match end of a string * Match zero or many occurrences of a character /*match :Test the regexp in text*/int match(char* regexp,char* text){    if(regexp[0] == '^')&n...

   Regular expression,Implementation,Rob Pike,C     2012-06-25 05:23:41

  Carriage return and line feed

In programming and document editing, we may frequently encounter carriage return and line feed, i.e the well known CRLF.  But do you know about the history and difference of carriage return and line feed? Before computer came out, there was a type of teleprinter called Teletype Model 33. It can print 10 characters each second. But there is one problem with this, after finishing printing each line, it will take 0.2 second to move to next line, which is time of printing 2 characters. If a new...

   CR,CARRIAGE RETURN,LINE FEED,LF,NEW LINE,CRLF     2017-02-19 08:29:23

  try { return } finally {}

Do you know what value will be printed when following program is ran? class Test { public int aaa() { int x = 1; try { return ++x; } catch (Exception e) { } finally { ++x; } return x; } public static void main(String[] args) { Test t = new Test(); int y = t.aaa(); System.out.println(y); } } And before answering the above question, do you have answers to following questions? If ther...

   JAVA,JAVA INTERVIEW QUESTION     2016-09-26 08:06:28

  Google CEO Sundar Pichai : Google is open to return to China

At the Code Conference on Wednesday, Google CEO Sundar Pichai expressed his thought on Google's position in China. He expressed the openness of Google to return to China. "Google is in China....But Google Search is not there in China...But personally for me, I care about serving users globally in every corner. I always thought Google is for everyone, that applies to China, too. So wherever possible, we want to be in China to serve Chinese users....If we do it in a right and thoug...

   GOOGLE,CHINA,SUNDAR PICHAI,CODE CONFERENCE     2016-06-02 01:09:21

  Implementing DESede/ECB/NoPadding cipher algorithm in GoLang

By default, GoLang doesn't provide the ECB mode cipher for DESede though there is CBC mode provided. In cases we need to encrypt/decrypt data with ECB mode, we need to implement those by ourselves. This mode is frequently used when encrypting/decrypting PIN block which is small block data less than 16 bytes. In this post, we will introduce how to implement the DESede/ECB/NoPadding algorithm in GoLang by using the existing cipher support. Here we will not cover how DESede works in detail, instead...

   SECURITY,SAMPLE,GOLANG,DES,DESEDE,3DES     2019-07-29 06:43:50

  C++ : string beginWith and endWith

C++ is an very powerful programming language. It is efficient and flexible. When writing C++ programs, we may often need to process strings and often we need to check whether a string begin with some substring or end with some substring. We can use following functions to ahieve these:     static bool beginWith(const std::string str,const std::string needle){        return (!str.compare(0,needle.length(),needle));    }    ...

   C++,beginWith,endWith,     2012-08-31 06:53:44

  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

  Bill Gates to return as Microsoft's white knight?

Summary: Could and should Bill Gates return to day-to-day responsibilities at Microsoft? Fortune is reporting there’s a rumor to that effect. Fortune reported on December 8 that there’s talk Microsoft Chairman Bill Gates might be mulling a comeback, largely to help boost Microsoft’s stagnant stock price and employee morale. I have to say I am very, very, very skeptical on this one. First, it seems this is a single-sourced report....

   Microsoft,Change,Bill Gates,Return,White Knight     2011-12-09 07:39:39

  Arrays.equals() vs MessageDigest.isEqual()

Both Arrays.equals() and MessageDigest.isEqual() are used to compare the equality of two arrays. They can be interchangeably in many cases. However, they do have some differences which lead to different use cases in real applications. One difference is that the arrays passed to MessageDigest.isEqual() cannot be null while it's ok for Arrays.equals(). The one major difference between these two methods is that Arrays.equals() is not time-constant while MessageDigest.isEqual() is time-constant. Thi...

   Arrays.equal(),MessageDigest.isEqual(),Java,Security     2015-05-14 22:03:29