Skip to content

Instantly share code, notes, and snippets.

@mucaho
mucaho / example.html
Created November 20, 2015 23:25
CraftyJS using browserify CDN
<html>
<head>
</head>
<body>
<script src="https://wzrd.in/bundle/craftyjs@latest"></script>
<script>
var Crafty = require("craftyjs");
Crafty.init();
Crafty.background('rgb(127,127,127)');
</script>
@mucaho
mucaho / Makefile
Last active August 29, 2015 14:27 — forked from bellbind/Makefile
[iojs][emscripten] Call sudoku solver function implemented in C on iojs
all: libsudoku.js sudoku.js sudoku
clean:
rm -f libsudoku.js sudoku.js sudoku
rm -f libsudoku.js.map sudoku.js.map
rm -f libsudoku.js.mem sudoku.js.mem
# library for using functions in hand written JavaScript code
libsudoku.js: libsudoku.c
emcc -g4 -Wall -Wextra -std=c11 $^ -o $@ \
-s EXPORTED_FUNCTIONS="['_output', '_sudoku']" \
@mucaho
mucaho / generic-js-benchmark.html
Last active February 8, 2022 00:18
Generic template for benchmarking / performance testing JavaScript code using the [Benchmark node module](https://www.npmjs.com/package/benchmark)
<html>
<head>
<script src="https://wzrd.in/bundle/[email protected]"></script>
<script src="https://wzrd.in/bundle/[email protected]"></script>
<script src="https://wzrd.in/bundle/[email protected]"></script>
</head>
<body>
<script>
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
@mucaho
mucaho / index.js
Created July 16, 2015 12:51
requirebin sketch
// Copyright Daniel Berger
// see https://groups.google.com/forum/#!topic/craftyjs/1oOwQrcCd-4
var Crafty = require('craftyjs');
Crafty.init(960, 660);
var computeSpeed = function() {
return 500 + (500 ^ 2 * (((((Floor.y / player.y) ^ 2 + 2 + (player.y / Floor.y) ^ 2) ^ 0.5) * Floor.y * player.y) ^ 0.5) / (((((Floor.x / player.x) ^ 2 + 2 + (player.x / Floor.x) ^ 2) ^ 0.5) * Floor.x * player.x) ^ 0.5)) ^ 0.5
};
@mucaho
mucaho / index.js
Last active August 29, 2015 14:22
requirebin sketch
var Crafty = require('craftyjs');
Crafty.init(800, 600);
Crafty.background('black');
/**
* Chaser Component. Automatically chases entity given speed.
*/
Crafty.c("Chaser", {
required: "2D",
@mucaho
mucaho / ChecksumTest.java
Created May 10, 2015 15:32
Calculate checksum for DominoTest using hopefully deterministic JBox2D - see https://github.com/jbox2d/jbox2d/issues/19
package org.jbox2d.checksum;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Settings;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.*;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@mucaho
mucaho / index.js
Last active August 29, 2015 14:16
requirebin sketch
/**
* DEMO should display particles below the moving platform, but does not, as the current viewport._scale is not
* considered when displaying particles.
* See https://github.com/craftyjs/Crafty/pull/881
*/
var Crafty = require('craftyjs');
Crafty.init(600, 300);
Crafty.background('rgb(127,127,127)');
@mucaho
mucaho / FilterTypes.scala
Last active August 29, 2015 14:15
Scala polymorphic type filtering
object FilterTypes extends App {
import scala.reflect.ClassTag
import scala.reflect.runtime.universe._
object RichClass {
def unapply[T](a: RichClass[T]): Option[T] = Option(a.value)
}
implicit class RichClass[T](val value: T)(implicit val classTag: ClassTag[T], val typeTag: TypeTag[T]) {}
def getOfType[T : ClassTag : TypeTag](list: Seq[RichClass[_]]): Seq[T] = {
@mucaho
mucaho / FXApplet.java
Created November 1, 2014 12:13
FXApplet - A custom java.applet.Applet that sets-up a JavaFX environment.
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javax.swing.*;
/**
* A custom {@link java.applet.Applet Applet} that sets-up a JavaFX environment.
*/
@mucaho
mucaho / SelectiveItemDataModel.java
Created May 9, 2014 15:33
Apache Mahout: DataModel implementation which delegates to underlying DataModel, while allowing filtering of items
import org.apache.mahout.cf.taste.common.NoSuchItemException;
import org.apache.mahout.cf.taste.common.Refreshable;
import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.impl.common.FastIDSet;
import org.apache.mahout.cf.taste.impl.common.LongPrimitiveArrayIterator;
import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator;
import org.apache.mahout.cf.taste.impl.model.GenericUserPreferenceArray;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.model.PreferenceArray;