Skip to content

Instantly share code, notes, and snippets.

View stpettersens's full-sized avatar

Sam Saint-Pettersen stpettersens

View GitHub Profile
@stpettersens
stpettersens / tap.js
Created August 5, 2015 00:08
Touch pad tap code.
function isTouchScreenDevice() {
var isTouch = false;
var ua = navigator.userAgent;
if(ua.indexOf("Mobile") !== -1 || ua.indexOf("Tablet") !== -1) {
isTouch = true;
}
return isTouch;
}
window.onload = function() {
@stpettersens
stpettersens / sort_cards.js
Created August 5, 2015 00:06
Sort some playing cards (unused code from Blackjack implementation).
Cards.prototype.sort = function() {
this.sorted_hearts = [];
this.sorted_diamonds = [];
this.sorted_clubs = [];
this.sorted_spades = [];
for(var i = 0; i < this.deck.length; i++) {
var rs = this.deck[i].split(' ');
var num = 0
if(rs[0] == 'A') num = 1; // Ace
else if(rs[0] == 'J') num = 11; // Jack
@stpettersens
stpettersens / cheat_sheet.markdown
Last active August 29, 2015 14:26
Cheat sheet for porting between CoffeeScript, Dart, Haxe, TypeScript and Lua.

Cheat sheet for CoffeeScript, Dart, Haxe, TypeScript and Lua.

Cheat sheet for porting between CoffeeScript, Dart, Haxe, TypeScript and Lua.

Types

Types supported.

@stpettersens
stpettersens / jquery-urlparam.min.js
Last active August 29, 2015 14:24
jquery-urlparam
/*
jQuery module to get URL parameters.
Copied from: http://stackoverflow.com/questions/19491336/get-url-parameter-jquery
Minified.
*/
$.urlParam=function(a){var b=new RegExp("[?&]"+a+"=([^&#]*)").exec(window.location.href);if(b==null){return null}else{return b[1]||0}};
@stpettersens
stpettersens / gen_xnb_4_video.cs
Created January 23, 2013 13:54
Generate an XNB file for the video which is needed for the XNA content pipeline.
private void WriteXNBVideoData(string video)
{
string file = video + ".xnb";
// Only write the file when the file name is qualified correctly.
if(!file.Equals(".xnb"))
{
using(BinaryWriter bw = new BinaryWriter(File.Open("Content/" + file, FileMode.Create, FileAccess.Write)))
{
byte[] bytes = { 0x58, 0x4E, 0x42, 0x77, 0x05, 0x01, 0x55, 0x01,
// Define a Caption 'class'.
function Caption(message, color, x, y) {
// Properties.
this.message = message;
this.color = color;
this.x = x;
this.y = y;
// Methods.
@stpettersens
stpettersens / comp3142_index.html
Created July 5, 2012 01:34
Complete homepage listing.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Use UTF-8 encoding as it supports many characters -->
<meta charset="UTF-8"/>
<!-- Include stylesheet -->
<link rel="stylesheet" media="screen" type="text/css"
href="stylesheets/presenter.css"/>
<!-- Include Atom feed of project commits -->
<link rel="alternate" type="application/atom+xml"
@stpettersens
stpettersens / comp3142_canvases.css
Created July 4, 2012 17:44
CSS for canvas 'layers'.
/* (Demonstration) canvases. */
canvas {
position: absolute;
margin: auto;
border: 1px solid #c3c3c3;
}
/* 'position: absolute;' is used as I found this caused the canvases
to stack upon each other in layers as I had intended. */
@stpettersens
stpettersens / comp3142_demo_canvas.html
Created July 4, 2012 17:05
HTML5 canvas 'layers'.
<canvas id="demo-base" style="z-index: 0;" width="730" height="300">
</canvas>
<canvas id="demo-ui" style="z-index: 1;" width="730" height="300">
</canvas>
<canvas id="demo-overlay" style="z-index: 2;" width="730" height="300">
<!-- Message when CANVAS is not supported -->
<em>Your browser does not support the CANVAS element.<br/>
Please use an <a href="http://html5.com">HTML5</a>
-compliant browser to view this demonstration.</em>
<!-- /Message -->
// Clear the canvas.
context.clearRect(0, canvas.width, canvas.height);
/* Where context is a CanvasCanvasRenderingContext2D object
assigned via canvas.getContext("2d"); and canvas is
a canvas element. */