Skip to content

Instantly share code, notes, and snippets.

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

Arnaud Bos arnaudbos

😶‍🌫️
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / gist:1985534
Created March 6, 2012 10:15
Add Multiple UIBarButtonItems to UINavigationBar
UIToolbar *tools = [[UIToolbar alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)]; // 44.01 shifts it up 1px for some reason
tools.clearsContextBeforeDrawing = NO;
tools.clipsToBounds = NO;
tools.tintColor = [UIColor colorWithWhite:0.305f alpha:0.0f]; // closest I could get by eye to black, translucent style.
// anyone know how to get it perfect?
tools.barStyle = -1; // clear background
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];
// Create a standard refresh button.
@arnaudbos
arnaudbos / gist:1626567
Created January 17, 2012 13:05
Set gradient color in Objective-C
theView.backgroundColor = [UIColor clearColor];
CAGradientLayer *layer = (CAGradientLayer *)theView.layer;
CGColorRef liteColor = [UIColor colorWithWhite:0.92f alpha:0.8f].CGColor;
CGColorRef darkColor = [UIColor colorWithWhite:0.32f alpha:0.8f].CGColor;
layer.colors = [NSArray arrayWithObjects:(id)liteColor, (id)darkColor, nil];