Combobox.SelectedValue does not work properly in VS 2008

November 10, 2010

Found out that if Combobox.Sorted is set to true then Combobox.SelectedValue returns not the actual selection. As a possible workaround I used Combobox.SelectedItem – that worked for me at least.

Team explorer does not show Builds folder, but Build with a red cross

October 27, 2010

This really helps –

first of all you should to rename the cache folder for Team Foundation “C:\Documents and Settings\[accountname]\Local Settings\Application Data\Microsoft\Team Foundation\2.0″ (in Vista or Windows 2008 the path is “C:\Users\[accountname]\AppData\Local\Microsoft\Team Foundation\2.0\Cache”)

Then execute this command line: Start > Run : “devenv /resetuserdata”.

Kindle shows most recent books in reversed order?

September 20, 2010

If your Kindle shows most recent books in reversed order, probably its clock is not synchronized – connect turn wireless on and do Sync and Check for Items.

On vacation till September 1st

August 21, 2010


jQuery: Novice to Ninja – what I’ve found useful

June 26, 2010

Recently I’ve read a book  jQuery: Novice to Ninja. I was using jQuery for a long time, however I felt that I was using only a small part of this library, so I decided to read some books about it. The books is rather good and easy (and interesting) to read. Here I want to write some jQuery’s tips that I didn’t know and want to store for the future.

//Selects all direct child elements specified by "child" of elements specified by "parent".
$('parent > child')
//Height toggling:
$('#bio h3').click(function(){
{' height' : ' toggle' } , ' slow' , ' easeOutBounce'
 );}) ;
//Loads the selected element from AJAX result's html:
$('#biography' ).load('computadors. html div: first') ;
//Loading indicator that disappears when response comes:
$('#biography').html('loading…').load(url) ;
//Validate plugin is awesome!
$('#signup form').validate({
 rules: {
 name: {
 required: true
//Checks all checkboxes:
$('.check-all: checkbox').change(function(){
 var group = ':checkbox[name=' + $(this).attr('name') + ' ] ' ;
 $(group).attr('checked' , $(this).attr(' checked'));
}) ;
//Travers elements with an until-condition:
$('h2:first' ).nextUntil('h2') ;
//jQuery has map function!
$. map, $. slice, $. trim,

jQuery is a really great thing!

Auto trimming field value / Django forms

June 7, 2010

I don’t know why this is not done by default, but..

from django import forms

class TrimmedCharField(forms.CharField):
	def clean(self, value):		
		return forms.CharField.clean(self, value.strip())

class Form1(forms.Form):
	f1 = TrimmedCharField(widget=forms.Textarea(attrs={'rows': 6}))
	f2= TrimmedCharField(widget=forms.Textarea(attrs={'rows': 6}))

django registration form custom field

June 1, 2010

In most cases when a user registers in your django application you need to know more than just user name, password and e-mail. To add custom fields to the registration form you should pass form_class parameter to the register view function – it’s easy, but saving additional data could be rather complex. There are solutions that show how to use a custom django registration backend – or G! This is so complicated! Likely, django has signals that are sent during the registration process and we can use them – (the version of the doc is 0.8, however, it works with 1.2). We need user_registered signal.

In my case I needed to add just one field to the registration form – user’s City.

from models import City
import strings
from registration.forms import RegistrationForm

class UserRegistrationForm(RegistrationForm):
    city = forms.ModelChoiceField(queryset=City.objects,, empty_label=strings.notDefined)

Then pass this form to the register view in – register records should go before (r’^accounts/’, include(regUrls)),

from registration.views import register
import registration.backends.default.urls as regUrls
import regbackend

urlpatterns = patterns('',
	url(r'^accounts/register/$', register, {'backend': 'registration.backends.default.DefaultBackend','form_class': UserRegistrationForm}, name='registration_register'),
	(r'^accounts/', include(regUrls)),

Now we need to add a subscription to the user_registered signal. Assume that we have a custom profile with city information:

import profile

def user_created(sender, user, request, **kwargs):
	form = UserRegistrationForm(request.POST)
	data = profile.Profile(user=user)
	data.city_id =["city"]

from registration.signals import user_registered

That’s it – much easier, right? :)


I’ve made a really simple and not so well-formed sample application that can be a good starting point in resolving your problems
It assumes that you have Python26 folder with installed django 1.2.2 on c:\
There are 2 users: test with password test without city information and test2 with password 1 with city one set in its profile,
You may want to check the file to setup email settings so that it could send activation letters.
Just launch start.cmd and follow and links.

(Русский) – подбор жилья для отдыха на курортах

May 19, 2010

Sorry, this entry is only available in Русский.

Draw an arrow on Google map

April 25, 2010

I wrote a simple javascript function that draws an arrow on a Google Map (based on

function drawArrow(pt1, pt2, color)
	var lineWidth = 10;
	var lineOpacity = 0.7;
	var arrowSize = 50;

	function addHead(point, theta, zoom, color)
		var p = prj.fromLatLngToPixel(point,  zoom)
		var x = p.x, y = p.y;
		var t = theta + (Math.PI/4) ;
		if(t > Math.PI)
			t -= 2*Math.PI;
		var t2 = theta - (Math.PI/4) ;
		if(t2 <= (-Math.PI))
			t2 += 2*Math.PI;
		var pts = new Array();
		var headLength = arrowSize;
		var x1 = x-Math.cos(t)*headLength;
		var y1 = y+Math.sin(t)*headLength;
		var x2 = x-Math.cos(t2)*headLength;
		var y2 = y+Math.sin(t2)*headLength;
		pts.push(prj.fromPixelToLatLng(new GPoint(x1,y1), zoom));
		pts.push(prj.fromPixelToLatLng(new GPoint(x,y), zoom));
		pts.push(prj.fromPixelToLatLng(new GPoint(x2,y2), zoom));
		var head = new GPolygon(pts, color, 0, 1, color, 1);

	var polyline = new GPolyline([pt1, pt2], color, lineWidth, lineOpacity);
	var zoom = map.getZoom();
	var p1 = prj.fromLatLngToPixel(pt1,  zoom);
	var p2 = prj.fromLatLngToPixel(pt2,  zoom);
	var dx = p2.x-p1.x;
	var dy = p2.y-p1.y;
	var theta = Math.atan2(-dy,dx);

	addHead(pt2, theta, zoom, color);

Where pt1, pt2 are GLatLng instances, map is GMap2 and color is a string representation of color. Unfortunately, this function does not support map’s zooming – arrows heads grow bigger when zooming in.

The result looks like:
Continue Reading »

  • arrow

django add bitwise logics to the filter query

April 9, 2010

Django has a great ORM, but it has some limitations while performing queries, e.g. it does not allow to do bitwise operation. Likely, django’s QuerySet has extra method ( This method allows developers to write raw sql that will be included into the generated by ORM query. The tricky part is that all fields included in that raw sql must present in filter function.
For example:

res.filter(table__flags__isnull=False).extra(where=['NOT ("applicationName_table"."flags" | %s <> "applicationName_table"."flags")' %  condition])

Here we have a datatable with name table with a mask field called flags and an application called applicationName. If there was not filter(table__flags__isnull=False) this query would fail with “applicationName_table”.”flags” is unknown column. I could write any lookup expression with this filed that does not affect the result (checking that this filed is not null is quite OK for that).

Hope, this will help you!

Powered by Wordpress and MySQL. Theme by Shlomi Noach,