Move Successful

General No Comments »

If you see this post, the move to my new web hosting provider was successful.

California

General No Comments »

Last month, my wife and I vacationed to California. Here are some pictures from that vacation:

Read the rest of this entry »

STL Map Use

STL 2 Comments »

What’s wrong with the following code?

  1. template<typename T1, typename T2>
  2. struct my_pair
  3. {
  4.     typedef T1 first_type;
  5.     typedef T2 second_type;
  6.  
  7.     my_pair() : first(T1()), second(T2()) {}
  8.     my_pair(const T1& v1, const T2& v2) : first(v1), second(v2) {}
  9.  
  10.     T1 first;
  11.     T2 second;
  12. };
  13.  
  14. template<typename T1, typename T2>
  15. inline bool operator<
  16.     (
  17.     const my_pair<T1, T2>& x,
  18.     const my_pair<T1, T2>& y
  19.     )
  20. {
  21.     return (x.first < y.first || x.second < y.second);
  22. }
  23.  
  24. void f()
  25. {
  26.     typedef my_pair<…, …> key_type;
  27.     typedefvalue_type;
  28.     typedef std::map<key_type, value_type> map_type;
  29.  
  30.     map_type map;
  31.     // Use map
  32. }

Read the rest of this entry »

STL Vector Use

STL 5 Comments »

I recently wrote a piece of code that looked something like the following:

  1. static const int NUM_TOTAL_VALUES = …;
  2. typedefT;
  3.  
  4. // Create vec and reserve NUM_TOTAL_VALUES spaces for later insertion
  5. std::vector<T> vec(NUM_TOTAL_VALUES);
  6.  
  7. // Insert values into vec
  8. for (int i = 0; i != NUM_TOTAL_VALUES; ++i)
  9.     vec.push_back();
  10.  
  11. // vec should now have NUM_TOTAL_VALUES values in it (but doesn’t!)

What’s wrong with this code?

Read the rest of this entry »

Managed Wrappers and Hidden Interdependencies

C#, C++ 2 Comments »

Let’s say you have the following unmanaged code:

  1. #pragma unmanaged
  2.  
  3. class Stream {}; // Conceptual stream class
  4.  
  5. class StreamWriter
  6. {
  7. public:
  8.     StreamWriter(Stream* pStream) : m_pStream(pStream) {}
  9.     ~StreamWriter() { /* Use m_pStream in some way */ }
  10.  
  11.     …
  12. private:
  13.     Stream* m_pStream;
  14. };
  15.  
  16. void f()
  17. {
  18.     Stream stream;
  19.     StreamWriter streamWriter(&stream);
  20.  
  21.     // Use streamWriter
  22.  
  23.     // streamWriter is destroyed
  24.     // stream is destroyed
  25. }

Note that StreamWriter’s destructor uses m_pStream (perhaps by flushing the stream). This means that the order of destruction is importantStreamWriter must be destroyed before its underlying Stream is.

Now let’s try to write and use some simple managed C++ wrappers for these classes:

  1. #pragma managed
  2.  
  3. public __gc class ManagedStream
  4. {
  5. public:
  6.     ManagedStream() : m_pStream(new Stream) {}
  7.  
  8.     // NOTE: This is a finalizer, not a determinstic destructor  
  9.     ~ManagedStream() { delete m_pStream; }
  10.  
  11. public private: // Make accessible by ManagedStreamWriter
  12.     Stream __nogc* m_pStream;
  13. };
  14.  
  15. public __gc class ManagedStreamWriter
  16. {
  17. public:
  18.     ManagedStreamWriter(ManagedStream* pStream) :
  19.         m_pStreamWriter(new StreamWriter(pStream->m_pStream)) {}
  20.  
  21.     // NOTE: This is a finalizer, not a determinstic destructor  
  22.     ~ManagedStreamWriter() { delete m_pStreamWriter; }
  23.  
  24. private:
  25.     StreamWriter __nogc* m_pStreamWriter;
  26. };
  27.  
  28. void f()
  29. {
  30.     ManagedStream stream = __gc new ManagedStream();
  31.     ManagedStreamWriter streamWriter =
  32.         __gc new ManagedStreamWriter(stream);
  33.  
  34.     // Use streamWriter
  35.  
  36.     // GC will clean up stream and streamWriter
  37. }

See the problem?

Read the rest of this entry »

Nightly MySQL Backups

Unix No Comments »

Courtesy of Dave, here’s a script I put into crontab to perform nightly full backups of my WordPress MySQL database:

#!/bin/sh

DATE=`date +%Y-%m-%d`
BACKUPDIR=$HOME/.mysql-backup

USERNAME=XXXXX # TODO
PASSWORD=XXXXX # TODO
DATABASE=XXXXX # TODO

if [ ! -d $BACKUPDIR/$DATABASE ]; then
  mkdir $BACKUPDIR/$DATABASE
fi

mysqldump --user=$USERNAME --password=$PASSWORD $DATABASE > $BACKUPDIR/$DATABASE/$DATE.dump
bzip2 -9 $BACKUPDIR/$DATABASE/$DATE.dump

Home Depot and Nardelli

General No Comments »

Yesterday, Home Depot, the world’s third-largest retailer by sales, announced a big change: Mr. Nardelli was leaving the company, taking an exit package valued at about $210 million, including $20 million in cash severance.

Lublin, Joann S., Ann Zimmerman, and Chad Terhune. Behind Nardelli’s Abrupt Exit [$]. The Wall Street Journal 2007 Jan 4: A1.

Home Depot’s share price fell 8% during Mr. Nardelli['s] tenure, which began in December 2000. The company is locked in a fierce battle with Lowe’s, which boasts newer, brighter stores and a better image with many shoppers. Lowe’s stock has risen 188% in the past six years.

Ibid.

Mr. Nardelli moved to cut back on higher-paid full-time employees with experience as plumbers or handymen, and to rely more on part-time workers with less experience answering home-improvement questions from customers. Frequently, Mr. Nardelli found himself fending off questions about deteriorating customer service and about whether cost-cutting was the cause of that.

Ibid.

[As part of his exit package negotiation,] Mr. Nardelli submitted a one-page list of perks he was willing to drop, including personal use of the six corporate jets…

Ibid.

guaranteed $3 million annual bonus… [emphasis mine]

Ibid.

Much of [Mr. Nardelli's compensation] package is due to the rich employment contract he negotiated with the Home Depot board before leaving General Electric Co., where he was one of three finalists to succeed Jack Welch. Mr. Welch convinced his board to give all three finalists large batches of stock options, telling board members they would have to make good on only one man’s options, one director says. Upon leaving GE, the board was told, the two runners-up likely would use those awards to negotiate pay at their next jobs — which is exactly what Mr. Nardelli and James McNerney, who is now CEO of Boeing, did.

Ibid.

“Some defenders of CEO pay argue that CEOs are rewarded for increasing the stock or the overall value of the company, but judging by today’s market reaction, Mr. Nardelli’s contribution to raising Home Depot’s stock value consists of quitting and receiving hundreds of millions of dollars to do so,” [said Barney Frank (D., Mass.), chairman designate of House Financial Services Committee]

Ibid.

Comments Disabled

General No Comments »

Due to a tragic loss of data, along with incessant spam problems, I have disabled all comments on my blog.

Update 2007-01-16 9:54AM: I have reenabled comments, but all previous comments were lost. Yet another case study in the importance of backups.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in