Category Archives: Programming

Programming

How to apply patches from Git commits

The following link shows you how to generate a patch file from git commits, http://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/ In the second part of this artcle, I will show you how to use the generated patch to apply to the working directory. to be continued…

How to extend JQuery UI plugin

The existing dialog plugin doesn’t have an option to close dialog on clicking modal overlay, how to add an option to provide the functionality? (function($){ var _init = $.ui.dialog.prototype._init; $.ui.dialog.prototype._init = function(){ var self = this; _init.apply(this,arguments); $(‘.ui-widget-overlay’).live(‘click’, function(){ if (self.options[‘overlay_close’]){ self.destroy(); } }); } })($);

Google Map v3 OverlayView Code Sample

Today I was writing some google map javascripts and had to implement the icons via OverlayView class, so I think I might share it in case anyone need some sample code. //”gmap” is an instance of the google map //creating the class to exntend the google map OverlayView class function MapLocationIcon(id,lat,lng,title,icon_class){ this.lat = lat; this.lng… Read More »

Python code snippet for DPS webservice

import suds url = “https://sec.paymentexpress.com/WS/PXWS.asmx?WSDL” client = suds.client.Client(url) #print client username = “USERNAME” password = “PASSWORD” trans = client.factory.create(‘TransactionDetails’) trans.amount = 1 trans.cardHolderName = “Test” trans.cardNumber = ‘4111111111111111’ trans.inputCurrency= ‘NZD’ trans.cvc2 = ‘000’ trans.dateExpiry = ‘0412’ trans.txnType = ‘Purchase’ print client.service.SubmitTransaction(username, password, trans)

Python Webcam Capture Code Snippet

Here is a small piece of code how to query your webcam and save the frame as an image. import sys import Image, ImageDraw, datetime import opencv #this is important for capturing/displaying images from opencv import highgui camera = highgui.cvCreateCameraCapture(0) def get_image(): for i in range(10): im = highgui.cvQueryFrame(camera) # Add the line below if… Read More »

Python decorator – caching your django functions

Prerequisites: – Python Memcahed Library – Memcached server Settings.py CACHES = { ‘default’ : { ‘BACKEND’: ‘django.core.cache.backends.memcached.MemcachedCache’, ‘LOCATION’: [‘127.0.0.1:11211’], ‘KEY_PREFIX’: ‘YOUR_PREFIX’, } } Caching Code from django.core.cache import cache #get the cache key for storage def cache_get_key(*args, **kwargs): import hashlib serialise = [] for arg in args: serialise.append(str(arg)) for key,arg in kwargs.items(): serialise.append(str(key)) serialise.append(str(arg)) key… Read More »

My Vim Key Maps

Finally I have decided to move over to vim, if you would like to do the same, please spend 10 minutes of your life to read about this blog and this blog After reading those 2 blogs, by now you should have a basic understanding of Vim and have NERDTree installed. This is my key… Read More »