Friday, January 23, 2015

URLs vs URIs

Whenever I needed to work with a URL in my code I wasn't sure how to name the variable: `url` or `uri`? What term to use in documentation: URL or URI?

Some projects use term `URI` ( `Connection URI` in Flask,  `redirect_uri` in Facebook API). Other projects use term `URL` (like SqlAlchemy or `redis.from_url`).

I've been thinking about this occasionally in the last several years. Today, after reading again the Wikipedia article about URI I reached a conlusion.

A URN is a URI that identifies a resource by name in a particular namespace. A URN can be used to talk about a resource without implying its location or how to access it.
The International Standard Book Number (ISBN) system for uniquely identifying books provides a typical example of the use of URNs. ISBN 0-486-27557-4 cites unambiguously a specific edition of Shakespeare's play Romeo and Juliet. The URN for that edition would be urn:isbn:0-486-27557-4. To gain access to this object and read the book, its location is needed, for which a URL would have to be specified.

A URL is a URI that, in addition to identifying a web resource, specifies the means of acting upon or obtaining the representation, specifying both its primary access mechanism and network location. For example, the URL http://example.org/wiki/Main_Page refers to a resource identified as /wiki/Main_Page whose representation, in the form of HTML and related code, is obtainable via HyperText Transfer Protocol (http) from a network host whose domain name is example.org.

In other words: the URN defines an item's identity, while the URL provides a method for finding it.

Or in my words, URN is like an identifier of a resource, and URL is identifier of one of its locations (but not resources global identity).

So, every URL is a URI, but not every URI is a URL.

So, if we talk about a database whose location we want to put into settings, we should use term URL, because it's a location (`postgresql://scott:tiger@localhost/mydatabase`)! Using an URN (something like `urn:database:6e8bc430-9c3a-11d9-9669-0800200c9a66`) would not work in these cases. So if we can't use URNs, we should not use term URI which includes URN.

Thursday, January 1, 2015

Websockets chat in Python

I've made a simple Websockets server in Python using Flask + gevent-websocket.

The idea was taken from https://devcenter.heroku.com/articles/python-websockets

It uses Redis Pub/Sub subsystem to ensure that all connected clients receive the messages, even if there are several Gunicorn workers.

See the code here: https://github.com/warvariuc/flask-websockets

Feel free to comment and improve.

Saturday, December 20, 2014

Do people lose interest in programming as they age?

Some younger programmers expect that older programmers are slower, make more mistakes, and would rather be doing something else such as managing programmers. Are they right to think so?

Rod Johnson 
Written 14 Dec.

In my experience, ability and attitude is what differentiates programmers, not age. The IT industry suffers from rampant agism, which deserves to be called out. Somehow agism is considered more acceptable than sexism, when it's equally wrong.

Regarding whether people appear to lose interest in programming, I think it often depends on whether they had real interest in the first place. A lot of people become programmers with little passion, and many of them realize that they also lack real aptitude. Such people will jump at a chance to move into management: Where they will often also fail, but may have a better chance of getting away with it.

However, it is true that many passionate, competent programmers (like myself) move into business or management jobs as their career progresses. I can think of several reasons for this, most of them nothing to do with advancing age:

  • Necessity. Often someone emerges as a natural leader in a specific project, and it's the best thing for all concerned for that person to take on more and more management responsibility.
  • Opportunity. For example, when a programmer becomes an entrepreneur.
  • Concern about encountering age discrimination. While great programmers will always be employed, regardless of their age or the state of the economy, average and even good programmers can start to be frozen out as they get older, and they change track to avoid the problem.
  • Unwelcoming environment for older programmers. I have mid 40s friends who are starting to find working as Google engineers uncomfortable, despite being good at their jobs.
  • Desire for career variety. I personally could not imagine doing the same thing--even something awesome like programming--for my entire career, any more than I could imagine living my entire life in the same country or spending my entire career at the one company.
  • Desire to do a more people-centric job, at least part of the time. I loved (and still love) writing code, but also get a huge buzz out of working closely with people and talking about human, rather than technical, issues.
  • Discovery of new areas of passion. In my case, I discovered, initially to my great surprise, that I found many business problems intensely interesting, and enjoyed management.

Having said that, I don't think a passionate programmer ever loses the buzz programming can provide. It's addictive. It may just become a hobby rather than a day job.

Source

Saturday, November 15, 2014

Prepopulate a `user` field in a Django admin form

It took me a while to find the solution, which I am posting here:
class ArticleAdmin(admin.ModelAdmin):

    form = ArticleAdminForm

    def get_changeform_initial_data(self, request):
        initial = super().get_changeform_initial_data(request)
        initial['submitted_by'] = request.user
        return initial


Tuesday, November 11, 2014

Implementing a ReDiS COUNT command in Lua

Inside of a Blog: Implementing a ReDiS COUNT command in Lua: I have recently been implementing a master/slave redis cache for our enterprise application and at certain points during the development/test phases, have found it useful to be able to query redis for the # of keys that have been inserted that match a certain regex...

In short:

eval "return #redis.pcall('keys', '*')" 0

Thursday, October 23, 2014

Stop Baloo in KDE

This will make an entry Indexing-Enabled=false in $HOME/.kde/share/config/baloofilerc :
$ kwriteconfig --file baloofilerc --group 'Basic Settings' --key 'Indexing-Enabled' false

Upgrading Kubuntu/Ubuntu from 14.04 to 14.10

Ensure that you have the upgrade tool installed:
$ sudo apt install update-manager-core
Reading package lists... Done
Building dependency tree       
Reading state information... Done
update-manager-core is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Run the upgrade tool. In my case it didn't work:
$ sudo do-release-upgrade
Checking for a new Ubuntu release
No new release found
Edit configuration to allow upgrades to non-LTS versions (change "lts" -> "normal"):
$ sudo nano /etc/update-manager/release-upgrades
Try again:
$ sudo do-release-upgrade
Checking for a new Ubuntu release
Get:1 Upgrade tool signature [198 B]
Get:2 Upgrade tool [1 147 kB]
Fetched 1 148 kB in 0s (0 B/s)
authenticate 'utopic.tar.gz' against 'utopic.tar.gz.gpg'
extracting 'utopic.tar.gz'
...
Don't forget to re-enable repositories which could have been disabled after the upgrade.