• Sublime Text and Language Server Protocol

    Sublime Text and Language Server Protocol (LSP)

    Language Server Protocol (LSP)

    LSP - protocol for interactions between IDE and language server. The latter provides such means like autocompletion, goto implementation and etc. When IDE needs to show autocomplete choices on, for example, python language - it sends a request to the special server. And it responds with the necessary data. The cool part here is that it is an initiative of a big company - Microsoft.

    Comments Read More
  • Trap in counting related objects in Django

    Trap in counting related objects in Django

    Task: for every object count number of related objects satisfying some conditions.

    Comments Read More
  • Django: signal or model method?

    Django: signal or model method?

    When I needed to implement some functionality on model saving, I always asked a question to myself - where to place it. In signal or in model method save()? Let’s see, what and when is more applicable.

    Comments Read More
  • Trying JSON in Django and PostgreSQL (and compare with MongoDB)

    Trying JSON in Django and PostgreSQL

    New JSONField will be added in Django 1.9, it can be used with PostgreSQL >= 9.4. Let’s try to work with it and find out, in what situations it can be useful.

    Comments Read More
  • OAuth and django rest framework


    OAuth and django rest framework

    This is a well known topic, but i can’t find the existing solution that will fully satisfy me. So i write it by myself :).

    Assume we have a “single page” web site, that is talking with backend via REST API. Client side can be written with ember, angularjs or some like this. Backend - django rest framework (DRF). We’ve got a task - add social login (OAuth protocol).

    Comments Read More
  • Tornado and pgettext

    Tornado and pgettext

    Recently (26.05.2015) new tornado 4.2 was released. It contains different updates, the most valuable i suppose are modules tornado.locks and tornado.queues. They migrated from package Toro, look detailed explanation in Jesse Jiryu Davis post.

    Here i want to tell about another helpful function, that was added with my help - pgettext.

    Comments Read More
  • OAuth step by step

    OAuth step by step

    OAuth protocol has two versions: 1.0 and 2.0.

    Most of services today use version 2.0, i suppose because it is easier to implement. Also, 2.0 can be realized in standalone applications (those, that don’t have a server).

    To understand the protocols very useful to have a look at their realisation. Here i’ll show several scripts that talk to OAuth providers of different versions. Scripts will implement client application functionality. Only standard python libraries are used. This help to overview the OAuth protocol - everything is on single screen and familiar. Of course, for production application we must use third party oauth libs, they handle many special cases and so on. Purpose of these scripts is just understanding of the protocol and nothing else. It is often hard to keep the protocol flow in production-ready library, because it is splitted in many modules, some other packages are used. And the full vision is slipping out of sight.

    Comments Read More
  • Python tips & tricks

    Python tips & tricks

    Recently i’ve read the book Learning Python, 5th Edition by Mark Lutz. Here is a list of most interesting insights for me.

    Comments Read More
  • Listen wifi with wireshark

    Listen wifi with wireshark

    I always knew, that it is possible to catch wifi network packets. But haven’t done it in practise (i was analysing network packets, but not in HTTP protocol). So i decided to do it, as this is interesting and useful. Such experience help to understand TCP-IP and HTTP protocols and also to pay more attention for web security.

    Comments Read More
  • Debug SQL in django test

    Debug SQL in django test

    In django tests we can measure number of sql queries:

    def test_home(self):
        with self.assertNumQueries(1):
            response = self.client.get('/')
        self.assertEqual(response.status_code, 200)

    If code in context of assertNumQueries will make other number of DB attempts than expected (here 1), test will throw error. But when test fails it is sometimes hard to understand, what unexpected query was made. To debug such case very useful to log SQL expressions to console. Below is description how to do it.

    Comments Read More
  • Tornado i18n and l10n


    Tornado i18n and l10n

    Let’s talk about i18n, i10n and tornado implementation. This post have a lot of text, but i wanted to describe many things that i faced during realization of i18n in tornado project. The step by step instruction is placed in the second part of this article.

    Comments Read More
  • Timestamp and ObjectId in mongoDB

    Timestamp and ObjectId in mongoDB

    Every record in mongoDB has field _id, that must be unique inside collection. By default type of this field is ObjectId, and it is assigned automatically if field is not set.

    Lets look at ObjectId more carefully.

    Comments Read More
  • Set url for Tornado handlers

    Set url for Tornado handlers

    To set url for tornado handlers we can pass list of tuples (url regex, handler) into application initialisation:

    application = tornado.web.Application([
        (r"/", MainHandler),
        (r"/some/path/page/(?P<pk>[0-9]+)$", PageHandler),

    But it is more convenient to use wrapper tornado.web.url, that allows to assign meaningful names for paths (similar to django url).

    Comments Read More
  • Django celery setup

    Django celery setup

    To enable celery in new django project i often look in previous ones to refresh in my memory some steps: what settings should be specified, how to launch, how to stop and so on.

    Here i want to combine all together in one place.

    Comments Read More
  • Nested SQL queries in Django

    Nested SQL queries in Django

    Did you know, that Django ORM can do nested SQL queries? Shame on me, but i’ve found it not so long ago.

    Comments Read More
  • Free t-shirt from New Relic

    Free t-shirt from New Relic

    New Relic - service for site monitoring. It shows statistic of your application, where it spend most of time, how often it access the database and many other information. For description of this cool service i need to write a separate post. Here i want to tell about another thing - how i’ve got a free t-shirt from New Relic.

    Actually, it is needed just to register and setup New Relic on a working web site. As it said in their offer.

    Comments Read More
  • Remote url for localhost server

    Remote url for localhost server

    There is a nice tool called ngrok. It allows to bind the URL for your localhost server!

    Comments Read More
  • Send email in django project with mandrill service

    Send email in django project with mandrill service

    To send email messages from server we can just use SMTP protocol. But there is another way - special email services. I’ll describe one of them here, mandrill.com.

    Comments Read More
  • What you should know about mongodb indexes

    What it is needed to know about mongodb indexes

    Recently i’ve completed course “M101P: MongoDB for Developers” (periodically repeats, next starts at April). During this course i’ve found to myself interesting features of mongodb.

    Comments Read More
  • Async Bitcoin RPC client


    To work with Bitcoin RPC from python there is a library Python-BitcoinRPC.

    But recently i need to call API from tornado application. Mentioned lib works in synchronous, i.e. blocking mode. For tornado it will be much better to use asynchronous version. Tried to search for existing solution, but can’t find it. So i create my async fork, that use tornado’s AsyncHTTPClient: https://github.com/st4lk/python-bitcoinrpc-tornado.

    Comments Read More

Atom feed