Skip to content

Instantly share code, notes, and snippets.

View tlhunter's full-sized avatar
📷
Taking Photos

Thomas Hunter II tlhunter

📷
Taking Photos
View GitHub Profile
@tlhunter
tlhunter / cobalt-calibur-game-loop.js
Created September 17, 2012 22:38
Cobalt Calibur Game Loop
var currentFrame = 0;
setInterval(function() {
    currentFrame++;
    if (currentFrame % 3 == 0) {
        currentFrame = 0;
        // redraw every 150 ms, but change animation every 450 ms
        app.graphics.globalAnimationFrame = !app.graphics.globalAnimationFrame;
        app.player.killIfNpcNearby();
    }
    app.environment.map.render(currentFrame === 0);
@tlhunter
tlhunter / cobalt-calibur-viewport.js
Created September 17, 2012 22:53
Cobalt Calibur Viewport Code
initialize: function() {
var view = app.graphics.viewport;
view.WIDTH_TILE = Math.floor($(window).width() / app.graphics.TILE_WIDTH_PIXEL);
view.HEIGHT_TILE = Math.floor($(window).height() / app.graphics.TILE_HEIGHT_PIXEL);
view.WIDTH_PIXEL = app.graphics.viewport.WIDTH_TILE * app.graphics.TILE_WIDTH_PIXEL;
view.HEIGHT_PIXEL = app.graphics.viewport.HEIGHT_TILE * app.graphics.TILE_HEIGHT_PIXEL;
view.PLAYER_OFFSET_TOP_TILE = Math.floor(view.HEIGHT_TILE / 2);
view.PLAYER_OFFSET_LEFT_TILE = Math.floor(view.WIDTH_TILE / 2) + 1;
$('#gamefield').append('<canvas id="map" width="' + view.WIDTH_PIXEL + '" height="' + view.HEIGHT_PIXEL + '"></canvas>');
$('#page, #nametags').width(view.WIDTH_PIXEL).height(view.HEIGHT_PIXEL);
@tlhunter
tlhunter / cobalt-calibur-draw-tile.js
Created September 17, 2012 23:03
Cobalt Calibur Tile Drawing
drawTile: function(x, y, tile) {
var x_pixel = x * app.graphics.TILE_WIDTH_PIXEL;
var y_pixel = y * app.graphics.TILE_HEIGHT_PIXEL;
if (tile == null || isNaN(tile[0])) {
return;
}
app.graphics.handle.drawImage(
app.graphics.tilesets.terrain,
@tlhunter
tlhunter / cobalt-calibur-draw-avatar.js
Created September 17, 2012 23:18
Cobalt Calibur Draw Avatar
var len = app.players.data.length;
for (var k = 0; k < len; k++) {
var player = app.players.data[k];
if (player.x == mapX && player.y == mapY) {
var index = app.graphics.getAvatarFrame(player.direction, app.graphics.globalAnimationFrame);
var player_name = player.name || '???';
var picture_id = player.picture;
if (isNaN(picture_id)) {
picture_id = 0;
@tlhunter
tlhunter / cobalt-calibur-draw-black.js
Created September 17, 2012 23:24
Cobalt Calibur Draw Black
function render(redrawNametags) {
// immediately draw canvas as black
app.graphics.handle.fillStyle = "rgb(0,0,0)";
app.graphics.handle.fillRect(0, 0, app.graphics.viewport.WIDTH_PIXEL, app.graphics.viewport.HEIGHT_PIXEL);
var i, j;
var mapX = 0;
var mapY = 0;
var tile;
if (redrawNametags) app.graphics.nametags.hide();
@tlhunter
tlhunter / gist:3740676
Created September 18, 2012 01:05
PHP localhost dashboard
<?php
session_start();
?>
<html>
<head>
<title><?php echo $_SERVER['SERVER_NAME']; ?></title>
<style>
body {
background-color: #000;
margin: 10px; padding: 0px;
@tlhunter
tlhunter / sofadb.php
Created September 18, 2012 01:09
SofaDB PHP CouchDB alternative
<?php
/*
SofaDB, a pure PHP CouchDB alternative
Developed by Thomas Hunter
Released under the LGPL
May 1st, 2010
Version 0.0.1
This was something I started as a joke, basically a document storage system which
stores files on disk in the form of ID.json. It was never heavily tested...
*/
@tlhunter
tlhunter / traveling-salesman.php
Created September 18, 2012 01:11
PHP Traveling Salesman Genetic Algorithm
<?php
ini_set("error_reporting", E_ALL & ~E_NOTICE);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Genetic Algorithm : TSP : PHP Implementation by Thomas Hunter</title>
<style>
body {
@tlhunter
tlhunter / crawler.php
Created September 18, 2012 01:28
PHP Eve Online Killmail Scraper
<?php
include("mysql.ssi.php");
#Naming conventions: http://support.eve-online.com/Pages/KB/Article.aspx?id=37
#Sample page format: http://www.example.com/?a=kill_detail&kll_id=1000000
# This is a script I wrote a few years ago to scrape Eve Online kill mails. I ran it on a single
# core 2.4 Ghz with 2GB of RAM for a week and it scraped a couple million kills. It stores data
# in a relational format, but I've since lost the schema file. It can be easily reverse
# engineered from this file though. It would scrape sequentially, it should have run multiple
# requests in parallel for better efficiency.
@tlhunter
tlhunter / gist:3750218
Created September 19, 2012 15:20
Node.js Bcrypt won't compile on CentOS
# Yes, openssl-devel is installed.
$ npm install bcrypt
npm http GET https://registry.npmjs.org/bcrypt
npm http 304 https://registry.npmjs.org/bcrypt
npm http GET https://registry.npmjs.org/bindings/1.0.0
npm http 304 https://registry.npmjs.org/bindings/1.0.0
> bcrypt@0.7.2 install /home/thunter/unified-api/node_modules/bcrypt
> node-gyp rebuild