Technology

Copying a std::vector into a std::map

I had two vector’s with the first being the keys and the second being the values. It took a couple tries before I got the STL working for me!
The first thing was to check if the std::map constructors had something useful. It certainly seems like taking two sets of iterators would be a great way to initialize a map. No such luck.
So how about one of the std algorithms to copy the keys and values into the map? std::copy seemed likely but it only takes a single sequence. A little more digging and std::transform. The second version of std::transform takes two sequences, an output iterator, and a binary function to convert the two values from the two sequences into something that can be inserted into the output iterator. Perfect.
So how to turn the two values into a pair suitable for std::map? The std::make_pair
is exactly what is needed. The hard part is getting the syntax so you can pass it as a function: make_pair in this example.
So the code finally looks like:

#include 
#include 
#include 
#include 
#include 
#include 
void test()
{
    std::map  m;
    std::vector    keys;
    std::vector        values;
    std::transform (keys.begin(), keys.end(),
                    values.begin(),
                    std::inserter (m, m.begin()),
                    std::make_pair);
}
News · NYC · Politics · Technology

Closer to a new car?

It’s one step closer to happening! Getting a new car based on a trade in might actually happen. It hasn’t passed the House yet (much less the Senate) but the leadership of both parties agree on doing it.
From House Reaches a Deal on ‘Cash for Clunkers’ Program:

Under the House plan, a car trade-in that improves fuel efficiency by at least 10 miles per gallon would qualify for a $4,500 voucher, as would the trade-in of a small truck that improves efficiency by 5 miles per gallon. The new vehicle must have a minimum fuel efficiency rating of 22 miles per gallon for cars and 18 miles per gallon for small trucks.

Technology

Setting the timezone

I’ve gotten pretty careful about keeping time in UTC and then converting it to localtime for the user to understand. For the first time, I actually had to find the localtime in a non-local timezone. It’s ugly. It seems you have to mess with the TZ environment variable. Here’s what I wrote:

#include 

And here’s a code fragment that uses it:

std::string oldzone = changeTimeZone("US/Pacific");
time_t  seconds = ::time(0);
struct tm   tm_time;
localtime_r (&seconds, tm_time);
changeTimeZone(oldzone);
Politics

The Banality of Bush White House Evil

Frank Rich in the NY Times does a great job reminding us tat the Bush Whitehouse desire to invade Iraq drove so many things:

Five years after the Abu Ghraib revelations, we must acknowledge that our government methodically authorized torture and lied about it. But we also must contemplate the possibility that it did so not just out of a sincere, if criminally misguided, desire to “protect” us but also to promote an unnecessary and catastrophic war. Instead of saving us from “another 9/11,” torture was a tool in the campaign to falsify and exploit 9/11 so that fearful Americans would be bamboozled into a mission that had nothing to do with Al Qaeda. The lying about Iraq remains the original sin from which flows much of the Bush White House’s illegality.

Technology

Cars and Batteries

Fascinating profile of
Shai Agassi who’s introducing replaceable batteries for the auto industry. Part of his theory is that selling the “energy” is very profitable.
>But Agassi realized he needed one more breakthrough: some way to rapidly charge a vehicle. No drivers, he knew, will tolerate a two-hour wait to recharge when they’re on a 500-mile haul. Then one day, he and an automotive engineer were chewing over an impractical method for quickly replenishing batteries. The engineer wondered aloud: Wouldn’t the fastest way to charge an electric car be to simply replace the battery?

4C6C9BC9-7284-4EB2-910B-F0AB01834593.jpg
NYC · Politics · Technology

A new car?

Maybe I can finally buy a new car?:

The Schumer-Israel approach would provide vouchers worth up to $4,000 to drivers who turn in an older car that gets 18 miles per gallon or worse and buys a new or used car that exceeds the corporate average fuel economy for vehicles in its class by 25 percent. Taken together, these two requirements guarantee considerable oil savings and significant reductions in carbon dioxide.

Politics

Going Galt? Give me a break

I have a friend who seems to believe in Ayn Rand Objectivist philosophy and talks about Tea Parties and Going Galt.
I’m guilty of not having read Atlas Shrugged though I did like this 1000 word summary of Atlas Shrugged . I certainly enjoyed this discussion from Ezra Klein
Here’s a great review from Whittaker Chambers reviewing in 1957 Ayn Rand’s Atlas Shrugged on National Review Online:

Its story is preposterous. It reports the final stages of a final conflict (locale: chiefly the United States, some indefinite years hence) between the harried ranks of free enterprise and the “looters.” These are proponents of proscriptive taxes, government ownership, labor, etc., etc. The mischief here is that the author, dodging into fiction, nevertheless counts on your reading it as political reality. This,” she is saying in effect, “is how things really are. These are the real issues, the real sides. Only your blindness keeps you from seeing it, which, happily, I have come to rescue you from.”
Since a great many of us dislike much that Miss Rand dislikes, quite as heartily as she does, many incline to take her at her word. It is the more persuasive, in some quarters, because the author deals wholly in the blackest blacks and the whitest whites. In this fiction everything, everybody, is either all good or all bad, without any of those intermediate shades which, in life, complicate reality and perplex the eye that seeks to probe it truly.

Technology

Google Voice/Grand Central vs. Skype

I decided to give Skype a try, again, after I started working with a few people that use it for chat, teleconference and video conferencing.
Contrary to what some people are saying, it seems like a complementary offering to Google Voice. I spend a lot of time in front of my computer and there’s a certain benefit to being able to call and be called from it. But I’m not about to give out my skype phone number for people to call — I don’t always have a computer on.
On the other hand, if I add my Skype phone number to Google Voice and gave out the Google Voice phone number, than rather I wanted to answer a call from my computer, my cell phone, or my home phone becomes irrelevant.
From NY Times: Google Voice May Threaten Other Phone Services:

Google Voice allows users to route all their calls through a single number that can ring their home, work and mobile phones simultaneously. It also gives users a single and easy-to-manage voice mail system for multiple phone lines. And it lets users make calls, routed via the Internet, free in the United States and for a small fee internationally.

Technology

Qt Labs Blogs » Lightning-fast JavaScript

Here are the performance numbers about Qt4.5’s improvement in JavaScript performance that I mentioned in yesterday’s post. It offers about a seven times performance improvement on ix86 processors. From Lightning-fast JavaScript:

For Qt 4.5, the JavaScript engine is powered by a new bytecode interpreter, along with optional JIT (just-in-time) compile support. They are often referred as SquirrelFish and SquirrelFish Extreme, respectively. This interpreter has been developed by Apple engineers working on WebKit in order to speed-up JavaScriptCore, the backbone of WebKit’s JavaScript engine. The interpreter makes its first appearance in the recent Safari 4 Public Beta, where it is dubbed as Nitro JavaScript Engine.

Longer is better:
44F6492C-A237-484F-86AF-8A6038ACC285.jpg
96FB80DE-1DC1-449C-803E-98AC6C88CDFE.jpg

Technology

Thunderbird and Gmail

In my quest for the ultimate email, rss, and newsreader I’m giving Thunderbird 3.0b2 a try. Check out this post for a few more details. So far, decent for email, decent for news, but it’s weak for rss.
First, read these two tutorials:

Then, you ned to figure out keyboard shortcuts
If you are curious about how messages get retrieved, check out this tidbit on IMAP and the “IDLE” command from Entire message fetched when opening a IMAP message:

mail.imap.fetch_by_chunks controls whether Thunderbird tries to fetch a message body (or any other MIME body part) in chunks. mail.imap.chunk_size controls the size of the chunk. It currently defaults to 10240 bytes. If you set the chunk size too big, it defeats any attempt to fetch just the message body. One problem with enabling fetching by chunks is it breaks the optimizations built into the TCP/IP protocols, and adds extra overhead as each chunk has to be acknowledged. If tweaking the “MIME Parts On Demand” preferences doesn’t help, or if it works but you get poor performance, try disabling fetching by chunks.