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

SEARCH KEYWORD -- Source Code



  You should publish your contributions of Open Source, even it’s not required

Although many Open Source projects don’t require you publish the modifications of them, I still propose you should make the changes open. The reasons are as following: (1) For other people: the out-of-box Open Source projects save your time and money, and you get benefit from them. You should not only take, but also need to give! Only if everyone shares his code, document, or whatever related, the Open Source projects can grow up healthy. (2) For yourself: You release your code can actuall...

       2017-07-18 03:53:05

  A Perl Regular Expression That Matches Prime Numbers

perl -lne '(1x$_) =~ /^1?$|^(11+?)\1+$/ || print "$_ is prime"' Can you figure out how it works? I give an explanation below, but try to figure it out yourself. Here is what happens when you run it: $ perl -lne '(1x$_) =~ /^1?$|^(11+?)\1+$/ || print "$_ is prime"' 1 2 2 is prime 3 3 is prime 4 5 5 is prime 6 7 7 is prime 8 9 10 11 11 is prime Here is how it works. First, the number is converted in its unary representation by (1x$_). For example, the number 5 gets converted into 1x5, which is ...

   Perl,Regex,Regular expression,Prime number,One line     2011-12-26 08:42:00

  C/C++ Pointer Declaration Syntax – It makes sense!

I never really liked the way pointers are declared in C/C++: int *a, *b, *c; // a, b and c are pointers to int The reason is that I am used to reading variable declarations as MyType myVar1, myVar2, myVar3; and I always read “int*” as the type “integer pointer”. I therefore wanted the following int* a, b, c; // a is a pointer to int, b and c are ints to mean that a, b and c all were of type int*, i.e. pointers to int. and I therefore found it slightly a...

   C,Pointer,Declaration,Attempt     2012-02-22 05:43:58

  A Javascript When Function

function when(conditionFunc, execFunc, interval){ if (conditionFunc()){ execFunc(); }else{ setTimeout(function(){ when(conditionFunc, execFunc, interval);}, interval); } } You have some code which should only execute when a condition is true. E.g. You have code which relies on a javascript library but can't be sure the library has loaded yet and don't want the code to execute until it has. This is common if you have a bookmarklet which injects more than one <...

   JavaScript,When,Implementation,When function     2012-02-24 05:08:34

  Paint messages will come in as fast as you let them

There is a class of messages which are generated on demand rather than explicitly posted into a message queue. If you call Get­Message or Peek­Message and the queue is empty, then the window manager will look to see if one of these generated-on-demand messages is due, messages like WM_TIMER, WM_MOUSE­MOVE, and WM_PAINT. Neil wonders, "In that program that called Invalidate­Rect 100,000 times, how many paint messages were generated?" The Zen answer to this question is "Yes." A ...

   WM_PAINT,paint message,work,Mouse move     2011-12-21 09:37:14

  2013 Google Code Jam is around the corner

According to Google Code Jam, the registration time of Google Code Jam 2013 will start on 12th March, and the deadline for registration will be 14th April 00:00UTC. This year the champion will get $15,000. Besides the prize and title, the champion will be enrolled in the qualification round in 2014 directly. Since 2003, Google Code Jam attracted many professional and students to solve the hardest algorithm problems in the world. Last year, there were over 35000 programmers participated in this c...

   Google,Code Jam 2013     2013-03-13 05:48:24

  GitHub Copilot may generate code containing GPL code

GitHub Copilot is a new AI-powered code completion tool that can generate code snippets from natural language descriptions. It is powered by OpenAI Codex, a deep learning system that has been trained on billions of lines of public code. GitHub Copilot claims to be a “copilot, not a pilot”, meaning that it is not intended to write code for you, but rather to help you write code faster and better. However, some developers have raised concerns about the legal and ethical implications of...

   GITHUB COPILOT,GPL     2023-04-21 14:21:29

  Magic CSS shape

There is a question on StackOverflow which states that someone finds a CSS sample on http://css-tricks.com/examples/ShapesOfCSS/  , the sample shows a triangle created with pure CSS. The source code is :#triangle-up {width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid transparent;border-bottom: 100px solid red;}The question is how these few lines can create a triangle? Next we give the answer and the detail illustration to this question We need to consider the B...

   CSS,Triangle,Box model,Border     2012-04-20 12:56:22

  <=> operator in MySQL

Have you ever seen "<=>" in a SQL query while using MySQL? Does it mean less and equals to and greater than? Actually if you consider it as the union of <= and =>, great, you are close to it. This is one form of equal operator in MySQL, it has the similar meaning to the = operator with some subtle difference. According to MySQL documentation, <=> is NULL-safe equal. This operator performs an equality comparison like the = operator, but returns 1 rather than NULL if both operand...

   MySQL,NULL safe,<=>     2014-03-24 06:23:22

  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