Cash-for-Clunkers

Posted on Jul 01 2009 | Tagged as: politics, technology

It looks like Cash-for-Clunkers has passed. I could get $4,500. The way it’s supposed to work is you give your old to the dealer and the dealer discounts the price of the . I think the is supposed to be junked so it’s not clear there’s any trade in value.

Here are some notes:

In a nutshell, your vehicle qualifies for trade-in credit if:

• It is at most 25 years old.

• It gets 18 miles a gallon or less.

• It is drivable.

• It is registered.

• It has been insured for the past year.

You can find out what gas mileage your or truck should get here.

I’m not sure my qualifies! According to the web site my gets 19mph! I don’t believe it!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google

Mercurial, Apache, and OpenSuse 11.1

Posted on Jun 28 2009 | Tagged as: technology

’s Web Interface

Funny how some things can turn out to be much easier than you fear. I’d been meaning to make some of my code accessible via a web interface. It turned out to be much easier than I expected.

Getting Setup

I didn’t want to run as .cgi script. I’d had some initial problems with mod_python and decided I wanted to try out the newer wsgi interface.

Installing mod_wsgi

mod_wsgi was not installed by default. I went to (software..org)[http://software..org/search?q=mod_wsgi] to find an RPM. I got it and installed it:

www# wget http://download.opensuse.org/repositories/Apache:/Modules/openSUSE_11.1/i586/apache2-mod_wsgi-2.5-1.1.i586.rpm
www# rpm -i apache2-mod_wsgi-2.5-1.1.i586.rpm

I then needed to activate the wsgi module in apache2:

www# a2enmod wsgi
www# /etc/init.d/apache restart

Configuring

WSGIScriptAlias /hg /path-to-repository/scripts/hgwebdir.wsgi
<Directory /path-to-repository/scripts>
	Order deny,allow
	Allow from all
</Directory>

The WSGIScriptAlias directive is similar to the Alias directive in that it specifies either a directory as containg wsgi scripts or in this case that “/” should map to the script hgwebdir.wsgi.

Installing hgwebdir.wscgi

You’ll need to copy ’s wsgi script to where you put it in the config

cp path-to-mercurial-source/mercurial-1.2.1/contrib/hgwebdir.wsgi /path-to-repository/scripts

You then modify scripts/hgwebdir.wsgi and setup the absolute path to your repository. Something like:

CONFIG = '/path-to-repository/hgweb.config'
application = hgwebdir(CONFIG)

It’s really the assignment to application that matters (as that’s what wsgi uses).

Setting up hgweb

[web]
style = gitweb
contact = Pete Ware ware@peteware.com

[paths] / = /path-to-repository/**

The [web] section sets up defaults for all the repositories.

The [paths] directive combined with the “/**” means to find all repositories under that directory.

Setting up a project

You can clone any project you’d like to put it under the web interface. The web interface works on the underlying DB so it’s always up to date (wrt to the repository).

# cd /path-to-repository
# hg clone /orig-repository project

If you want people to be able to push to it, everything needs to be owned by the same as the web server. In the case of , that’s wwwrun:

# cd /path-to-repository/
# chown -R wwwrun  project

Controlling who can access the project

Within each project. the ./hgrc controls who can access it. For example, the following allows a user “testuser” to push. I allow push to not happen over ssl. Probably not the best idea but this isn’t critical software.

[web]
allow_push = testuser
push_ssl = false

The above uses ’s authorization.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google

‘Cash for Clunkers’ Passes House

Posted on Jun 10 2009 | Tagged as: politics

So the cash for clunkers is getting closer. It passed in the House:

In addition to having stricter fuel economy requirements, the Senate bill contains three major differences. The first is the maximum fuel economy of the trade-in vehicles, which is 17 miles a gallon. The second is there are three voucher amounts ($2,500 to buy a new that gets at least seven miles a gallon more, $3,500 for 10 m.p.g. more and $4,500 for 13 m.p.g. more). Finally, the Senate bill also offers a provision for buying a used .

So maybe that new car smell isn’t so far away. Here’s a comparison of the House and Senate version of the bill.

The estimate is that it’ll increase auto sales by 625,000. It’ll work for me!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google

Getting the keys from a std::map

Posted on May 21 2009 | Tagged as: technology

So last week I wrote about initializing a std::map from two std::vectors. How about doing the reverse? How do I get a list of the keys or a list of the values into a vector?

So I wrote a functor, based on std::unary_function, that returns the pair.first and another that returns the pair.second:

#include <utility>
#include <functional>
 
    /**
     * A functor that returns the first in a pair
     */
    template<typename PairType>
    struct first: public std::unary_function<PairType, typename PairType::first_type>
    {
	typedef typename PairType::first_type result_type;
	typedef PairType argument_type;
 
	result_type operator()(argument_type &p) const
	{
	    return p.first;
	}
 
	result_type operator()(const argument_type &p) const
	{
	    return p.first;
	}
    };
 
    /**
     * A functor that returns the second in a pair
     */
    template<typename PairType>
    struct second: public std::unary_function<PairType, typename PairType::second_type>
    {
	typedef typename PairType::second_type result_type;
	typedef PairType argument_type;
 
	result_type operator()(argument_type &p) const
	{
	    return p.second;
	}
	result_type operator()(const argument_type &p) const
	{
	    return p.second;
	}
    };

The first() template functor (from above) is used as the functor that returns the key to the std::transform() alogrithm. Here is a little fragment code that uses first(). (The test code part of a larger CPPUNIT test suite):

void TestUtils::testFirst()
{
    typedef std::map<std::string,std::string> String2StringMap;
    String2StringMap m;
 
    m["a"] = "0";
    m["z"] = "1";
    m["x"] = "2";
 
    std::vector<std::string>	keys;
    std::transform (m.begin(), m.end(),
		    std::back_inserter (keys),
		    first<String2StringMap::value_type>());
    CPPUNIT_ASSERT_EQUAL (m.size(), keys.size());
    CPPUNIT_ASSERT_EQUAL (std::string ("x"), keys[1]);
}
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google

Functor for deleting objects

Posted on May 20 2009 | Tagged as: technology

In a destructor for a class, I had a std::vector of pointers that I wanted to delete. I started to write the usual for(;;) loop and realized I do this often enough I should make it easy to use std::for_each().

Here’s the functor (based on std::unary_function):

    #include <functional>
 
    template<typename Type>
    struct deleter: public std::unary_function<Type *, bool>
    {
	bool operator()(Type * ptr) const
	{
	    delete ptr;
	    return true;
	}
    };

And here’s some sample code using it:

std::vector<Symbol *> m_symbols;
// ...
std::for_each (m_symbols.begin(), m_symbols.end(), deleter<Symbol>());

I added a return of true because some other template code wasn’t happy about “return void” — supposedly something fixed in recent compilers.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google

A better output_iterator

Posted on May 19 2009 | Tagged as: technology

I was using the std::stream_iterator, for example:

    std::vector<int>	vals;
    vals.push_back (12);
    vals.push_back (22);
    vals.push_back (5);
    vals.push_back (30);
 
    // The std::ostream_iterator appends the ","
    std::ostringstream	str3;
    std::copy (vals.begin(), vals.end(), std::ostream_iterator<int> (str3, ","));
    CPPUNIT_ASSERT_EQUAL (std::string ("12,22,5,30,"), str3.str());

It has the “,” after the last item.

So here’s an implementation that doesn’t append the seperator after the last one:

#ifndef INCLUDED_OUTITER_H
#define INCLUDED_OUTITER_H
 
#include <iterator>
 
/**
 * A replacement for std::ostream_iterator that doesn't put the
 * seperator after the last item.
 */
template<typename Type, typename CharType = char,
	 typename Traits = std::char_traits<CharType> >
class outiter : public std::iterator<std::output_iterator_tag, void, void, void, void>
{
public:
    typedef CharType			char_type;
    typedef Traits			traits_type;
    typedef std::basic_ostream<CharType, Traits>	ostream_type;
 
    /// Initialize from a stream
    outiter (ostream_type &stream)
	: m_stream (&stream),
	  m_string (0),
	  m_started (false)
    {}
 
    /// Copy constructor
    outiter (const outiter &copy)
	: m_stream (copy.m_stream),
	  m_string (copy.m_string),
	  m_started (copy.m_started)
    {}
 
    /// Initialize from a stream and the seperator 
    outiter (ostream_type &stream, const CharType *str)
	: m_stream (&stream),
	  m_string (str),
	  m_started (false)
    {}
 
    /// Assignment actually does the output
    outiter &
    operator=(const Type &value)
    {
	if (!m_started)
	{
	    m_started = true;
	}
	else if (m_string)
	{
		(*m_stream) << m_string;
	}
 
	(*m_stream) << value;
	return *this;
    }
 
    /// Just return a reference to this
    outiter &
    operator*()
    {
	return *this;
    }
 
    /// Just return a reference to this
    outiter &
    operator++()
    {
	return *this;
    }
 
    /// Just return a reference to this
    outiter &
    operator++(int)
    {
	return *this;
    }
private:
    /// The stream to write to
    ostream_type *		m_stream;
    /// The seperator (may be NULL)
    const char_type *		m_string;
    /// Flag to indicate if we've output anything
    bool			m_started;
};
#endif /* INCLUDED_OUTITER_H */

And here’s the corresponding code to use it:

    std::ostringstream	str;
    std::copy (vals.begin(), vals.end(), outiter<int> (str, ","));
    CPPUNIT_ASSERT_EQUAL (std::string ("12,22,5,30"), str.str());
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google

That new car smell

Posted on May 19 2009 | Tagged as: politics

I’m closely keeping track of that cash-for-clunkers program. It sounds like the Senate is close to approving a plan that provides a $3,500 subsidy for trading in an old gas guzzler for a more efficient !

The U.S. House of Representatives has passed a plan and the Senate is likely to do the same this week. It looks like the plan would provide a $3500 subsidy to anyone trading in a getting less than 18 miles per gallon as long as there is at least a 4-mpg improvement. (I think I got yardage on my old , not mileage.) A 10-mpg improvement would get you another $1000.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google

ClarkConnect 5.0 - Beta #3

Posted on May 12 2009 | Tagged as: technology

It looks like the next version of ClarkConnect is getting close. The 3rd beta is out. From ClarkConnect 5.0 - Beta #3 - May 8, 2009:

LDAP and Samba A great deal of effort has gone into the underlying LDAP architecture. With this more flexible and powerful architecture in place, we will be able to build some great new feature in the 5.x releases.
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google

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

Posted on May 08 2009 | Tagged as: technology

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 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<std::string,int> in this example.

So the code finally looks like:

#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <iterator>
 
void test()
{
		std::map<std::string, int>	m;
		std::vector<std::string>		keys;
		std::vector<int>			values;
 
		std::transform (keys.begin(), keys.end(),
						values.begin(), 
						std::inserter (m, m.begin()),
						std::make_pair<std::string,int>);
}
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google

Closer to a new car?

Posted on May 06 2009 | Tagged as: news, nyc, politics, technology

It’s one step closer to happening! Getting a new 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 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.
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google

Next Page »