Skip to content

Instantly share code, notes, and snippets.

@diosmosis
diosmosis / example.cpp
Created February 19, 2012 11:05
cryo examples
using namespace cryo;
// define some entities
struct author
{
autogenerate<int>::type id;
std::string name;
};
CRYO_DECLARE_ENTITY(author, id, (name));
@diosmosis
diosmosis / example.coffee
Created February 19, 2012 10:51
jsquickhtml examples
# load jsquickhtml as a module if on node.js,
# or assume its been loaded if in the browser
if require?
jsq = require 'jsquickhtml'
else
jsq = window.jsq
# define some elements
div = jsq.lazy_element 'div'
@diosmosis
diosmosis / example_controller.coffee
Created February 19, 2012 10:39
Example snippets that use thewire
thewire = require 'thewire'
Layout = (data, more_data, body) ->
# ...
View1 = (pages) ->
# ...
View2 = (page) ->
# ...
@diosmosis
diosmosis / cakejam_air_example.cakejam.coffee
Created February 19, 2012 09:24
cakejam example (Adobe AIR target)
cakejam = require 'cakejam'
# aliases
jslib = cakejam.targets.jslib
aircert = cakejam.targets.aircert
airapp = cakejam.targets.airapp
# a JavaScript library that will hold all the code in one file
lightspeedjs = jslib 'lightspeedjs', __dirname,
sources: ['src/config.coffee',
@diosmosis
diosmosis / everything.scala
Created January 1, 2012 04:02
Scala Experiment Iteration 2
import scala.actors.Actor
import scala.actors.Actor._
import scala.collection.immutable.HashMap
import scala.collection.mutable.{HashMap => MutableHashMap}
import scala.util.Random
import scala.math.Ordering._
import scala.util.Sorting
/**
* The type passed to RouterActionInvokers.
@diosmosis
diosmosis / router.scala
Created December 29, 2011 02:42
Scala Experiment Iteration 1
import scala.actors.Actor
import scala.actors.Actor._
import scala.collection.immutable.HashMap
import scala.collection.mutable.{HashMap => MutableHashMap}
/**
* The type passed to RouterActionInvokers.
*
* The 'message' member can be anything.
*/
@diosmosis
diosmosis / router.scala
Created December 13, 2011 23:32
Scala Experiment Iteration 0
import scala.collection.mutable.HashMap
/** Represents a segment in a router's tree of valid paths. Describes exactly what
* path segments are allowed to come after this one.
*/
class RouteTreeNode(pathSegment:String) {
/** The segment this node represents. */
private val segment = pathSegment
@diosmosis
diosmosis / example.c
Created August 21, 2011 09:40
JNI Facade
#include <jni.h>
#include <mapper.h>
/* Maps the following fictitious Java classes.
class MyEntity {
MyEntity(int id, String name);
int getId();
void setId(int id);
@diosmosis
diosmosis / example.py
Created August 15, 2011 22:41
Python decorator that catches exceptions and logs a traceback that includes every local variable of each frame.
import os
from log_exceptions import log_exceptions
def throw_something(a1, a2):
raise Exception('Whoops!')
@log_exceptions(log_if = os.getenv('MYAPP_DEBUG') is not None)
def my_function(arg1, arg2):
throw_something(arg1 + 24, arg2 - 24)
@diosmosis
diosmosis / async.py
Created August 8, 2011 18:46
Asynchronous function calling with python and GTK.
import threading
from gi.repository import GObject
# calls f on another thread
def async_call(f, on_done):
"""
Starts a new thread that calls f and schedules on_done to be run (on the main
thread) when GTK is not busy.
Args: