Python performance tips
I came across this python performance tips article this afternoon and found it very interesting. Will definitely start using those tips in my next project.
I came across this python performance tips article this afternoon and found it very interesting. Will definitely start using those tips in my next project.
Just a quick python snippet I written today to reduce the image size during upload class PhotoField(forms.FileField, object): def __init__(self, *args, **kwargs): super(PhotoField, self).__init__(*args, **kwargs) self.help_text = “Images over 500kb will be resized to keep under 500kb limit, which may result in some loss of quality” def validate(self,image): if not str(image).split(‘.’)[-1].lower() in [“jpg”,”jpeg”,”png”,”gif”]: raise ValidationError(“File… Read More »
I was told to create some kind of logging mechanism to insert logs into database, and make sure it’s generic. So after some thought I decided to mimic the builtin RotatingFileHandler and write a DBHandler. The RotatingFileHandler allows you to specify which file to write to and rotate files, therefore my DBHandler should also allow… Read More »
“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” — Donald Knuth
I have been using git for a few months now, surely it’s great, and of course confusing, sometimes. For example, I was very confused with the rebase function, not that I didn’t understand what the purpose of it, but the workflow wasn’t so clear to me. So I asked on stackoverflow and got a pretty… Read More »
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…
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(); } }); } })($);
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 »
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)