Skip to content

Instantly share code, notes, and snippets.

View arnaudbos's full-sized avatar
😶‍🌫️

Arnaud Bos arnaudbos

😶‍🌫️
View GitHub Profile
@arnaudbos
arnaudbos / pygraphviz
Created April 24, 2013 09:00
Django models visualisation graphs.
sudo apt-get install graphviz
pip install django-extensions
pip install pygraphviz
# add 'django_extensions' to INSTALLED_APPS
# all models from INSTALLED_APPS (django too)
./manage.py graph_models -a -g -o my_project.png
# just two apps: emailing and localization
@arnaudbos
arnaudbos / management.py
Last active December 17, 2015 01:59
Create permissions or anything else after syncdb of an app has finished.
This should be located in: yourapp/management.py
from django.db.models.signals import post_syncdb
from django.contrib.auth import models as auth_models
from django.contrib.auth.models import User, Permission
from django.contrib.contenttypes.models import ContentType
def create_supervision_permissions(sender, **kwargs):
print '== create_supervision_permissions =='
# create a content type for the app if it doesn't already exist
@arnaudbos
arnaudbos / Activity.java
Last active December 20, 2015 01:19
Android view easter egg
private static final int EASTER_EGG_COUNT = 7;
private static final long EASTER_EGG_DURATION = 1000;
/** Easter egg click counter */
private int mEasterEggClickCount = 0;
/** Easter egg first click timestamp */
private long mEasterEggStart = -1;
@arnaudbos
arnaudbos / django_command_wrapper.py
Created July 30, 2013 13:38
Django command wrapper
from optparse import OptionParser
from myapp.management.commands import my_command
def make_test_wrapper_for(command_module):
def _run_cmd_with(*args):
"""Run the possibly_add_alert command with the supplied arguments"""
cmd = command_module.Command()
(opts, args) = OptionParser(option_list=cmd.option_list).parse_args(list(args))
cmd.handle(*args, **vars(opts))
@arnaudbos
arnaudbos / aes_file.py
Created August 30, 2013 14:27
AES Encrypt/Decrypt file
# encrypt.py
import os, random, struct
from Crypto.Cipher import AES
def encrypt_file(key, in_filename, out_filename=None, chunksize=64*1024):
""" Encrypts a file using AES (CBC mode) with the
given key.
key:
The encryption key - a string that must be
@arnaudbos
arnaudbos / aes_string.py
Last active December 22, 2015 00:38
AES Encrypt/Decrypt string
from Crypto.Cipher import AES
import base64
import hashlib
import os
# the block size for the cipher object; must be 16, 24, or 32 for AES
BLOCK_SIZE = 32
# the character used for padding--with a block cipher such as AES, the value
# you encrypt must be a multiple of BLOCK_SIZE in length. This character is
@arnaudbos
arnaudbos / gist:8581112
Created January 23, 2014 16:00
Pallet/jclouds node options
pallet: defnode macro
list:
os-family
location-id
architecture
image-id
hardware-id
os-name-matches
os-version-matches
@arnaudbos
arnaudbos / gist:8600721
Created January 24, 2014 16:27
Clojure: Read edn
user=> (require 'clojure.edn)
nil
user=> (slurp "stored-array.dat")
"[1 2 3 4]\n"
user=> (clojure.edn/read-string (slurp "stored-array.dat"))
[1 2 3 4]
@arnaudbos
arnaudbos / clojure.core.clj
Last active August 29, 2015 13:56
clojure partition-with
(defn partition-with
[f coll]
{:pre [(fn? f) (coll? coll)]}
(let [coll (partition-by f coll)
coll (partition 2 coll)
coll (map #(concat (first %) (second %)) coll)
]
coll))
(defn partition-on
@arnaudbos
arnaudbos / supervisord.sh
Created March 13, 2014 09:37
supervisord init
#! /bin/sh
#
# skeleton example file to build /etc/init.d/ scripts.
# This file should be used to construct scripts for /etc/init.d.
#
# Written by Miquel van Smoorenburg <[email protected]>.
# Modified for Debian
# by Ian Murdock <[email protected]>.
# Further changes by Javier Fernandez-Sanguino <[email protected]>
#