Nautilebleu

Dive into my universe

0 notes &

Esquisses de Cavaliers des Skrodes

Cavaliers des Skrodes (Un feu sur l’Abîme, Vernor Vinge)

Il y a quelques jours, Nim évoquait Un feu sur l’Abîme un roman de Vernor Vinge alors que l’on venait de découvrir le pithovirus.

Bizarrement, cela faisait quelques temps que le roman – écrit il y a plus de 20 ans – me trottait dans la tête et j’avais envie de dessiner un Cavalier des Skrodes, une des espèces extra-terrestres jouant un rôle prépondérant dans l’intrigue.

À l’invitation de Nim, j’ai donc décidé de me mettre au travail. Comme mes souvenirs sont un peu vieux, j’ai fait une rapide recherche pour voir si le sujet avait déjà été traité… ce qui n’est pas vraiment le cas ! Au moins, le fruit de mes cogitations ne souffrira pas trop de la comparaison et sera une contribution originale, dans tous les sens du terme !

Si Un feu sur l’Abîme n’est pas un roman de Hard SF, je voulais donner un aspect raisonnablement réaliste au skrode. Je voulais éviter le syndrôme Daleks, les ennemis du Docteur Who, qui veulent dominer l’univers mais ne peuvent pas monter une marche !

J’ai donc dôté le skrode de roues montées sur des jambes articulées, un peu à la façon de Curiosity. D’ailleurs, l’organisation globale du skrode ressemble beaucoup au robot envoyé sur Mars. Ce n’est peut être pas très original mais au moins cela me semble fonctionnel.

J’ai également cherché à concevoir un skrode sans symétrie longitudinale, les Cavaliers étant présentés comme ayant plutôt un axe de symétrie radial. Mais à la réflexion, le fait de se déplacer dans une direction conduit assez rapidement à développer une organisation dans le sens de la marche.

Je n’ai pas le souvenir qu’il soit fait référence à des pinces ou à un quelconque mécanisme sur les skrodes, mais ça me semble aussi nécessaire à un moment ou un autre pour les Cavaliers.

Au final tout cela confère un côté très insectoïde au skrode qui contraste avec l’aspect végétal du Cavalier.

Place aux dessins !

Esquisses des Cavaliers des Skrodes

Voir en grand

Filed under skrode skroderider skroderiders vernor vinge a fire upon the deep

0 notes &

Défi dessin février

Je vais tenter de participer au Défi dessin février (sur Twitter). J’ai commencé au 5ème jour. Voici donc mes propositions :

Ouf !

Edit: Mise à jour avec tous les dessins auxquels j’ai participé.

0 notes &

Mulan

I wanted to draw Mulan after seeing the character in Once Upon A Time (oh yeah!), having never seen the Disney movie.

After reading the Wikipedia page Mulan , several story ideas came to my mind. Even if I do not have time to deepen, I wanted to give it a little body.

Mulan on deviantart

In full format on DeviantArt

Why the eye patch and scar? I thought that after 12 years of struggle, Mulan was certainly evident in his flesh. Maybe also because I recently saw the Captain Harlock movie! ^^

About the costume, inspired more by the Huns and Mongols, I guess Mulan to be able to beat the Ruanruan, would probably take many of their habits, such as clothing and warfare techniques.

0 notes &

Mulan

J’ai eu envie de dessiner Mulan après avoir vu le personnage dans la série Once Upon A Time (et ouais !), n’ayant jamais vu le dessin animé de Disney.

Après avoir lu la page Wikipedia de Mulan, plusieurs idées de scénario me sont venues à l’esprit. Même si je n’ai pas le temps de les approfondir, j’avais envie de lui donner un peu corps.

Alt text

En plein format sur DeviantArt

Pourquoi le bandeau sur l’œil et la cicatrice ? Je me suis dit qu’après 12 ans de combat, Mulan aurait été sûrement marquée dans sa chair. Peut être aussi parce que j’ai vu Albator ! ^^

Quand au costume, plus inspiré par celui des Huns et des Mongols, j’imagine que Mulan, pour arriver à battre les Ruanruan, aurait sans doute adopter plusieurs de leurs habitudes, tant vestimentaires que guerrières.

0 notes &

Dernièrement, j’ai repris mon projet de BD. Je n’ai pas encore de titre. Il y a deux jours, j’ai eu cette idée, qui, si elle ne colle pas — pas la bonne époque, sans parler du problème de droit — était assez amusante.

Texture rouille issue de Wikimedia

Dernièrement, j’ai repris mon projet de BD. Je n’ai pas encore de titre. Il y a deux jours, j’ai eu cette idée, qui, si elle ne colle pas — pas la bonne époque, sans parler du problème de droit — était assez amusante.

Texture rouille issue de Wikimedia

2 notes &

BROrm to be alive!

Recently I’ve started to code in Cocoa to create iOS apps. This was an interesting challenge, as I’ve only work with interpreted languages (mostly Python and Javascript, formely with PHP –sigh– and even VBScript –yes, I’m in software development for decades!) until now.

Cocoa is a big beast to handle, but sometimes, tools are missing or really unsufficient. When dealing with database, Apple provides CoreData but what if you have to use a custom schema? At [Greenbureau][http://greenbureau.fr], we build apps for both Android and iOS and we don’t want to manage two different schemas. In this case, we can’t use CoreData and then, I start to look for an ORM.

Why an ORM?

One might wonder why I need an ORM at all? Well, even if I don’t want to use an ORM, I would need extra libraries to query comfortably SQLite. The best tool seems to be FMDB, that can be installed via cocoapods.

Also, one advantage of using an ORM is that they often handle the differences between SQL backends but in iOS, only SQLite is available, so it’s not crucial.

But I’m a developer very obsessed by code organization: I don’t want to have raw SQL queries everywhere in my project. Most of time, some queries recur over and over, but with small differences. SQL is not a very composable langage, or, at least, if I want to do this, I will rewrite a big part of an ORM. As I’m a lazy developer, I prefer reuse (and contribute) to an existing rather than reinvente the wheel.

Why BROrm?

After browsing the cocoapods repository, I only found 2 options: iActiveRecord and BROrm.

The first one seems quite mature and have a quite nice API (which is not a small thing for Objective-C!) but can’t be configured to use custom table names and columns.

BROrm was a much more younger project with a smaller community. The API was less nice at first glance but it is possible to configure table name and columns easily.

As a project in the early stage of its life, BROrm has not as many functionnalities as the django ORM for example. There’s no tools to validate input data and migrations support is rather poor.

In fact, currently, BROrm do only one thing, but it does it well: it provides a DSL to build queries and get objects (or arrays of objects).

Organize your code with BROrm

With BROrm, you can do queries like this (example stolen from the README):

// Get all
BROrmWrapper *w = [BROrmWrapper factoryForClassName:@"Person"];
NSArray *persons = [w findMany];

// Get one
BROrmWrapper *w = [BROrmWrapper factoryForClassName:@"Person"];
Person *person = (Person*)[w findOne:@2];

That nice and not too verbose for Objective C. But, as I say previously, I don’t to have queries everywhere in my project. Importing BROrmWrapper.h in all source files is not a particulary better solution.

I would prefer doing something like this:

// In a ControllerView
NSArray *people = [Person findAll];
Person *person = [Person findOneById:@2];

Taking advantage of Objective C categories, I’ve create the following class:

//BRModel+Extension.h

//  BRModel+BRModel_Extension.h
//  iVMH
//
//  Created by Goulwen on 10/10/13.
//  Copyright (c) 2013 Goulwen. All rights reserved.
//

#import "BRModel.h"

@interface BRModel (Extension)

+ (NSString *)nameColumn;
+ (BROrmWrapper *)wrapper;
+ (id)findOneById:(NSNumber *)idValue;
+ (id)findOneByName:(NSString *)nameValue;
+ (NSArray *)findAll;

@end


// BRModel+Extension.m

#import "BRModel+Extension.h"

@implementation BRModel (Extension)

- (NSString *)description
{
    return [NSString stringWithFormat:@"<%@: %@ [%@]>",
            NSStringFromClass([self class]),
            self[[[self class] nameColumn]],
            self[[[self class] idColumn]]];
}

+ (NSString *)nameColumn {
    return @"name";
}

+ (BROrmWrapper *)wrapper
{
    BROrmWrapper *w = [BROrmWrapper
                       factoryForClassName:NSStringFromClass(self)];
    return w;
}

+ (id)findOneById:(NSNumber *)idValue
{
    BROrmWrapper *w = [[self class] wrapper];
    [w whereEquals:[self idColumn] value:idValue];
    return (BRModel *) [w findOne];
}

+ (id)findOneByName:(NSString *)nameValue
{
    BROrmWrapper *w = [[self class] wrapper];
    [w whereEquals:[self nameColumn] value:nameValue];
    return (BRModel *) [w findOne];
}

+ (NSArray *)findAll:
{
    BROrmWrapper *w = [[self class] wrapper];
    return (BRModel *) [w findMany];
}

@end

So I end up with class methods to perform queries and instance methods to get or set data on a particular object. This distinction, in combination of pragma marks, makes the code easy to read and to understand.

Note that I’ve also add the description and findOneByName methods. The latter is mostly for debugging and unit testing purposes. I’ve configured the description so it returns me the class name, the name and the id by default. As iOS apps doesn’t display a URL, the need of being able to query an object with another property than the primary key is less required but it’s interesting when unit testing, where we need to be able to get always the same object but can’t rely on primary keys.

If I need other queries, I proceed the same way but in the object files. For example, if I want a query that returns the latest 5 objects, I do the following:

// Person.h
+ (NSArray *)findLatest;

// Person.m
+ (NSArray *)findLatest:
{
    BROrmWrapper *w = [[self class] wrapper];
    [w orderBy:@"updated_at" withOrdering:@"ASC"];
    [w setLimit:5];
    return (BRModel *) [w findMany];
}

BROrm has quite powerful capabilities to do complex queries, especially by being able to use partial or full raw SQL if needed (I try to avoid it but sometimes that’s not possible.)

Validation

I’ve write before that BROrm is not capable to perform validation on data. In fact, as SQLite seems to have a really poor columns types support (you can put anything in a column regardless of its type), one might argue that it’s not really necessary. But as a webdeveloper, I tend to code in a fairly paranoid way, and I can’t imagine saving data without checking them.

It would be nice if it was possible to define the properties like in the django ORM, specifying if the columns accept nulls, settings a default, etc. It would be nicer to have BREmailField for example that checks automatically that the data is really an email. I’m not sure if it’s possible in Objective-C. If I find a way to do this, I will probably contribute to BROrm.

For now, it simply does the check in the save method of the class:

- (BOOL)save {
// Performs some validations on values before pushing to DB.
// SQLite has a really weak datatype enforcement.

NSArray *number_columns = @[@"age", @"customer_id"];
for (NSString *column in number_columns) {
    if (![self[column] isKindOfClass:[NSNumber class]]) {
        NSLog(@"Bad data type for %@", column);
        return NO;
    };
}

NSArray *string_columns = @[@"name", @"email"];
for (NSString *column in string_columns) {
    if (![self[column] isKindOfClass:[NSString class]]) {
        NSLog(@"Bad data type for %@", column);
        return NO;
    };
}

BRModel *customer = [Customer findOneById:(NSNumber *)self[@"customer_id"]];
if (!customer) {
    NSLog(@"Bad foreign key Customer: %@", customer);
    return NO;
}
return [super save];

}

I check if the data are in the correct type using isKindOfClass. I also validate that foreign keys are correctly set when they are required. But it is a pain to have to do this in all classes so a better solution would be great!

That’s all for now. All those little tricks have helped me to organize my project. I would be interested to know how people do this, so don’t hesitate to share your thoughts!

PS: The title is obviously a wink to this song. I’m not particulary fan of disco but the joke was fun! ;)

Filed under objective c iphone Cocoa brorm orm

0 notes &

Using a recent version of OpenSSL with Python on MacOS X

Mac OS X, even Mountain Lion, comes with a quite old version of OpenSSL and both pyelliptic and django-ios-notifications requires a more recent one.

Especially if you try to send iOS push notification and the process hangs when executing the _connect method of django-ios-notifications, this post can save your day! Symptoms are an Error exception raised in the method when adding the private key to the openssl context or simply nothing (!).

Thanksfully Homebrew provide a decent version of OpenSSL. But as it is released as a keg-only, we have to do some hacking so both are happy.

First backup the Apple binary and libraries:

$ sudo mv /usr/bin/openssl /usr/bin/openssl.osx
$ sudo mv /usr/include/openssl /usr/include/openssl.osx
$ sudo mv /usr/lib/libcrypto.dylib /usr/bin/libcrypto.dylib.osx
$ sudo mv /usr/lib/libssl.dylib /usr/bin/libssl.dylib.osx

Then create symlinks from Homebrew Cellar to actual folders in the PATH:

$ sudo ln -s /usr/local/Cellar/openssl/1.0.1e/bin/openssl /usr/bin
$ sudo ln -s /usr/local/Cellar/openssl/1.0.1e/include/openssl /usr/include
$ sudo ln -s /usr/local/Cellar/openssl/1.0.1e/lib/libcrypto.dylib  /usr/lib/libcrypto.dylib
$ sudo ln -s /usr/local/Cellar/openssl/1.0.1e/lib/libssl.dylib  /usr/lib/libssl.dylib

You can now compile PyOpenSSL with the good underlying OpenSSL release!