Skip to content

Instantly share code, notes, and snippets.

View grapefrukt's full-sized avatar
💭
🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭

martin jonasson grapefrukt

💭
🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭
View GitHub Profile
@grapefrukt
grapefrukt / IFilter.hx
Created February 4, 2014 23:04
Here's a few bits and pieces I once used to pitch/filter a sound in OpenFL
/*
The MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@grapefrukt
grapefrukt / Main.hx
Last active August 29, 2015 13:57
Compiler bug? "Variable initialization must be a constant value" despite being just that.
class Main {
// this particular setup gives me the error:
// Main.hx:12: characters 22-85 : Variable initialization must be a constant value
// set either GRID_SIZE, CELL_SIZE or OUTLINE_RATIO to anything else and it's fine
public static inline var GRID_SIZE :Int = 20;
public static inline var CELL_SIZE :Int = GRID_SIZE - 2;
public static inline var OUTLINE_RATIO :Float = 1.2;
@grapefrukt
grapefrukt / RTextField.hx
Created May 30, 2014 11:13
Hack to fix offset/cropped text when scaling a TextField in OpenFL
package flash.text;
import openfl.text.TextField;
import openfl.text.TextFormat;
/**
* ...
* @author Martin Jonasson, m@grapefrukt.com
*/
#if flash
typedef RTextField = TextField;
@grapefrukt
grapefrukt / setconfig.hx
Created October 13, 2014 13:35
Recursively applies the values from one object to another using reflection
static function setconfig(target:Dynamic, config:Dynamic) {
// iterate over the fields of the config object
for (key in Reflect.fields(config)) {
// make sure our target has this field
if (!Reflect.hasField(target, key)) continue;
// fetch the value of the first field
var configvalue:Dynamic = Reflect.field(config, key);
// check if its and object, and if so, make sure it actually has multiple values inside
// (strings are for some reason considered objects)
package com.grapefrukt.games.slicer.utils;
/**
* ...
* @author Martin Jonasson, m@grapefrukt.com
*/
class ConvexHull {
public static function get<T:{x:Float, y:Float}>(vertices:Array<T>):Array<T> {
@grapefrukt
grapefrukt / arcade_joy.ino
Last active August 29, 2015 14:15
This is the code I use for my Teensy 2.0++ Joystick interface in my Arcade machine.
#define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(COND)?1:-1]
#define CHECK_SIZE(a) (sizeof(a)/sizeof(a[0]))
#define NUM_DIR 4
#define NUM_BUT 6
#define NUM_INPUT (NUM_DIR + NUM_BUT)
#define LEFT 0
#define RIGHT 1
#define UP 2
// on init
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at patterns.mvc.views.loader::AbstractLoader/show()
at patterns.mvc.views.loader::MainLoader/show()
at ApplicationHolder/onQueueStart()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.hydrotik.utils::QueueLoader/dispatchEvent()
at com.hydrotik.utils::QueueLoader/openHandler()
@grapefrukt
grapefrukt / gist:730276
Created December 6, 2010 13:22
Three.js error
Uncaught ReferenceError: Float32Array is not defined
THREE.WebGLRenderer/three.js/build/Three.js:138
initgeometry_minecraft.html:125
(anonymous function)geometry_minecraft.html:66
#aDir is a directory path
names = glob.glob(aDir + "/*.png") #file type of the packable images
#append to the list of image objects
if names:
images.extend(names);
# then sort later:
sortedImages = sorted([(i.size[1], name, i) for name,i in ((x,Image.open(x)) for x in images)], reverse=True)
L-Button 1  2 50  W 87  F12 123 
R-Button 2  3 51  X 88  F13 124 
Cancel 3  4 52  Y 89  F14 125
M-Button 4  5 53  Z 90  F15 126
Back 8  6 54  NP - 0 96  F16 127
Tab 9  7 55  NP - 1 97  F17 128
Clear 12  8 56  NP - 2 98  F18 129
Return 13  9 57  NP - 3 99  F19 130
Shift 16  A 65  NP - 4 100  F20 131
Control 17  B 66  NP - 5 101  F21 132