Skip to content

Instantly share code, notes, and snippets.

View gaspard's full-sized avatar

Gaspard Bucher gaspard

View GitHub Profile
@gaspard
gaspard / Zena VirtualClass export example
Created April 15, 2011 08:37
In order to easily share Zena applications, this is a full export of VirtualClasses and Roles with properties, indexing information and relations.
---
Node:
type: Class
Original:
type: Role
columns:
origin:
ptype: string
index: string
tz:
@gaspard
gaspard / roles.yml
Created April 15, 2011 08:39
In order to easily share Zena applications, this is a full export of VirtualClasses and Roles with properties, indexing information and relations.
---
Node:
type: Class
Original:
type: Role
columns:
origin:
ptype: string
index: string
tz:
@gaspard
gaspard / gist:994975
Created May 27, 2011 09:58
Some SQL generated by indices in Zena.
SELECT
nodes.*,
links.id AS `link_id`,
links.status AS `l_status`,
links.comment AS `l_comment`,
links.date AS `l_date`
FROM
idx_contracts AS sc1, /* custom index class */
idx_nodes_ml_strings AS ml1, /* key/value index */
links, /* relations contract ==> contact */
@gaspard
gaspard / gist:1048415
Created June 27, 2011 06:53
Compile time hash evaluation
// Usage:
// H("foobar") ===> replaced by uint during compilation
// macro hashing function by http://chrissavoie.com/index.php?option=com_content&task=view&id=14&Itemid=1
#define HASH_CONSTANT 5381
// The following is the guts of the compile-time hasher
@gaspard
gaspard / gist:1054915
Created June 29, 2011 20:47
wrapping C++ classes with Lua
-- ============ Create new class
SpecialEdit = {}
setmetatable(SpecialEdit, mimas.LineEdit_mt)
-- calling SpecialEdit() should do the following things
-- 1. create userdata
-- 2. set new table as uservale ---> self
-- 3. create new lua thread and install "self" on the stack
-- 4. set access to userdata from self ---> self.super = userdata
-- 5. set "SpecialEdit" as metatable for "self" ---> setmetatable(self, SpecialEdit)
@gaspard
gaspard / gist:1087380
Created July 17, 2011 09:02
Simple C++ class with C interface for Luajit ffi bindings
// g++ simple.cpp -shared -o libsimple.dylib
#include <stdio.h>
class Simple {
int id_;
public:
Simple(int id);
~Simple();
@gaspard
gaspard / simple_jit.lua
Created July 17, 2011 09:05
Testing Luajit bindings to C++
-- luajit simple_jit.lua
ffi = require 'ffi'
simple = ffi.load('simple')
ffi.cdef[[
typedef struct Simple Simple;
Simple *Simple_Simple(int);
void Simple__gc(Simple *);
@gaspard
gaspard / gist:1614891
Created January 15, 2012 07:42
dub optimizations
// =========================================================== Return value optimization
/** Vect Vect::operator+(const Vect &v)
* test/fixtures/pointers/Vect.h:55
*/
static int Vect_operator_add(lua_State *L) {
try {
Vect *self = *((Vect**)dub_checksdata(L, 1, "Vect"));
Vect *v = *((Vect**)dub_checksdata(L, 2, "Vect"));
dub_pushudata(L, new Vect(self->operator+(*v)), "Vect");
@gaspard
gaspard / gist:1636042
Created January 18, 2012 21:54
Simple Box2D demo with Lubyk
require 'lubyk'
-- Box2D bindings are not yet in published but code will look the same
-- (18.1.2012)
local function makeBody(x, y, r, hue)
-- Define the dynamic body. We set its position and call the body factory.
local bodyDef = b2.BodyDef()
bodyDef.type = b2.dynamicBody
bodyDef.position:Set(x, y)
@gaspard
gaspard / mod.cpp
Created March 25, 2012 11:15
Simple Qt module producing bug 24945
#include <QtGui/QApplication>
#include <QtCore/QTimer>
#include <qglobal.h>
#include <cstdio>
static int app_argc = 0;
static char *app_argv[] = {};
static void something() {