Pontiac Grand Prix и прочие американцы

Ощущения от езды на американском автомобиле по американским же дорогам

Car

Волею судьбы приходится бороздить просторы техасщины на Pontiac Grand Prix. Это такой немаленький автомобильчик (см. фото). Другие кусочки машинки можно увидеть здесь. 3.8-литровый 6-ти горшковый 203-сильный движок разгоняет этот 1,5-тонный танк до 100 км/ч за 8,5 секунд. И не так прожорлив, как может показаться: 9,8л на 100 км в смешанном цикле. Тех. характеристики можно посмотреть тут. Для сравнения Волга 31105 разгоняет свои 1,5 тонны до сотни за 13,5 секунд при помощи 2,4-литрового 4-х горшкового движка, кушая при этом 9, а за городом 13,5 литров в городе на сотню.

Теперь о субъективщине.
Я как-то с детства привык ездить на машинках с механической коробкой передач. Ну, казалось бы, нет ничего проще, чем пересесть на автомат. Ан нет, с непривычки давил на тормоз левой ногой. Из-за чего начальник, имевший неосторожность не пристегнуться на заднем сиденье, долбанулся об переднее головой. 2 раза %). А я удивлялся, насколько чувствительные тормоза у машинки 🙂 Хотя, они, собственно, такие и есть. Слишком чувствительные. Это очень неудобно, т.к. любое неосторожное нажатие приводит к тому, что машина просто резко встает. А резко тормозить у буржуев не принято. Они все тормозят очень плавно, что, безусловно, радует. Так что будь я конструктором, тормоза я бы приделал к этой машинке другие.

Теперь про газ (педальку, а не известный автозавод). Газ, прямо скажем, неадекватный. Просто не знаешь, что от него ожидать. С непривычки, иногда стартую с пробуксовкой, несмотря на то, что газ жму несильно. С другой стороны тормозной автомат понимает, что надо переключиться на пониженную только через несколько мнгновений после того, как утапливаешь педальку. Почему эти мнгновения иногда кажутся вечностью, я думаю, объяснять не надо :). Да и вообще, педалька, мягко говоря, неинформативная. Совершенно не чувствуешь адекватную отдачу и сложно дозировать нажатие. При езде по местным дорогам возникает ощущение, что тебя несет потоком. Обгонять не получается, т.к. во всех рядах едут с одинаковой скоростью даже на трассах %). Да и жутковато на таком корабле обгонять, 5 метров в длину все-таки. Хотя, наверное, на Porsche тут тоже было бы скучно ездить :/
Зато в машинке есть такая приятная фичка как круиз-контроль. Т.е. едешь, жмешь на кнопку и педаль газа можно отпустить – машинка будет сама поддерживать наебходимую скорость. В городе фичка бесполезная, а вот на трассе – достаточно приятная.
Кондиционер в машинке плюшевенький. Я, конечно, не избалован этим буржуйским изобретением, но впечатления достаточно грустные. Печка не печет, кондишен охлаждает так себе. Зато вентилятор работает практически бесшумно. И еще что мне понравилось, громкость музыки на штатной магнитолке увеличивается при увеличении скорости движения.

Вот что тут замечательное – это дороги. Это просто местная достопримечательность. Дело даже не в качестве покрытия (тут большинство дорог бетонные) а в том, что дороги хорошие ВЕЗДЕ! Даже в самой захудалой улочке в самом заныканном уголке города. Вот, что важно! Причем везде широкие дороги, несколько полос в каждую сторону, с газончиком и паребриком между направлениями движения. Ну а развязки там (см. фото) – вообще отдельная песня. Так что приезжайте к нам на техасщину – вместе попоем 🙂

Причем тут “прочие американцы”? А дороги-то кто делал. :))

Advertisement

Подробный рецепт солянки по-шагам

Солянка по-Артемовски 🙂 Из расчета на большую кастрюлю: Ингридиенты:

  1. Говядина, 1 цельный кусок > 0.5 кг;
  2. Колбасы (полукопченые, копченые, вареные), копчености, можно сосиски. Все вместе > 0.75 кг;
  3. Поллитровая банка хороших (крепких) соленых огурцов (с рассолом). Если соленых огурцов не нашли (есть только маринованные в уксусе), то рассол можно заменить небольшим количеством каперсов

    (2-3 чайные ложки). Уксус из под маринованных огурцов в суп добавлять нельзя – вкус супа будет полностью испорчен.

  4. Немного зеленых (можно черных) маслин (шт 6-8) без косточек;
  5. 1 лимон;
  6. 2 картофелины;
  7. 4 крупных луковицы;
  8. 2 морковки;
  9. Томатная паста;
  10. Подсолнечное масло для жарки;
  11. Сметана (обычно около 250г на кастрюлю, в зависимости от Вашего вкуса);
  12. Соль по вкусу;
  13. Черный перец молотый по вкусу;
  14. Грибы по вкусу;

Процесс:

  1. Моем говядину;
  2. Кладем говядину в кастрюлю одним цельным куском, туда же 2 луковицы (неразрезанные, целиком), туда же 2 морковки, заливаем полностью водой по края, чуть подсаливаем, ставим на огонь;
  3. Когда морковка готова, ее вытаскиваем. Мясо довариваем до полной готовности (обычно не менее часа);
  4. Когда мясо готово вытаскиваем мясо и лук из бульона (бульон НЕ сливаем, он – основа супа), вареные луковицы выкидываем(!);
  5. Мелко режем 2 луковицы, режем картошку маленькими кубиками (5мм х 5мм х 5мм);
  6. Берем сковородку, смазываем маслом, чтобы не пригорало, кладем нарезанные луковицы и ставим на огонь, слегка обжариваем добавляем туда картофель, распределяем его по всей сковородке, обжариваем картофель (необязательно до полной готовности);
  7. Нарезаем говядину, колбасы, копчености, сосиски и прочие мясопродукты, которые у нас есть, маленькими длинненькими параллелепипедиками (примерно 5мм х 3мм х 20мм), добавляем к картошке туда же дабавляем очень мелко нарезанную вареную морковку, при желании можно добавить чуть-чуть нарезанных грибочков и обжариваем это все;
  8. Добавляем пару больших ложек томатной пасты, нарезанные такими же мелкими параллелепипедиками огурцы (1/2 – 3/4 банки) и еще обжариваем (можно при этом чуток посолить);
  9. Сваливаем все это обжаренное в бульон из-под говядины, добавляем туда маслины, разрезаем лимон на 4 части и не более 1/4 выжимаем в бульен, затем добавляем туда 1/4 часть рассола из-под огурцов (или пару маленьких ложек каперсов, если нет рассола), ложку томатной пасты, тут же можно добавить чуть-чуть черного молотого перца и варим 10-15 мин под крышкой;
  10. После выключения даем супу настояться под крышкой мин 15;
  11. Уже в тарелки добавляем сметану по-вкусу и еще дополнительно лимонного сока.

Know-How:

  1. Очень важно НЕ пересолить. Если что-то солите – соли надо добавлять совсем немного, т.к. соленость будет от рассола и соленых огурцов;
  2. То же для перца – обычно щепотку-две;
  3. Картошку резать непосредственно перед тем как жарить, иначе обветрится;
  4. На остроту так же влияет лимон, так что можно его тоже чуть меньше заливать, так же убедитесь, что косточки НЕ попадают в суп, когда Вы выжимаете лимон, для этого перед тем как его выживать надо выковорять все косточки, можно также разрезать половинку еще пополам, чтобы косточки было удобнее выковыривать.

В итоге суп готовится очень легко и быстро, т.к. вываривание говядины не требует внимания, а обжарка и варка все вместе занимает мин 30 (если за вас уже все ингридиенты порезали 🙂 ). По последней статистике при готовке вдвоем с неопытным поваром с момента начала и до подачи на стол (последержания под крышкой) прошло 2 часа 30 мин. Еще один хороший рецепт солянки можно найти тут: http://chefcook.ru/2009/02/20/%D1%80%D0%B5%D1%86%D0%B5%D0%BF%D1%82-%D0%BC%D1%8F%D1%81%D0%BD%D0%BE%D0%B9-%D1%81%D0%BE%D0%BB%D1%8F%D0%BD%D0%BA%D0%B8/ Приятного аппетита!

Break and continue statements will stop exception flow

As it is said in The Java Language Specification (http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.15):
The preceding descriptions say “attempts to transfer control” rather than just “transfers control” because if there are any try statements within the break target whose try blocks contain the break statement, then any finally clauses of those try statements are executed, in order, innermost to outermost, before control is transferred to the break target. Abrupt completion of a finally clause can disrupt the transfer of control initiated by a break statement.
Let’s look into next example:

public class Test {
	private static void test() throws Exception {
		for (int i = 0; i < 3; i++) {
			try {
				throw new Exception("Exception text");
			} finally {
				System.out.println("Finally exception " + i);
				continue;
			}
		}
		System.out.println("Impossible");
	}

	public static void main(String[] args) throws Exception {
		test();
		System.out.println("Impossible 2");
	}
}

will produce output:

Finally exception 0
Finally exception 1
Finally exception 2
Impossible
Impossible 2

So, be extremely careful with your breaks!

How to access overridden methods of superclass of a superclass in Java?

Let us consider an example:

public class Test2 {
  static class TestClass1 {
      int x = 1;
      String test() {
          return "1";
      }
  }

  static class TestClass2 extends TestClass1 {
      int x = 2;
      String test() {
          return "2";
      }
  }

  static class TestClass3 extends TestClass2 {
      int x = 3;
      int testX() {
          return ((TestClass1)this).x;
      }
      String test() {
          return super.test();
      }
  }

  public static void main(String[] args) {
      TestClass3 obj = new TestClass3();
      System.out.println(obj.testX());
      System.out.println(obj.test());
  }
}

It produces expected output

1
2

The point is that there is no way to call test() method of the TestClass1 class!

super.super.test()

won’t compile but

((TestClass1)this).test()

will produce java.lang.StackOverflowError.

Despite that we can access superclass members of any level by casting this to appropriate class (see The Java Language Specification at http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.11.2), polymorphism allows us to access immediate superclass only, not overridden methods of higher levels (see The Java Language Specification at http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.12.4.9).

Some approach for writing equials() and hashCode()

The problem described in details in http://www.hibernate.org/109.html The problem is that if we implement equals()/hashCode() as comparison and hashCode() of entity’s ids (see http://djeang.blogspot.com/2005/08/override-equals-and-hashcode-methods.html) then the hashCode() (and, possibly, equals()) will change after saving entities if ids are generated by DB. To solve this issue I can suggest to use inner classes with equals()/hashCode(). It will not affect Hibernate’s internal collections taskflow, but will allow you to use ids in equals()/hashCode() after entities are persisted. On other hand hashCode() and equals() will not change in your persistent objects after you have saved it.

 public class Test3 { static class SomeEntity { private Integer id; private String data; public SomeEntity() { super(); } public SomeEntity(Integer id, String data) { super(); this.id = id; this.data = data; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getData() { return data; } public void setData(String data) { this.data = data; } public class SomeEntityId { private SomeEntity link = null; public SomeEntityId(SomeEntity link) { super(); this.link = link; } @Override public boolean equals(Object obj) { if (this == obj) return true; if ((obj == null) || (obj.getClass() != this.getClass())) return false; if (this.link.getClass() != ((SomeEntityId) obj).getLink().getClass()) return false; Integer thisId = link.getId(); Integer otherId = ((SomeEntityId) obj).getLink().getId(); if ((thisId == null) || (otherId == null)) throw new RuntimeException("Id not defined!"); return thisId.equals(otherId); } @Override public int hashCode() { Integer thisId = link.getId(); if (thisId == null) throw new RuntimeException("Id not defined!"); return thisId.hashCode(); } public SomeEntity getLink() { return link; } }; public SomeEntityId getDTO() { return new SomeEntityId(this); } } public static void main(String[] args) { SomeEntity e0   = new SomeEntity(null, "no id"); SomeEntity e1 = new SomeEntity(1, "e1"); SomeEntity e2 = new SomeEntity(2, "e2"); SomeEntity e3 = new SomeEntity(3, "e3"); SomeEntity e33 = new SomeEntity(3, "e33"); Set aSet = new HashSet(); // aSet.add(e0.getDTO()); aSet.add(e1.getDTO()); aSet.add(e2.getDTO()); aSet.add(e3.getDTO()); aSet.add(e33.getDTO()); System.out.println("set size: " + aSet.size()); System.out.println("set:"); for (SomeEntity.SomeEntityId seId : aSet) { SomeEntity se = seId.getLink(); System.out.println("entity: " + se.getData()); } } }

I even could suggest you to add it to entities code generation in such tools as Hibernate Tools. I would also like to mention also that SomeEntityId object could be stored in transient field of an entity. Comments are welcome.

Algorithm for generating serialVersionUID for java entities

Here is some way of generating serialVersionUID for java entities.
It is stable in sense that it depends only on your schema, not JVM/time or date of creation.
On the other hand it depends on all fields in entity.
If we have next n fields:
typeName_1 fieldName_1;
typeName_2 fieldName_2;

typeName_n fieldName_n;
we could calculate
serialVersionUID =
(fieldName_1.hashCode() XOR typeName_1.hashCode()) * 31^0+
(fieldName_2.hashCode() XOR typeName_2.hashCode()) * 31^1 + … +
(fieldName_n.hashCode() XOR typeName_n.hashCode()) * 31^n
where fieldName_i.hashCode() is hashCode() of fieldName_i string
(for int id; it will be “id”.hashCode())
and typeName_i.hashCode() is hashCode() of typeName_i string
(for int id; it will be “int”.hashCode())
so, we will be independent from
1) JVM
2) time/date of creation
and depend on
1) fields order
2) field types
3) field names

Get rid of your nested if operators!

Every one of you know how it is disappointing that you can not use

switch

operators with strings, doubles, your custom objects, etc. But anyway sometimes it is possible to get rid of your nested ifs if you will use static maps. Let us consider an example: here we need to set JavaBean properties of certain types:

 protected static Object fillTestBean(Object bean) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
  Method[] methods = bean.getClass().getMethods();

  for (Method method : methods) {
   if (RTTIUtils.isSetter(method)) {
    Class type = RTTIUtils.getSetterType(method);
    if (type == String.class)
     RTTIUtils.invokeSetter(bean, method, testStr);
    else if (type == boolean.class)
     RTTIUtils.invokeSetter(bean, method, testBoolean);
    else if (type == byte.class)
     RTTIUtils.invokeSetter(bean, method, testByte);
    else if (type == char.class)
     RTTIUtils.invokeSetter(bean, method, testChar);
    else if (type == short.class)
     RTTIUtils.invokeSetter(bean, method, testShort);
    else if (type == int.class)
     RTTIUtils.invokeSetter(bean, method, testInt);
    else if (type == long.class)
     RTTIUtils.invokeSetter(bean, method, testLong);
    else if (type == float.class)
     RTTIUtils.invokeSetter(bean, method, testFloat);
    else if (type == double.class)
     RTTIUtils.invokeSetter(bean, method, testDouble);
    else if (type == Boolean.class)
     RTTIUtils.invokeSetter(bean, method, testBooleanObj);
    else if (type == Byte.class)
     RTTIUtils.invokeSetter(bean, method, testByteObj);
    else if (type == Character.class)
     RTTIUtils.invokeSetter(bean, method, testCharacterObj);
    else if (type == Short.class)
     RTTIUtils.invokeSetter(bean, method, testShortObj);
    else if (type == Integer.class)
     RTTIUtils.invokeSetter(bean, method, testIntegerObj);
    else if (type == Long.class)
     RTTIUtils.invokeSetter(bean, method, testLongObj);
    else if (type == Float.class)
     RTTIUtils.invokeSetter(bean, method, testFloatObj);
    else if (type == Double.class)
     RTTIUtils.invokeSetter(bean, method, testDoubleObj);
    else if (type == Date.class)
     RTTIUtils.invokeSetter(bean, method, testDate);
   }
  }

  return bean;
 }

(here all variables starting with test are constants)
Seems really annoying to write all this ifs and, also what if we will need to check values? Another function will also need this nested ifs!
In this case I usually do the following (factory method -like solution):

 private static final Map initObjects = new HashMap();
 private static boolean isCosideredType(Class type) {
  return initObjects.containsKey(type);
 }
 static {
  initObjects.put(String.class, testStr);
  initObjects.put(boolean.class, testBoolean);
  initObjects.put(byte.class, testByte);
  initObjects.put(char.class, testChar);
  initObjects.put(short.class, testShort);
  initObjects.put(int.class, testInt);
  initObjects.put(long.class, testLong);
  initObjects.put(float.class, testFloat);
  initObjects.put(double.class, testDouble);
  initObjects.put(Boolean.class, testBooleanObj);
  initObjects.put(Byte.class, testByteObj);
  initObjects.put(Character.class, testCharacterObj);
  initObjects.put(Short.class, testShortObj);
  initObjects.put(Integer.class, testIntegerObj);
  initObjects.put(Long.class, testLongObj);
  initObjects.put(Float.class, testFloatObj);
  initObjects.put(Double.class, testDoubleObj);
  initObjects.put(Date.class, testDate);
 }

 protected static Object fillTestBean(Object bean) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
  Method[] methods = bean.getClass().getMethods();

  for (Method method : methods) {
   if (RTTIUtils.isSetter(method)) {
    Class type = RTTIUtils.getSetterType(method);
    if (isCosideredType(type)) {
     RTTIUtils.invokeSetter(bean, method, initObjects.get(type));
    }
   }
  }

  return bean;
 }

Creating Web 2.0 RIA applications with Flex and Rails

Flex now is much for web development: we have OOP there, fine web-services integration, code and layout separation and more.
I personally think that the best way of creating web application is designing (or modeling) how it’ll look like for the end-user, what and what it going to afford to the end-user. So, let us think we already have some Flex web-application and going to connect it to some web-server to make it do something meaningful.
We have at least 4 options here, we can use:

  1. Custom XML-based HTTP service;
  2. Custom non-XML HTTP service;
  3. SOAP-based web-service;
  4. AMF (Adobe proprietary) based service.
1. Custom XML-based HTTP service

Flex will send HTTP request and receive XML answer like following:

<?xml version="1.0" encoding="UTF-8" ?>
<list>
  <item product="Computer">
    <UID>12321</UID>
    <CPU>4Gh</CPU>
    <RAM>2Gb</RAM>
    <HDD>400Gb</HDD>
  </item>
</list>

Pro here is that you can do comparatively small XML here (smaller that SOAP one).
Contra is that you are responsible for constricting XML on the server side and working with it (say, using DOM) on the client side.
It is rather inconvenient to do this additional work dealing with some XML structures, but many systems work just the way I described here.

2. Custom non-XML HTTP service

Similar to previous approach, but here you deal with yourself designed metadata like:

list[
  Computer[
    UID=12321
    CPU=4Gh
    RAM=2Gb
    HDD=400Gb
  ]
]

It can be not so verbose as XML, but you are now responsible for parsing your custom structures by yourself. It has so many troubles that it even does not worth to be considered, unless you write system like AMF by yourself.

3. SOAP-based web-service

Absolutely pain-free method, since now nearly all web-application frameworks have transparent built-in methods for SOAP based web-services. So does Flex. Troubles could begin here when you experience high loads with crowds of users. Constructing and parsing big XMLs will kill your web-servers and channels. SOAP does best with heterogeneous systems integration like those used in b2b, but it is too heavy for ordinary web applications.

4. AMF-based service

Pros here come from the nature of the protocol. It is fast binary over HTTP. Designed just for Rich Internet Applications. Why not to use proprietary protocol for communication with server if you already have chosen proprietary Flex system to be used? The reasons could be: you don’t know how to integrate it in your server and you are afraid of possible troubles by dealing with proprietary technology. Here in this article we will consider both questions.
Let us be more exact. There are 2 versions of the protocol: AMF3 for Flex and AMF0 for Flash. So let us focus on AMF3 only (further in this article I’ll use AMF in meaning AMF3).
There are some frameworks for AMF: Adobe Flex Data Services (http://www.adobe.com/products/flex/dataservices/), AMFPHP (http://amfphp.org/), WebORB (http://www.themidnightcoders.com/weborb/). Maybe there are some others. Frameworks are available for .NET, Java, PHP and Ruby on Rails. But I’ve found only one available for Rails. It is WebORB. So further in this article I’ll describe my experience about dealing with WebORB plugin for Rails.

Flex and Rails

Good news is that Flex applications works fine with Rails via WebORB (see http://www.themidnightcoders.com/weborb/rubyonrails/gettingstarted.htm how to use it). Bad one is that it conflicts with number of other plugins like act_as_attachment (we wrote workarounds by changing the WebORB plugin).

Sessions

Another inconvenience is that WebORB service classes which you write for your web services are plain classes, but not something inherited. So you don’t have those nice features like ones you have for your controllers or SOAP web-services. Therefore, your services are stateless by default, since they do not have an access to the session object (HTTP session maintained via cookie). We wrote some utility classes and slightly changed WebORB to add session object. But you can choose to maintain session on the client side by SharedObject Flex class: http://livedocs.adobe.com/flex/2/langref/flash/net/SharedObject.html

File upload

There are no obvious ways to upload file via AMF. The only way to upload by the Flex that we have found was using FileReference + URLRequest objects. There are some obstacles here. The URLRequest initializes other HTTP Session than AMF one’s. Therefore we can’t identify user who makes URLRequest on the server side. The workaround for this problem is to send additional information with URLRequest to make it possible to identify a user. Another inconvenience is that URLRequest can’t get more than http status code as a result (no messages or values).

Search Engine Optimization and mobile access

Search Engine Optimization (SEO) stays for providing readable HTML data for search engines like google.com, yahoo.com, and others. Usually the main argument against using Flash/Flex is the absence of SEO possibility. But there is a workaround for this issue. The trick here is that you can create a simple xHTML site with all SEO information and then a user loading such page, JavaScript will load your Flex on corresponding page. The big advantage of this approach is that it automatically makes your site available for mobile devices (WAP 2.0) if you use xHTML Mobile Profile DTD.

Types mapping

By tests we’ve found that it is the next (Flex <-> Ruby):

  1. int <-> Fixnum
  2. Numeric <-> Float
  3. Date <-> Time
  4. String <-> String
  5. Boolean <-> Boolean

Be aware, that if you choose “:decimal” type for database column it will not be mapped to convertible Ruby type and therefore not accessible in Flex.

There is an interesting site concerning Flex and Ruby questions: http://flexonrails.net/. I could recommend you to look throw this article: http://www.flex888.com/2007/09/20/10-flex-and-ruby-on-rails-integration-examples.html
and this one http://webddj.sys-con.com/read/295396.htm

Good luck!

Approaches to search ZIP codes within given radius

There are several approaches to get zip codes within given radius from given zip:

  1. Round circle by square if zips given by points;
  2. Exact 3D geometry calculate if zips given by points;
  3. Exact GIS calculate if zips given by polygons.

Approximation by square

We approximate circle by square on surface, where:

  1. latitude +- radius/EARTH_RADUIS
  2. longitude +- radius/(EARTH_RADUIS*cos(latitude))

cos here is because longitudes distances differ depending on latitudes (say, in polar it is 0).

The databases for 1999 is an accessible open source, but up to date database costs money. Free database:
http://svn.baconbear.com/rails_plugins/acts_as_locateable/trunk/data/zip_code_data.csv

Open source database is about 42 000 records. Up to date is about 72 000. See, for instance:

  1. http://www.zip-codes.com/
  2. http://www.zip-code-database.org/?
  3. http://www.google.com/search?q=zip+codes+database?

Exact 3D calculations

3D coordinates:

  1. x= EARTH_RADIUS*sin(latitude)*cos(longitude)
  2. y= EARTH_RADIUS*sin(latitude)*sin(longitude)
  3. z= EARTH_RADIUS*cos(latitude)

Search points must be within sphere:

x*x + y*y + z*z <= radius*radius

It is non-efficient table full-scan implementation.

See http://en.wikipedia.org/wiki/Spherical_coordinate_system

Exact zip polygon databases

Here you have to install open-source PostGIS (http://postgis.refractions.net/) system on your PostgreSQL and buy zip codes polygon database.
After installing PostGIS you can query zip codes within given radius the next way (http://postgis.refractions.net/pipermail/postgis-users/2007-February/014760.html):

SELECT z.zipcode FROM zipcode z, zipcode z2 WHERE z2.zipcode = '02109' AND expand(z2.the_geom, "whatever radius you want goes here but your spatial ref needs to be in that metric or you need to convert the radius") && z.the_geom AND distance(z.the_geom, z2.the_geom) <= "radius"

Zip codes polygon databases:

  1. http://maps.huge.info/blog/2007/04/zip_code_polygon_databases.html
  2. http://www.google.com/search?q=zip+codes+poligon+database

Or, if you use RoR, you can use the following plugins:

As far as I understand they use Google API, so they have some restrictions.