Skip to content

Instantly share code, notes, and snippets.

View Natim's full-sized avatar
🏠
Working from home

Rémy HUBSCHER Natim

🏠
Working from home
  • Silvr
  • Rennes
  • 03:45 (UTC +02:00)
  • X @Natim
View GitHub Profile
@Natim
Natim / urls.py
Created September 6, 2013 18:06
Example with decorator in urls.py
from django.conf.urls import patterns, url
from django.contrib.auth.decorators import login_required
from django.utils.translation import ugettext_lazy as _
from youproject.yourapp import views
people_list = login_required(views.PeopleListView.as_view())
people_detail = login_required(views.PeopleDetailView.as_view())
@Natim
Natim / ini2json.py
Created January 11, 2013 10:21
Convert an ini configuration file into a json file
# -*- coding: utf-8 -*-
import json
import sys
from ConfigParser import (ConfigParser, MissingSectionHeaderError,
ParsingError, DEFAULTSECT)
class StrictConfigParser(ConfigParser):
def _read(self, fp, fpname):
@Natim
Natim / django_core_management_find_manamgement_command.patch
Created December 28, 2012 11:24
Django Core Management Command Patch to enable package lookup.
--- a/django/core/management/__init__.py 2012-10-01 13:06:10.000000000 +0200
+++ postbox/lib/omelette/django/core/management/__init__.py 2012-10-01 13:08:35.329819345 +0200
@@ -42,6 +42,7 @@
parts.reverse()
part = parts.pop()
path = None
+ paths = []
# When using manage.py, the project module is added to the path,
# loaded, then removed from the path. This means that
@Natim
Natim / Vagrantfile
Created December 21, 2012 13:57
Vagrantfile
# -*- mode: ruby -*-
# Generated with /home/rhubscher/novapost/postbox/bin/postbox-configure --output-dir=var/vm/postbox --preset=vagrantfile-postbox vagrantfile
# **YOU SHOULD NOT EDIT THIS FILE MANUALLY.**
# You had better edit templates and presets, then run the generator again.
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
def create_data(self, model_name, data, data_id=None):
"""Create a data to a model_name."""
if data_id:
data_doc = self.db[data_id]
else:
data_doc = {
'type': 'data',
'model_name': model_name,
}
data_doc['data'] = data
@Natim
Natim / couchdb-delete-all-db.py
Created October 21, 2012 15:54
Delete all tables
import requests
import couchdb
server = couchdb.client.Server()
tables = requests.get('http://localhost:5984/_all_dbs')
for table in tables.json:
if table.startswith('daybed-test'):
del server[table]
@Natim
Natim / reader.py
Created August 29, 2012 09:00
Read and URL and get the file from cache if possible or update the file.
# -*- coding: utf-8 -*-
import hashlib
import datetime
import settings
import requests
import os
from wsgiref.handlers import format_date_time
INPUT_CACHE_DIR = getattr(settings, 'INPUT_CACHE_DIR', '/tmp')
@Natim
Natim / .emacs
Last active October 9, 2015 05:38
Emacs configuration
;; Ici on parle UTF-8
(set-language-environment "UTF-8")
;; Fichier de Customize
(setq custom-file "~/.emacs-custom.el")
(load custom-file)
;; On supprime ce qui est inutile (Barre d'outils, scroll)
(menu-bar-mode nil)
(tool-bar-mode -1)
@Natim
Natim / language_app.py
Created August 18, 2012 08:40
Flask language_dispatch : Detect the user language and redirect to the right domain_name
# -*- coding: utf-8 -*-
import locale
import re
from flask import Flask, redirect, request
app = Flask(__name__)
LANGUAGE_CODES = ('fr', 'en', 'zh')
DOMAIN_NAME = 'example.com'
@Natim
Natim / email_cleaner.py
Created August 10, 2012 21:49
Extract email from a file, make them unique and sort them.
import re, sys
email_pattern = re.compile('([\w\-\.]+@(\w[\w\-]+\.)+[\w\-]+)')
email_list = []
for line in sys.stdin:
# there are several matches per line
for match in email_pattern.findall(line):
email = match[0].lower()