Mar 07
If you ever have the need to represent a date/time (or part of a date/time) as a string for programmatic rather than human consumption (e.g. you are defining a save file format or a network protocol), please use ISO 8601 unless you have a very strong reason not to.
For more information, please read what the W3C has to say about ISO 8601 style date and time formats.
Mar 07
I recently received a bug report for my quick-and-dirty TCP debugging tool tcpconndbg where it was creating a large number of zombie processes. The person who filed the bug, Peter Viskup, was even kind enough to send a patch. While this is old news to anyone with extensive Unix programming experience, always remember the following:
If you create a child process using fork(), you must either:
- Explicitly retrieve the child process’s exit code using one of the
wait() functions (e.g. waitpid())
- Tell the system that you aren’t interested in the child process’s exit code by using either:
sigaction() with the SA_NOCLDWAIT parameter (preferred)
signal(SIGCHILD, SIG_IGN); (for systems which do not support sigaction())
As I fixed this bug, I realized I hadn’t looked at tcpconndbg in 5 years. My how programming style changes…
Jan 31
The folks behind chicagocrime.org are at it again — this time with a broader focused site called EveryBlock.
Here’s Chicago’s EveryBlock page, here’s where I work (the Loop).
Jan 30
Here is some quick-and-dirty SQL to calculate an geometric annual return (as a percent) from a column of monthly returns (in percents).
-
/* Convert the annualized number back to a percent */
-
SELECT (T3.AnnHPR - 1) * 100 AS GeomAnnRet
-
FROM
-
(
-
/* Annualize the holding period return */
-
SELECT POWER(T2.HPR, 12.0 / T2.NumReturns) AS AnnHPR
-
FROM
-
(
-
/* Calculate the holding period return over the time
-
period.
-
-
POWER(10, SUM(LOG10(n))) is a simulated PRODUCT(n)
-
aggregate function.
-
-
The precision of POWER is determined by the precision
-
of the first argument, so use a lot of decimals. */
-
SELECT POWER(10.0000000000000000,
-
SUM(LOG10(T.MonthReturn))) AS HPR,
-
COUNT(*) AS NumReturns
-
FROM
-
(
-
/* Convert all percent returns to multipliers (1% ->
-
1.01) */
-
SELECT 1 + MonthPctReturn / 100 AS MonthReturn
-
FROM …
-
) AS T
-
) AS T2
-
) AS T3</code>
Update 2008-01-30 10:52PM: Here’s the equivalent “one-liner”:
-
SELECT 100 * (POWER(POWER(10.000000000000000,
-
SUM(LOG10(1 + MonthPctReturn / 100))),
-
12.0 / COUNT(*)) - 1)
-
FROM …
Jan 30
Raymond Chen wrote an article today about how he couches his writing to preempt “nitpicking”. This hit close to home.
In my first drafts, I frequently add phrases such as “I think …” and adverbs such as “often”; the title of this blog post is an allusion to such behavior. These changes add precision but cause dramatic harm to readability and authority. I now make conscious effort to minimize these types of phrases.
It’s too bad Raymond feels the need to shift the balance the other way.
Jan 29
James Fallows, a correspondent for the Atlantic, has written an article entitled “The $1.4 Trillion Question describing the tenuous economic relationship between China and the United States. Former Treasury Secretary Lawrence Summers has aptly described the relationship as the “balance of financial terror”.
The most shocking aspect of the relationship is the sheer size of China’s reserves — $1.4 trillion and counting. To provide perspective, $1.4 trillion is enough to purchase all of the following companies outright:
In 2007 alone, China added $461.9 billion to its reserves. This was nearly enough to buy Exxon-Mobil ($463.64 billion). Imagine China buying an Exxon-Mobile every year.
Other countries also have large supplies of foreign reserves (Japan, the United Arab Emirates, and Russia are the runners-up per Fallows). What they do with them will have profound effects on the American economy.
Jan 24
Looking at these policymakers’ reactions in their entirety leads to the conclusion that this Fed is willing to react to large falls in asset prices that it feels are unwarranted by fundamentals. This is a change that I applaud. I only hope that this new approach is not asymmetrical and that US central bankers will see the need to respond to large increases in equity, fixed-income, and housing prices when they inevitably come.
Cecchetti, Stephen. “Bernanke’s Fed shows that it can be nimble.” The Financial Times 24 January 2008.
I predict the Fed will take up a symmetric approach to monetary policy at the same time the BLS takes up a symmetric approach to quality adjustment1 when calculating CPI. In short, never.
For example, how much has inflation increased due to tasteless tomatoes or how much modern air travel resembles steerage?
I have no problem with quality adjustment in theory, but intellectual honesty demands both symmetry and, for proper comparison, a recalculation of past CPI numbers with quality adjustment taken into account. However, given the impracticality of the latter, any comparison of post-quality adjustment to pre-quality adjustment CPI figures should be performed with a giant asterisk.
And don’t get me started on intra-category substitution. Inflation should compare the price of beef to the price of beef, not the price of beef to the price of today’s cheapest meat.
Jan 09
While reading the Mandelbrot set chapter in Dewdney’s The New Turing Omnibus, I realized that this would be a great test application for Microsoft’s new interactive Web application framework Silverlight. Below is the component, its source code, and a few things I learned along the way.
Beware: the Mandelbrot set is computationally expensive and may appear to lock up your web browser. If a “Stop running this script?” dialog pops up, please click no to allow the calculations to finish.
Read the rest of this entry »
Jan 04
Let’s say you have the following function:
-
void AppendChar(std::string& s, char ch)
-
{
-
s += ch;
-
}
What happens if this function is exported as an ordinal function from a DLL (not an inlined piece of code inside a header) and you call it from an EXE?
Read the rest of this entry »
Dec 15
From the Congressional Budget Office, a graph of actual and projected federal spending:

Note that the vast majority of the growth of projected spending in Medicare and Medicaid is due to projected increases in health care costs.
The graph really says it all.
Recent Comments