Skip to content

Instantly share code, notes, and snippets.

Avatar

Geoff Blair geoffb

View GitHub Profile
@geoffb
geoffb / command-repl.js
Created Dec 20, 2017
Simple example of a command REPL in Node.js
View command-repl.js
const readline = require("readline");
let input = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let queryCommand = () => {
input.question("Command: ", (command) => {
if (command === "exit") {
@geoffb
geoffb / permut.js
Created Feb 24, 2017
Calculate permutations
View permut.js
var permut = function (array, count, initial, output) {
if (initial.length >= count) {
output.push(initial);
} else {
for (var i = 0; i < array.length; ++i) {
permut(array, count, initial.concat(array[i]), output);
}
}
};
View pixi-spritebatch-mask.js
var renderer = new PIXI.autoDetectRenderer(400, 400);
document.body.appendChild(renderer.view);
var stage = new PIXI.Stage(0x0000FF);
var container = new PIXI.DisplayObjectContainer();
stage.addChild(container);
var spriteBatch = new PIXI.SpriteBatch();
stage.addChild(spriteBatch);
@geoffb
geoffb / simple-canvas-rotation.html
Last active Apr 23, 2020
A simple example of rotating a rectangle using HTML5 canvas.
View simple-canvas-rotation.html
<!DOCTYPE html>
<html>
<head>
<title>HTML5 Canvas Transformation</title>
</head>
<body>
<script>
// Create our canvas and append it to the document body
var stage = document.createElement("canvas");
View canvas-path-fill-test.html
<!DOCTYPE html>
<html>
<head>
<title>Canvas Path Fill test</title>
</head>
<body>
<canvas id="stage" width="256" height="256"></canvas>
<script>
@geoffb
geoffb / QBasic.tmTheme
Created Sep 8, 2011
TextMate QBasic Theme - Just for fun
View QBasic.tmTheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>QBasic</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@geoffb
geoffb / animation.js.diff
Created Feb 16, 2011
Patch allowing Weltmeister to show the first frame of an entity's animation rather than the top left sprite in it's animation sheet.
View animation.js.diff
diff --git a/lib/impact/animation.js b/lib/impact/animation.js
index 20839f9..f367083 100644
--- a/lib/impact/animation.js
+++ b/lib/impact/animation.js
@@ -45,6 +45,7 @@ ig.Animation = ig.Class.extend({
this.frameTime = frameTime;
this.sequence = sequence;
this.stop = !!stop;
+ this.tile = this.sequence[0];
},
View jquery_events.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Event Test</title>
<style>
.red {
background: #f00;
}
.blue {
background: #00f;
@geoffb
geoffb / astar.js
Created Jan 12, 2011
Simple A* Pathfinding
View astar.js
var AStar;
(function () {
var Node = function (index, x, y, parent) {
this.index = index;
this.x = x;
this.y = y;
this.parent = parent || null;
this.f = 0;
@geoffb
geoffb / impact_suspend.js
Created Jan 12, 2011
ImpactJS: Suspend/Resume on blur/focus
View impact_suspend.js
window.addEventListener("blur", function () {
if (ig.system) {
ig.music.stop();
ig.system.stopRunLoop();
}
}, false);
window.addEventListener("focus", function () {
if (ig.system) {
ig.music.play();
You can’t perform that action at this time.