How to Change Disabled Button Background, Focused TextBox Border etc in Windows Phone

In the properties tab or attributes of XAML, the level of control you can have over Silverlight controls is rather limited. You can’t change their behaviours in different states. To actually control it, you need to create a ControlTemplate. Sounds innocent enough but it’s basically forcing the user to redefine a user control and recreate the button or the textbox manually from their constituents (border, grid etc) which is extremely labour intensive if all you want to do is just change say the colour of the border when it is selected.

Instead of recreating the control from scratch, you can let Microsoft Expression Blend do some part of that job for you. Style your control to your liking as much as you can in Blend and then right-click to select Edit Template -> Edit a Copy. Then you get to define a key. Think of it like a CSS class and name it as you wish. Define it in the Application (App.xaml) so you can use it everywhere in your application. This will then generate a ControlTemplate for you based on the instance of control you selected Edit Template on. Continue reading


Read Raw JSON Data from HTTP POST for ASP.NET MVC 4 Web API

The Web API is a good step catching up to Ruby on Rails and Django but isn’t nearly as well documented. If your posted data doesn’t match exactly a model object, it’s hard to figure out how to just get all the data out and process it yourself. Inside the

public void Post()

tag, you can have access to a Request member from ApiController and with it, you can do

JsonObject input = Request.Content.ReadAsAsync().Result;

to get the data out. A key detail is that if you do so, you cannot put any parameters in the Post method declaration or it will try to bind it to which ever parameter type you specified.


Can’t Ping Windows Parallels VM in Bridged Network Mode

If you can’t see your Windows 7 VM from Mac OS X in bridged mode, the problem could be the location set on your Windows 7 OS. It’s possible that with bridged mode, Windows can’t figure out the network time and default to ‘Unidentified network’ which is the same as if you chose Public and put it into a safer mode than if you chose Home or Work. Unfortunately if it were the case, you can’t really change the network type. If your VM is going to stay home and never wonder into the dangerous wildland, you can just set the ‘Unidentified network’ to be treated as a private network via:

Start -> secpol.msc
Network List Manager Policies -> Unidentified Networks
Select Private

Then you’re done!


Pythonic Coding Example

Great article about the elusive ‘Pythonic’ coding:

http://artifex.org/~hblanks/talks/2011/pep20_by_example.html


8 Ways to Share your Git Repository

Excellent article describing how you can collaborate with your development team:

http://www.jedi.be/blog/2009/05/06/8-ways-to-share-your-git-repository/


Mac Doesn’t Go to Sleep

When you make the Mac go to sleep but it just stays on with the screen black, you can use the

pmset -g

to display you current power management settings and see the entry for sleep that will tell you the problem causing process PID


Login SAP CRM as a Separate User than Single Sign-On

If you have SSO enabled on SAP CRM, you can sometimes get stuck with your user on your computer’s certificate and you can’t get out of it with logout, delete cookies, no auto-login etc. But what you can do is add

?sap-user=DIFFERENTUSER

at the end of your usual sap/bc/bsp/sap/crm_ui_start/default.htm URL and the login dialog will prompt. Try it in conjunction with ‘Clear SSL state’ button in the Content tab of Internet Options


iPhone rings twice with text message

It was kinda off putting with my new iPhone 4S to find out that Apple makes SMS alerts ring twice (once on receive and one reminder) instead of having an LED light for alerts like in Android or Blackberry. Kind of a workaround rather than a real solution to the problem of how to find out I have alerts pending when I missed the first alert. Apple operates on a push principle and Google/RIM operates on pull.

Anyway, if I have reason to miss the first one, I most likely won’t notice the second one. It’s also misleading when it rings twice because you’d think there’s 2 messages.

To turn that functionality off, go to Settings->Notifications->Messages->Repeat Alert->Never.

20111101-093215.jpg


Django Compress Static Files and Compile CSS

I started off looking for a request time compiler of LESS for Django and initially found django-css which seems to serve the purpose great. Compressing static files on the fly is definitely a nice added bonus as well. It does so by containing a fork of django_compressor. But on further inspections, I jumped ship. The original project, django_compressor, sees a more regular update and is now Django 1.3 ready while the ‘successor’ isn’t. Funny thing is django_compressor supports compiling any CSS formats compilable via command line. With a better documentation overall, seems like the original has beat the sequel.


Django Log to File

In the official Django logging docs, it wasn’t very clear about how to log to files. As you can understand, Django can use any Python logging classes that are all listed here. One of them is FileHandler. To use it, just add this to your settings.py Continue reading


Logitech Performance MX Review

Got a Logitech Performance MX on “special” at Best Buy this weekend (80$ for a mouse… what a slaughter) because I just have a laptop mouse and am tired of not having anything to rest my palm on. At first, it’s great. Looks like a race car, good performance, nice receiver, rechargeable on the fly etc. Then, something feels off… something uncomfortable. I turn the mouse over and the fatal flaw. The sensor isn’t placed at the center of the mouse but almost under your thumb… Continue reading


Validate and Format Addresses using Google API

Suppose you want to make some web app that lets users input addresses. I would be nice to

  1. Weed out minor misspelling
  2. Standardise format (proper capitalisation, abbreviated province/state or full name etc)
  3. Input in freeform but store civic number, street name, city etc separately
  4. Verify the address exists of course

Some governmental entities provide this information via public APIs but if you want a uniform service, why not use Google? Continue reading


Python Debug with ipdb

A quickie:

import ipdb; ipdb.set_trace()

This puts a breakpoint in the code using ipdb. It has the advantage of having better formatted output, tab completion etc over the vanilla pdb


PIL: Get RGB Value from GIF

If you load a GIF file with PIL via Image.open(‘giffile.gif’) and then try to look at its pixels, you would get integers instead of tuples since the GIF pixels refers to one of the 256 colours in the GIF colour palette. The palette would then contain the RGB value of the pixel.

To avoid all this hassle and just get RGB tuple directly:

gif = Image.open('giffile.gif')
rgbimage = GIF.convert ('RGB')
rgbimage.getpixel((0,0))
>>>(231, 10, 54)