Skip to content

Instantly share code, notes, and snippets.

View herrersystem's full-sized avatar

HSystem herrersystem

View GitHub Profile
@herrersystem
herrersystem / examples.py
Last active October 20, 2016 09:20
[Django] Utiliser l'héritage dans nos modèles
from my_app.models import *
my_books = Book.objects.all() #Search in Book only.
my_collection = Collection.objects.all() #Search in all collection.
for elem in my_collection:
if elem.categorie == 'book':
print(elem.book.author, elem.book.title)
else:
print(elem.music.artist, elem.music.album)
@herrersystem
herrersystem / debian_torrelay.sh
Last active October 10, 2016 20:17
[Tor relay] Installation script for debian jessie
## For Debian (jessie)
## Maintener: Anton Millescamps <[email protected]>
## Create source.list file.
echo -e "\n# Tor" >> /etc/apt/sources.list
echo "deb https://deb.torproject.org/torproject.org jessie main" >> /etc/apt/sources.list
echo "deb-src https://deb.torproject.org/torproject.org jessie main" >> /etc/apt/sources.list
## Import gpg key.
gpg --keyserver keys.gnupg.net --recv 886DDD89
@herrersystem
herrersystem / freebox_host.py
Last active October 4, 2016 19:37
Freebox OS API - See connected hosts
#!/usr/bin/env python
from apize.decorators import apize_raw
api_url = 'http://mafreebox.freebox.fr/api/v3'
@apize_raw(api_url + '/lan/browser/pub/')
def get_lan_host(session_token):
"""
@herrersystem
herrersystem / freebox_test_phone.py
Last active October 4, 2016 19:39
Freebox OS API - Test phone call
#!/usr/bin/env python
import time
from apize.apize import Apize
app = Apize('http://mafreebox.freebox.fr/api/v3')
@app.call('/phone/fxs_ring_start/', method='POST')
def call_start(session_token):
@herrersystem
herrersystem / freebox_connection.py
Last active October 4, 2016 19:40
Freebox OS API - Login and logout to API
#!/usr/bin/env python
import hmac
from apize.apize import Apize
app = Apize('http://mafreebox.freebox.fr/api/v3')
@app.call('/login/session/', method='POST')
def connect_app(app_token, app_id, challenge):
@herrersystem
herrersystem / freebox_register_app.py
Last active October 4, 2016 19:41
Freebox OS API - Register app and get authorization
#!/usr/bin/env python
from apize.decorators import apize_raw
api_url = 'http://mafreebox.freebox.fr/api/v3'
@apize_raw(api_url + '/login/authorize/', method='POST')
def get_authorization():
data = {
@herrersystem
herrersystem / decorators.py
Last active August 7, 2018 07:13
[Django] Custom HTTP Header with decorator
'''
A noter qu'il s'agit d'un exemple. Par exemple si vous ne souhaitez modifier que
l'en-tête X-FRAME-OPTIONS, django à prévu le coup:
https://github.com/django/django/blob/master/django/views/decorators/clickjacking.py
'''
def complete_headers(view_func):
def wrapped_view(*args, **kwargs):
#Objet HTTPResponse retourné par render.
response = view_func(*args, **kwargs)
@herrersystem
herrersystem / models.py
Last active March 11, 2017 22:35
[Django] Create your custom user model
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import BaseUserManager
from django.contrib.auth.models import PermissionsMixin
'''
In this example, create usermodel who use email and password for login.
Don't forget to add in settings.py:
AUTH_USER_MODEL='your_app.UserModel'