Services Blog Français

Using rst for documentation on both GitHub and Sphinx/RTFD: code-block tip

| by jpic | python documentation service

Good documentation should be readable from source, and usable to generate fancy HTML. That’s why RST is so commonly used:

  • readable as text source,
  • usable to generate HTML and even PDF
  • GitHub knows how to render it,
  • Sphinx and ReadTheDocs know how to render it.

Good documentation should often show code. This article demonstrates an inconsistency between RTFD and GitHub rendering, and how to fix it.

As far as sphinx is concerned, the default highlight language for code blocks is Python. This will render as Python on Sphinx/RTFD:

Read More

Django development: possible change of the .save() implementation

| by jpic | django-developers django

An interesting topic by Anssi Kääriäinen flew by django-developers mailing list about ticket #16649: “Models.save() refactoring: check updated rows to determine action”.

The ticket mentions a 50% performance optimization. Here’s an explanation by akaariai (core developer):

A bit more information about what the approach suggested is about. Assume you load a model from DB, change some fields and save it. We currently do:

SELECT - load from DB
[change fields]; save()
In save:
    SELECT - assert that the PK exists in the DB
    if yes:
        UPDATE
    else:
        INSERT

The second select above is usually redundant. If we know the object is loaded from DB (self._state.adding == False), and we are saving it to the same DB it was loaded from (self._state.db == the db we are saving to), then it is very likely the object exists in the DB. So, instead we should do:

Read More

Django & DBAs: "Performance problems due to incorrect many-many primary key on many tables"

| by jpic | django django-developers

Extract from a great thread on the django-developper mailing list started by Trey Raymond:

I’m a DB engineer working for Yahoo, and we have a new product using django that I’m onboarding. We see a variety of easily fixed issues, but one major one - there are 21 many-many tables here, yet they have auto increment primary keys

-- Example, existing:
CREATE TABLE `accounts_profile_starred_groups` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `profile_id` int(10) unsigned NOT NULL,
  `group_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `profile_id` (`profile_id`,`group_id`),
  KEY `group_id_refs_id_e2f1545` (`group_id`)
) ENGINE=InnoDB;
-- Fixed:
CREATE TABLE `accounts_profile_starred_groups` (
  `profile_id` int(10) unsigned NOT NULL,
  `group_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`profile_id`,`group_id`),
  KEY `group_id_refs_id_e2f1545` (`group_id`)
) ENGINE=InnoDB;

Looking forward to see how it goes !

Read More

Django & ajax & HATEOAS: how to reverse urls in javascript (not)

| by jpic | http hateoas api

This is the second article about reversing urls in javascript. The previous article actually presented a bad idea.

Github API v3

Github’s API is undubitably quite suprising for a web developer that isn’t aware of the HATEOAS concept, here’s the kind of things you can see for example:

[
  {
    "updated_at": "2012-11-27T14:42:24Z",
    "svn_url": "https://github.com/yourlabs/django-cities-light",
    "language": "Python",
    "milestones_url": "https://api.github.com/repos/yourlabs/django-cities-light/milestones{/number}",
    "downloads_url": "https://api.github.com/repos/yourlabs/django-cities-light/downloads",
    "subscription_url": "https://api.github.com/repos/yourlabs/django-cities-light/subscription",
    "teams_url": "https://api.github.com/repos/yourlabs/django-cities-light/teams",
    "full_name": "yourlabs/django-cities-light",
    "git_url": "git://github.com/yourlabs/django-cities-light.git",
    "git_tags_url": "https://api.github.com/repos/yourlabs/django-cities-light/git/tags{/sha}",
    "owner": {
      "login": "yourlabs",
      "organizations_url": "https://api.github.com/users/yourlabs/orgs",
      "followers_url": "https://api.github.com/users/yourlabs/followers",
      "starred_url": "https://api.github.com/users/yourlabs/starred{/owner}{/repo}",
      "following_url": "https://api.github.com/users/yourlabs/following",
      "avatar_url": "https://secure.gravatar.com/avatar/c0efe8e5c15bd268224fbc40a574329d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-org-420.png",
      "repos_url": "https://api.github.com/users/yourlabs/repos",
      "subscriptions_url": "https://api.github.com/users/yourlabs/subscriptions",
      "url": "https://api.github.com/users/yourlabs",
      "events_url": "https://api.github.com/users/yourlabs/events{/privacy}",
      "gravatar_id": "c0efe8e5c15bd268224fbc40a574329d",
      "received_events_url": "https://api.github.com/users/yourlabs/received_events",
      "id": 1040547,
      "gists_url": "https://api.github.com/users/yourlabs/gists{/gist_id}"
    },

Wow, so many URLs… At first, this may look original, if not excentric. Why aren’t they just documented ?

Read More

How to: fully use gmail with the keyboard

| by jpic | keyboard

Keeping your inbox clean can be quite a pain. Except with keyboard shortcuts.

  • ? shows the list of shortcuts,
  • / to search mails,
  • c to compose a message,
  • gi brings you to the inbox,
  • j and k moves the little blue cursor between threads,
  • x selects the thread that has the blue cursor,
  • e archives selected threads,
  • o opens selected thread
  • a is for reply to all,
  • r is for reply.

That’s it !

Read More
Previous Page 29 of 32 Next Page

They trust us

Contact

logo