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 / Bot.java
Last active November 17, 2017 17:49
An IRC bot for playing rock paper scissors.
import org.jibble.pircbot.*;
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Random;
public class Bot extends PircBot {
public final String PARENT = "C:\\Documents and Settings\\Tanner Rogalsky\\My Documents\\RPS\\users";
public String mainChannel;
@TannerRogalsky
TannerRogalsky / program.lua
Created July 11, 2011 04:24
BFG10K program
function middleofsquare(x)
local m = tostring(math.pow(x, 2)):sub(4,9)
m = m:match("^[0]*(%d*)") --trim leading zeros
local offset = 1
while(string.len(m) < 6) do
m = tostring(math.pow(x, 2)):sub(4 - offset,9 - offset)
m = m:match("^[0]*(%d*)") --trim leading zeros
offset = offset + 1
end
return m
@TannerRogalsky
TannerRogalsky / RES Module - Subreddit Linker.js
Created July 12, 2011 03:20
A module for Reddit Enhancement Suite (RES) which finds any subreddit mentions that are not links and converts them into links.
modules['subredditLinker'] = {
moduleID: 'subredditLinker',
moduleName: 'Subreddit Linker',
options: { },
description: 'Finds any subreddit mentions that are not links and converts them into links.',
isEnabled: function() {
return RESConsole.getModulePrefs(this.moduleID);
},
include: Array(
/https?:\/\/([a-z]+).reddit.com\/user\/[-\w\.]+/i,
@TannerRogalsky
TannerRogalsky / index.html
Created July 24, 2011 18:26
Injecting only part of a remote page into the DOM via jQuery AJAX get request.
<html>
<head>
<script src="jquery-1.6.2.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
$.ajaxSetup ({
cache: false
});
@TannerRogalsky
TannerRogalsky / MyBot.java
Created December 25, 2011 00:12
Old Hunt the Wumpuse IRC bot
import org.jibble.pircbot.*;
import java.util.Random;
import java.util.ArrayList;
public class MyBot extends PircBot {
public String channel; // The name of the primary channel.
public ArrayList map; // The map data. 0 = empty, 1 = wumpus, 2 = shaft, 3 = bats, 4 = player.
public String player; // The player's nickname.
public boolean gameInProgress; // Whether or not there is a game in progress.
@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
(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();
[
{ "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" }
]
@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})
@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