Skip to content

Instantly share code, notes, and snippets.

@mkosler
mkosler / Block-HaxeCPP.cpp
Created May 9, 2012 21:10
The CPP source file of a Puzzle League block when built with Haxe
#include <hxcpp.h>
#ifndef INCLUDED_hxMath
#include <hxMath.h>
#endif
#ifndef INCLUDED_com_haxepunk_Entity
#include <com/haxepunk/Entity.h>
#endif
#ifndef INCLUDED_com_haxepunk_Graphic
#include <com/haxepunk/Graphic.h>
@mkosler
mkosler / draw_image.dart
Created August 3, 2012 15:15
Drawing an image onto the HTML5 canvas
// Taken from StackOverflow (http://stackoverflow.com/questions/11599113/dart-lang-how-to-load-image)
var image = new ImageElement();
image.src = 'my_image.png';
image.on.load.add((e) => /* draw image after it has loaded */
// OR
context.drawIamge(image, x, y, width, height);
@mkosler
mkosler / gist:4248079
Created December 10, 2012 02:53
Catmull-Rom
double catmullrom(double t, double p0, double p1, double p2, double p3, int m1, int m2)
{
std::vector<std::vector<double> > t_vec(1, std::vector<double>(4, 0.0));
t_vec[0][0] = t * t * t;
t_vec[0][1] = t * t;
t_vec[0][2] = t;
t_vec[0][3] = 1;
Matrix t_matrix(1, 4, t_vec);
std::cout << "+++ Time Matrix +++\n" << t_matrix << std::endl << std::endl;
@mkosler
mkosler / gist.c
Created February 13, 2013 10:23
Annotated guide to WRONG!
if(block_found.isempty == 1)
{
if(block_found.block_size == _length)
{
//int p = 0;
//for(p = log2(_length) - log2(*BASIC_BLOCK_SIZE); p < log2(*TOTAL_BLOCK_LENGTH) - log2(*BASIC_BLOCK_SIZE) + 1; p++)
//{
// printf("free_list_left[%d] isempty = %d \n", p, free_list_left[p].isempty );
// printf("free_list_right[%d] isempty = %d \n\n", p, free_list_right[p].isempty );
@mkosler
mkosler / downsample.cpp
Created March 20, 2013 01:20
Bad downsampling! Bad!
void Canvas::downsample(float *pixels, unsigned side)
{
unsigned nside = side / 2;
for (unsigned i = 0; i < nside * nside; i++) {
unsigned row = i / nside;
unsigned x = (i * 2) + (row * side);
unsigned y = x + 1;
unsigned z = x + side;
unsigned w = z + 1;
@mkosler
mkosler / ball.lua
Created March 23, 2013 05:30
Manager
-- Possible topic:
-- - The require statement
local Manager = require 'manager'
-- Possible topic:
-- - Object-oriented programming
local Ball = Class{}
function Ball:init(x, y, r)
self.x = x
self.y = y
function Level:setMood(mood)
for i,interactive in ipairs(self.interactives) do
if interactive.name == "Barrier" then
interactive.body:setActive(interactive.type ~= mood)
end
end
end
@mkosler
mkosler / main.lua
Created February 16, 2014 18:46
LuaPlaysPokemon
local socket = require("socket")
function getNextMove(commands)
local max = {
command = "",
count = 0,
}
for command, count in pairs(commands) do
if count > max.count then
@mkosler
mkosler / main.py
Created February 17, 2014 00:53
TwitchDrawsPokemon
import re, socket, time
from PIL import Image
def send(sock, msg):
print(">> {}".format(msg))
sock.send(msg + "\r\n")
if __name__ == "__main__":
IMG = Image.new("RGB", (128, 128), "white")
PIXELS = IMG.load()
@mkosler
mkosler / controller.js
Last active August 29, 2015 13:56
TwitchHasAController
$(function () {
$("#controls > div").hide();
$('<canvas id="viewport" width="140" height="65">')
.css("float", "left")
.appendTo("#controls");
$("<button />", {
text: "Show",