Drawing Blanks

Premature Optimization is a Prerequisite for Success

Archive for November 2011

Zen and the art of batch files

leave a comment »

I often use batch files for quick and dirty scripting tasks. Much more often than the modern scripting tools like Windows Scripting Host and Powershell. Because I’m familiar with the concepts of batch scripting since DOS 3.0. Figuring out how to accomplish a simple task using the modern tools would take me longer than writing it as a bat file. Even though bat files are outdated they have been evolving. The capabilities of cmd scripting and the command line utilities in Windows 7 and Windows Server are way superior compared to DOS.

I’d like to share some bat file tips and tricks using this example (provided as is, for demo purpose, not intended for production use):

@echo off
rem Recursively Deletes all files older than the specified age
rem from folders specified in the folderList file and logs output to a file.
rem folderlist file format: "<path>",<mask>,<maxAgeInDays>
rem e.g.: "C:\aaa",*.tmp,30

(set folderList=%~dp0folderList.txt)
(set logpath=%~dp0)
(set datestamp=%date:~10,4%-%date:~4,2%-%date:~7,2%)
(set log=%logpath%\%datestamp%.log)

echo %datestamp% %time% >> %log%
for /F "tokens=1-3 delims=," %%f in (%folderList%) do (
echo %%f %%g %%h >> %log%
forfiles /p %%f /m %%g /d -%%h /s /c "cmd /c if @isdir==FALSE echo @file >> %log% & del @file >> %log%"

Things to notice:

  1. The parenthesis around (set var=val). I use them to avoid the blank space issue.
  2. What is %~dp0 ? It is the path where the batch file is located. %0 is the full path to the current script, and the ~dp parses the drive and path out of it. This variable is especially useful in Windows Vista and higher since when you run the script “as administrator” it is not started in the folder in which it’s located.
  3. Parsing the %date% variable using ~Pos,Len to create the log file name. Note that this method relies on the date format set in the system locale.
  4. Using the for /f operator to parse a text file.
  5. The forfiles command.

Written by bbzippo

11/26/2011 at 2:52 am

Posted in programming

The place of HTML5 in Windows 8

with 2 comments

First, a rant. “HTML5” is a buzzword. When you hear people talk about “HTML5”, what they talk about is:

Canvas and WebGL, Plugin-free video, Excessive JavaScript, CSS3, HTML5

Most people don’t care about business app development. They mostly get excited about the ability to present graphics and video and to program simple games without plugins like Flash or Silverlight.

And those who do care about business app development got excited when they heard from Microsoft that HTML5 will be the language of choice in the WinRT (Metro App) framework. Well, people always get excited when someone promises them PORTABILITY. They just can’t stop believing in the Portability Myth.



In particular, HTML5 in Windows 8 will NOT be a tool for developing portable applications. In fact, HTML5 is NOT going to be a Windows 8 app development tool at all. Take a look: http://msdn.microsoft.com/en-us/library/windows/apps/br229565(v=VS.85).aspx . Do you see “HTML5” mentioned anywhere in the documentation? Is this HTML5?:

<div style="display: -ms-box;">
     <div data-win-control="WinJS.UI.DatePicker"></div>


The so called “HTML5 applications” on Windows 8 will in fact be developed using JavaScript, PROPRIETARY HTML EXTENSIONS that will allow you to use the WinRT PROPRIETARY controls and APIs, and some CSS3 for layouts (although you will mostly be using PROPRIETARY layout containers).

So don’t get excited about portability.

In fact, it’s going to be much easier to port applications between WinRT XAML, Silverlight and WPF than between WinRT “Html5” and in-browser Html5.

MS is introducing and hyping HTML5 only to attract developers who are used to JavaScript/DOM/CSS coding.

Written by bbzippo

11/20/2011 at 11:39 pm

Posted in programming

Neutrinos aren’t slowing down

leave a comment »

I wasn’t the only one who had suspicions about waveform matching in the OPERA experiment:


However, “A new measurement of the neutrino speed is being conducted using 2 ns long bunches spaced by 500 ns from the CNGS beam. In such a measurement the effects discussed here would no longer apply.”

According to rumors (http://twitter.com/#!/jsheltino), those measurements have been conducted, and the neutrinos are still arriving too early!

Update: same rumor was also  leaked to Russian media by Natalia Polukhina (an OPERA Collaboration Board member).

Update: official word: http://press.web.cern.ch/press/PressReleases/Releases2011/PR19.11E.html


“pioneer or a nut” is an anagram of “opera neutrino”.

Written by bbzippo

11/17/2011 at 6:02 am

Posted in Uncategorized

What did Euler know?

leave a comment »

I heard a legend that I refuse to believe. It goes like this:

Euler studied irreducible factorizations of polynomials x^n - 1. He noticed that all coefficients that appear in the factors are 1, –1 and 0. E.g. x^{15}-1=(x-1)(x^2+x+1)(x^4+x^3+x^2+x+1)(x^8-x^7+x^5-x^4+x^3-x+1) . He attempted to prove that that’s always the case, but he couldn’t. He computed all factorizations up to x^{100}-1 and he didn’t see any coefficients other than 1, –1 and 0.

He died convinced that this property always holds. But it doesn’t. Had he factorized x^{105}-1, he would see some 2s too.

Did Euler know that the factors are cyclotomic polynomials? Maybe not. Even if he noticed that, he probably wouldn’t be able to prove it. Even if he believed that, he wouldn’t be able to derive any general properties of the coefficients.

But if he really computed all those factorizations up to the power 100, how come he didn’t notice any patterns? I bet he did! He must have come up with some clever methods of computations, and he couldn’t miss the fact that the structure of the factorization of the polynomial depends on the prime factorization of the power. Then why would he stop at 100? Why not check 3*5*7 = 105 ?

Ok, let’s assume the legend is true. Then I’m curious if Euler would really think that the property is true or would consider it an open conjecture? We know that Euler didn’t care much about formal foundations. He died before Cauchy was born, so he never got a chance to put his work on a formal ground. Laplace, on the other hand (according to another legend), did recheck all his work after he learned about Cauchy’s formalism. (I mentioned Laplace here; I think he was at least as brilliant as Euler).

Written by bbzippo

11/09/2011 at 3:47 am

Posted in math