Author Archives: xiao

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)

Python Challenge Level 14: Italy – Code

Used a NumPy array. Doesn’t work if the diagonal+1s are white of course.

import Image
from numpy import array, zeros, uint8
 
line = Image.open('wire.png')
# third dimension is for colours
a = zeros((100, 100, 3), dtype=uint8)
 
step = array([0, 1])
position = array([0, 0])
count = 0
 
# continue until when the next spot expected to be unfilled is filled
while not max(a[tuple(position)]):
	# paint colour
	a[tuple(position)] = array(line.getpixel((count, 0)))
 
	# if reached a wall
	if max(position + step) > 99 or min(position + step) < 0 or max(a[tuple(position + step)]):
		# change direction
		step = (abs(step) ^ 1) * (-step[0] if step[0] else step[1])
 
	# advance
	position += step
	count += 1
 
# convert to image
Image.fromarray(a).save('swirl.jpeg')

How to Convert Numpy Array to Tuple

a = array((1, 2, 3))
print a
>>> array([1, 2, 3])
tuple(a)
>>> (1, 2, 3)

Pretty lame right?


ABAP Get REST XML and Parse XML

This tutorial will help you use ABAP to connect to any web service and process the resulting output. ABAP has native support for XML so it will be easiest to get your information in XML format rather than JSON and others. For this example, I will use a CBC’s news feed but it can be Digg top stories, Twitter, anything. The XML should look something like the picture below where each news article is enclosed in <ITEM> tags. Continue reading


Ctrl-Alt Hotkey Conflict with Virtual Machines

On most virtualisation software like VMWare’s etc, the guest machine’s hotkeys which requires ctrl-alt (such as ctrl-alt-f1 etc for tty change in Linux) can be blocked because ctrl-alt is used to release mouse/keyboard with the VM software. If you use it only occasionally, you can first temporarily disable the release hotkey by pressing ctrl-alt-space then your intended hotkey such as ctrl-alt-f1

Source


VMWare Tools vmware-open-vm-tools-kmod Install Issue

Trying to install VMWare tools from packages.vmware.com/tools repository in Ubuntu but getting a error while installing packages? There seems to be package dependency going back to open-vm-tools-kmod-generic but it doesn’t exist. When you try to install the next level of package, it would say

“PreDepends: vmware-open-vm-tools-kmod-… but it is not installable”

Unfortunately the VMWare Installation Guide isn’t clear on this matter whereas the Ubuntu documentation is much better. It shows that you can either use the open source version directly available via apt-get or you can build the kmod (kernel mods) from source using the source files in the VMWare repository.