arg3.com

namespace for c0der78's public void

C Sqlite Tricks

| Comments

Well, I thought I would share some tricks I use for easy data CRUD’s in C/C++/ObjC. I’m using sqlite here, but could apply to any database.

This is how my data access works - I’m not saying its the best approach, its just how I like it.

saving an account
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* The account table name */
#define ACCOUNT_TABLE "account"

/* a structure representing the account fields */
field_map account_values[] = {
  {"login", &acc->login, SQL_TEXT},
  {"email", &acc->email, SQL_TEXT},
  {"password", &acc->password, SQL_TEXT},
  {"timezone", &acc->timezone, SQL_INT},
  {0}
};

/* saves the fields to the database */
acc->id = db_save(account_values, ACCOUNT_TABLE, acc->id);

As you can see, saving a structure is as simple as creating a field_map table and calling db_save.

loading an account
1
2
3
4
5
6
7
8
9
10
/* loads one account by id */
if(db_load_by_id(account_values, ACCOUNT_TABLE, acc->id) != SQL_OK)
  fprintf(stderr, "could not load account");

/* a callback method */
void load_account_callback(sql_stmt *stmt);

/* load all accounts using the callback method */
if(db_load_all("account", load_account_callback) != SQL_OK)
  fprintf(stderr, "could not load accounts");

Loading is the same for single instances, but I use a callback method to load multiple instances.

AppHarbor Cloud for .NET

| Comments

AppHarbor is to .NET what Heroku is to Ruby, which is - awsome.

I’ve deployed a silverlight test app, Scrabby, to the cloud with no problems or cost. If you a lover of C# and midly confused by Azure then its cool enough to blog about.

Switching From Autoconf to Ruby

| Comments

Today I went to go work on an older C project of mine and cringed at the thought of configuring my autoconfigure build system. Needless to say I find it messy and obviously wasn’t working very well if I had to tweak it on a fresh install.

There is a very nice Gem called rake-builder which handles this in a very clean way:

Bitbucket Web Hosting and Project Documentation

| Comments

Today I found myself generating HeaderDoc html for a project and implemented a system to host the docs inside my bitbucket repository. Here’s how I did it:

  • First step is to create a project in bitbucket that is named after your account username in the format username.bitbucket.org.

  • Clone the project and add an index.html to it. I added bootstrap as well. Commit and push back to master.

  • Now assume I have a workspace folder devel with project xyz underneath that I use HeaderDoc with. I simply moved the documentation to username.bitbucket.org and made a symlink back to the project.

  • I use the index.html as a landing portal for all projects with subfolders containing project documentation. You can reference the subdirectories like any other link.

    ◆ devel
        ╷
        ├───▸ username.bitbucket.org
        │         ╷
        │         ├───▸ index.html
        │         │
        │         └───▸ project documentation ──┐
        │                                       │
        └───▸ project                           │
                  ╷                             │
                  ├───▸ html ◂──────────────────┘
                  │
                  └───▸ src

*I have no idea why I put so much effort into that diagram - utf8 art using box drawing characters.

More Useful Web Design Tools

| Comments

Was refactoring my octopress theme and I ran across a few helpful sites that were new to me.

The League of Moveable Type

A group of talented designers providing a collection of open-source font faces for the web. I pulled the *League Gothic” font from there.

Stripe Generator 2.0

A “Web 2.0” background image generator using stripes. Used for the darker background on this site.

Double J Design

A collection of icon packs, many of them free.

Best Programming Quotes

| Comments

Sites with programmer quotes that always humble me with their laser-like honesty. I’ve decided to keep a collection of my favourites here (in no particular order).

  • “They don’t make bugs like Bunny anymore.” - Olav Mjelde.

  • “Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.” - Linus Torvalds

  • “Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter.” - Eric S. Raymond

  • “In the one and only true way. The object-oriented version of ‘Spaghetti code’ is, of course, ‘Lasagna code’. (Too many layers).” - Roberto Waltman.

  • “Talk is cheap. Show me the code.” - Linus Torvalds