Skip to content

Instantly share code, notes, and snippets.

View JobLeonard's full-sized avatar

Job van der Zwan JobLeonard

  • IxD/supporting programmer at Linnarsson Lab
  • Malmö
View GitHub Profile
@JobLeonard
JobLeonard / hello_multicellular.ceu
Last active August 29, 2015 14:10
Céu: organisms within organisms
class HelloWorld with
var int id;
do
_printf("[%d] Hello world!\n", this.id);
every 1s do
_printf("[%d] Hello world!\n", this.id);
end
end
class HelloMulticellular with
@JobLeonard
JobLeonard / DwFE.ceu
Last active August 29, 2015 14:11
First attempt at porting DwFE to Ceu
#include "sdl.ceu"
#include "sdl-gfx.ceu"
input void SDL_REDRAW;
input void SDL_QUIT;
input int SDL_DT;
input _SDL_KeyboardEvent* SDL_KEYDOWN;
native do
SDL_Renderer* REN = NULL;
@JobLeonard
JobLeonard / sleepsort.ceu
Created December 15, 2014 20:22
Sleepsort in Céu
class SleepSorter with
var int t;
do
await (t)ms;
_printf("%d ", t);
end
par/or do
var SleepSorter[100000] sorter with
this.t = (_rand()%100);
@JobLeonard
JobLeonard / Firefly
Created February 1, 2015 09:24
LED-as-sensor sketch enhanced with sine-like pulse (using a lookup table)
// Lookup table for precalculated sine values - basically LUT[t % 512] == (byte)(255 * sin(2 * Pi * t / 512))
byte LUT[512] = {
0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, 2, 2, 2, 3, 3,
3, 4, 4, 4, 5, 5, 6, 6,
6, 7, 7, 8, 9, 9, 10, 10,
11, 11, 12, 13, 13, 14, 15, 16,
16, 17, 18, 19, 20, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38,
@JobLeonard
JobLeonard / DEMO_Arrays
Last active August 29, 2015 14:16
Array explanation in Processing
/*========================================================================
== DEMO: ARRAYS ==
=========================================================================
So far, we can only create one variable at a time:
__________________________________________________________________________
| |
| int x = 100000; |
|________________________________________________________________________|
@JobLeonard
JobLeonard / Drifters.ceu
Created October 9, 2015 11:18
Drifters, Céu-SDL 0.10 version
#include "sdl.ceu"
#include "sdl-gfx.ceu"
input void SDL_REDRAW;
input void SDL_QUIT;
input int SDL_DT;
input _SDL_KeyboardEvent&& SDL_KEYDOWN;
input _SDL_KeyboardEvent&& SDL_KEYUP;
@JobLeonard
JobLeonard / canvas.js
Last active July 29, 2023 01:44
A react component that wraps and autosizes a canvas element
import React, {PropTypes} from 'react';
import { debounce } from 'lodash';
// A simple helper component, wrapping retina logic for canvas and
// auto-resizing the canvas to fill its parent container.
// To determine size/layout, we just use CSS on the div containing
// the Canvas component (we're using this with flexbox, for example).
// Expects a "paint" function that takes a "context" to draw on
// Whenever this component updates it will call this paint function
// to draw on the canvas. For convenience, pixel dimensions are stored
@JobLeonard
JobLeonard / index.html
Last active March 24, 2017 14:04
charAt vs array lookup + string vs array indexOf comparison (http://jsbench.github.io/#cbfad9d07c549532aceb79f8b051553e) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>charAt vs array lookup + string vs array indexOf comparison</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@JobLeonard
JobLeonard / index.html
Last active December 3, 2022 07:27
split string into segments: regex vs substr vs split/slice/join (plus plain split for comparison) (http://jsbench.github.io/#9cb819bf1ce429575f8535a211f72d5a) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>split string into segments: regex vs substr vs split/slice/join (plus plain split for comparison)</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@JobLeonard
JobLeonard / index.html
Created March 27, 2017 09:24
string segments of two: substr vs regex (http://jsbench.github.io/#e5169a605b641037d62ba4f8bbb8f1d8) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>string segments of two: substr vs regex</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>