Archive for November 2011
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):
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
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:
- The parenthesis around (set var=val). I use them to avoid the blank space issue.
- 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.
- 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.
- Using the for /f operator to parse a text file.
- The forfiles command.
First, a rant. “HTML5” is a buzzword. When you hear people talk about “HTML5”, what they talk about is:
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.
PORTABILITY DOES NOT EXIST.
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;">
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.
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
I heard a legend that I refuse to believe. It goes like this:
Euler studied irreducible factorizations of polynomials . He noticed that all coefficients that appear in the factors are 1, –1 and 0. E.g. . He attempted to prove that that’s always the case, but he couldn’t. He computed all factorizations up to 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 , 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).