Skip to content

Instantly share code, notes, and snippets.

View Fintan's full-sized avatar

Fintan Fintan

View GitHub Profile
@Fintan
Fintan / BaseView.hx
Created December 28, 2011 21:34
Implementation of IViewContainer for RobotHaxe based on Mike Cann's gist: https://gist.github.com/1502132
package demo.view;
import flash.display.Sprite;
import flash.display.DisplayObject;
import robothaxe.core.IViewContainer;
class BaseView extends Sprite, implements IViewContainer {
public var viewAdded:Dynamic -> Void;
public var viewRemoved:Dynamic -> Void;
@Fintan
Fintan / SampleInterface.hx
Created December 30, 2011 14:38
Simple interface example
package interfaces;
interface SampleInterface {
//Read only property
var ro(default,null):Int;
//Write only property
var wo(null,default):Int;
@Fintan
Fintan / Test.hx
Created June 8, 2012 17:12
Perlin Noise Example
import flash.events.Event;
import flash.display.Shape;
import flash.display.Sprite;
class Test {
static var W = 540;
static var H = 300;
static var colours = [0x419164, 0x21A4A6, 0x52BAAB, 0x85CCBE];
@Fintan
Fintan / grid_layout.hx
Created October 2, 2012 11:53
grid layout algorithm
//grid layout snippet:
for(i in 0...cellCount) {
var cell = cells[i];
var xPos = (i % cols) * (cellWidth + colSpacing);
var yPos = Math.floor(i / cols) * (cellHeight + rowSpacing);
cell.x = xPos;
cell.y = yPos;
@Fintan
Fintan / prev_and_next
Created October 2, 2012 11:59
prev and next snippet
var slideCount:Int;
var currentSlide:Int;
function getNextIndex():Int
{
return currentSlide < slideCount ? ++currentSlide : slideCount;
}
@Fintan
Fintan / gist:3926739
Created October 21, 2012 11:30
Plasma (Seb Lee's)
/**
see it working here: http://try.haxe.org/#Bb6eF
taken from here: http://seb.ly/2007/11/animated-plasma-in-flash/
*/
import flash.display.BitmapData;
import flash.events.Event;
import flash.display.Bitmap;
@Fintan
Fintan / gist:3938945
Created October 23, 2012 14:08
Tube drawing
/*
see it working here: http://try.haxe.org/#DEacf
A circle follows the cursor and gets copied to a bitmap
Uses an adaptation of hype.extended.behavior.FixedVibration
*/
import flash.display.BitmapData;
import flash.display.Sprite;
@Fintan
Fintan / gist:4536887
Created January 15, 2013 07:22
how-to-save-your-model-to-database-in-backbone-js One of the way to solve this problem is override the save method in your backbone model and send an ajax request from save method.
var Shopper = Backbone.Model.extend({
save: function (options){
var model = this;
$.ajax({
url:'/your/url/',
type:'POST',
dataType: 'json',
data: model.toJSON(),
success: function (object, status){
//things to do if model saved successfully.
@Fintan
Fintan / gist:5077619
Last active December 14, 2015 11:09
A state machine based on the example shown here: http://lamehacks.net/blog/implementing-a-state-machine-in-javascript/ This version uses Underscore and Backbone
var states = [
{
'name':'working',
'initial':true,
'events':{
'bored':'coffee',
'call_for_meeting':'meeting',
}
},
{
@Fintan
Fintan / D3 test.js
Last active December 14, 2015 17:59
D3.js snippet to help understand enter/update/exit good tutorial here: http://mbostock.github.com/d3/tutorial/circle.html
//select p tags to manipulate
d3.select("body").selectAll("p")
//initial dataset
.data([4, 8, 15, 16, 23, 42])
//create any nodes that don't already exist (all of them)
.enter().append("p")
//set the node text based on the data