Skip to content

Instantly share code, notes, and snippets.

View TannerRogalsky's full-sized avatar
💯
P I X E L S

Tanner Rogalsky TannerRogalsky

💯
P I X E L S
View GitHub Profile
@TannerRogalsky
TannerRogalsky / map.lua
Created January 7, 2016 20:14
Load encoded/compressed Tiled data
-- From https://github.com/karai17/Simple-Tiled-Implementation/blob/4ac519dbd5efdc0c6a70c35b9125faebe347772f/map.lua#L217
local ffi = require("ffi")
local function getDecompressedData(data)
local d = {}
local decoded = ffi.cast("uint32_t*", data)
for i=0, data:len() / ffi.sizeof("uint32_t") do
table.insert(d, tonumber(decoded[i]))
end
require "gd"
function project(px, py, pz, win_width, win_height, fov, cam)
local factor = fov / (cam+pz)
local x = px*factor + win_width/2
local y = -py*factor + win_height/2
return x, y
end
local base = gd.createFromJpeg("base.jpg")
function love.load()
player = {
grid_x = 256,
grid_y = 256,
act_x = 256,
act_y = 256,
speed = 10
}
map = {
@TannerRogalsky
TannerRogalsky / CyberBot.java
Created December 19, 2012 02:36
A bot to play cyberzone
package main;
import java.util.*;
import org.jibble.pircbot.*;
public class CyberBot extends PircBot {
boolean noGame = true, prep, inGame;
String chan = "#cyberzone";
ArrayList<Player> players = new ArrayList<Player>();
@TannerRogalsky
TannerRogalsky / colors.lua
Created November 21, 2012 03:09
colors.lua
local colors
local color_map_mt, colors_mt = {}, {}
-- set up metatable imposed on each individual color map table (rgba values)
function color_map_mt.__index(t, k)
local mt = getmetatable(t)
return mt[k]
end
function color_map_mt.rgb(color)
@TannerRogalsky
TannerRogalsky / branch_clean.sh
Created September 11, 2012 13:35
Deletes local and remote branches that are merged into master
function rmb {
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$current_branch" != "master" ]; then
echo "WARNING: You are on branch $current_branch, NOT master."
fi
echo "Fetching merged branches..."
git remote prune origin
remote_branches=$(git branch -r --merged | grep -v '/master$' | grep -v '/production$' | grep -v '/staging$' | grep -v "/$current_branch$")
local_branches=$(git branch --merged | grep -v '/master$' | grep -v '/production$' | grep -v '/staging$' | grep -v "$current_branch$")
if [ -z "$remote_branches" ] && [ -z "$local_branches" ]; then
@TannerRogalsky
TannerRogalsky / gist:3170712
Created July 24, 2012 15:36
Auto-memoizing Fibonacci sequence in lua metatables
fib = setmetatable({1, 1},
{__index = function(t,n)
t[n] = t[n-1] + t[n-2]
return t[n]
end})
[
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+r"], "command": "reveal_in_side_bar" },
{ "keys": ["super+ctrl+r"], "command": "reveal_in_side_bar" }
]
(function ($) {
$.fn.getTextWidth = function() {
var spanText = $("BODY #spanCalculateTextWidth");
if (spanText.size() <= 0) {
spanText = $("<span id='spanCalculateTextWidth" + U_gen_id() + "' style='filter: alpha(0);'></span>");
spanText.appendTo("BODY");
}
var valu = this.val();
@TannerRogalsky
TannerRogalsky / coroutine-iterator.lua
Created April 18, 2012 12:33
Example of lua coroutines being used as iterators.
function permgen (a, n)
if n == 0 then
coroutine.yield(a)
else
for i=1,n do
-- put i-th element as the last one
a[n], a[i] = a[i], a[n]
-- generate all permutations of the other elements