Alkaline Battery Comparison
Been studying electricity lately and stumbled on to this article http://www.powerstream.com/AA-tests.htm Looks like Energizer is a clear winner.
Been studying electricity lately and stumbled on to this article http://www.powerstream.com/AA-tests.htm Looks like Energizer is a clear winner.
Here is a quick recipe for Django templates, let’s say you are building a Django web which has many list views, and which has pagination, it’s wise to abstract the pagination template out to be reusable by all list view templates. My preference is to keep all reusable templates in a partials folder, and place the… Read More »
I have just created this python library so that you can query the remote api just like the Django queryset. It is particularly usefully when used in Django ListView with pagination. https://github.com/variable/django-rest-framework-queryset
Seems like there are not many code sample there, and the requests documentation was giving the wrong hint to use files={‘file’: open(‘image.jpg’)} which you will end up getting 415 response code. I think I will just share my working sample code here to save someone’s time import requests # local file with open(‘image.jpg’, ‘rb’) as… Read More »
If you are a good python dev, surely you follow PEP8 coding style guidelines, and surely you have installed the flake8 plugin to constantly reminding yourself to format your code properly, and surely you have valid cases that you import stuff but not used, eg. __init__.py and surely your IDE will annoy the fuck out of… Read More »
I was writing a service which import various feeds and then post to another RESTful API, simple enough as below: from django.db import connections class Receiver(PolymorphicModel): … class Database(Receiver): name = models.CharField(max_length=255) def get_data_source(self): return connections[name] Then the feed model: class Feed(models.Model): receiver = models.ForeignKey(‘Receiver’) def get_data_source(self): return self.receiver.get_real_instance().get_data_source() Then run this feed in trivial… Read More »
I have been studying Java EE and I posted a question on Stackoverflow to verify my understanding of “SessionBean”, here is the summary: Stateless bean in client: public void work(){ bean.work1(); // this uses instance 1 in App Server … bean.work2(); // this can be instance 2 in App Server } Stateful bean in… Read More »
Let’s say you have a function to process a GET parameter from a HTTP request, the bad example to do this is: def process(request): value = request.GET.get(‘name’) work(value) process(request) The above example has 2 problems: 1. This will become a nightmare to write unit tests on this function, now you need to mock the request… Read More »
At stackoverflow, I demonstrated how to make Resource Server to proxy the token validation to Authentication Server, in order to enable sharing Access Tokens between Resource Servers.
PHP and Python both are dynamic typed language, so there is no point the discuss anything related in this aspect. Exception is first class citizen try: a = 1 / 0 except: print ‘Caught’ Prints ‘Caught’ Let’s look at PHP: try{ $a = 1 / 0; }catch (Exception $e){ print “Caught”; } I cannot believe… Read More »