Skip to content

Instantly share code, notes, and snippets.

View spoike's full-sized avatar
👓
I may be slow to respond.

Mikael Brassman spoike

👓
I may be slow to respond.
View GitHub Profile
@spoike
spoike / Dynamic.java
Created August 24, 2011 16:51
Example on how to do dynamic variable binding in Java
package dynamic;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
/**
* Console example application.
*
@spoike
spoike / sketch_aug31b.pde
Created August 31, 2011 12:02
Processing Sketch - Flames!
/**
* Flames. Generates some flames by using gradients (with basic
* spline math) and Perlin noise (for generating the flame
* height).
*/
/** Flame outer color */
color startCol = color(100, 0, 210);
/** Flame inner color */
color endCol = color(200, 150, 255);
@spoike
spoike / quadtree.pde
Created September 1, 2011 11:16
Quad Tree Visualization
/**
* Quad Tree implementation and visualization in Processing. Executes
* with Processing 1.5.1
*
* Adds points to a quad tree and shows visually as the quad tree
* splits and repushes the values as new values are added.
*
* Restart QuadTree with new values with a key press.
*/
@spoike
spoike / invaders.pde
Created September 1, 2011 19:23
Space Invaders Generator
/**
* Space invaders generator. Generates and draws invaders. Inspired
* by invaders fractals:
* http://www.levitated.net/daily/levInvaderFractal.html
*
* Mouse press will create new invaders and draw the new ones.
*/
/** Scaling factor */
float sc = 3f;
@spoike
spoike / funky_pattern.pde
Created September 2, 2011 07:35
Funky pattern
/**
* Funky pattern generator. Creates a rather funky, Amiga-esque
* demo pattern that fades and regenerates. Looks cool but is
* quite useless.
*
* Uses sinus function to generate the colors, offset and
* scaled so that the bound [-1.0f, 1.0f] is [0, 255] instead.
*/
void setup()
package javaapplication2;
public class BodyPart {
private int health = 100;
private String bodyPartName;
public BodyPart(String bodyPartName, int health) {
this.health = health;
this.bodyPartName = bodyPartName;
}
@spoike
spoike / gist:5876045
Created June 27, 2013 12:31
Paged collections in lodash
// Use _.mixin to extend lodash
_.mixin({
'paged': function(collection, size) {
var pages = [];
this.each(myarr, function(val, i) {
var pos = Math.floor(i/size);
if (!pages[pos]) pages.push([]);
pages[pos].push(val);
});
@spoike
spoike / gist:5876227
Last active December 19, 2015 01:28
Ranked lists in lodash
// Use _.mixin to extend lodash
_.mixin({
'rankedBy': function(c, rank_cb, reversed) {
var ranks = [], pos = 0, _ = this;
var grouped = _.groupBy(c, rank_cb);
ranks = _.sortBy(grouped, function(v) {
return rank_cb(v[0]);
});
if (reversed) {
@spoike
spoike / usage.js
Created July 2, 2013 10:47
Async func with promise and optional callback
// Usage:
var pauseModule = require('./uselessPause');
var callback = function(str) {
console.log(str);
};
// Either call the async function with callback
pauseModule(callback);
// Or call the async and queue the callback to the returned promise
@spoike
spoike / hodor.js
Created July 8, 2013 08:02
Hodor... hodor-hodor. HODOR!
define(['ko'], function(ko) {
var viewModel = function () {
};
viewModel.prototype.hodor = ko.computed(function() {
return "HODOR!";
});
return function() {