Skip to content

Instantly share code, notes, and snippets.

View cacciatc's full-sized avatar

Chris Cacciatore cacciatc

View GitHub Profile
@cacciatc
cacciatc / clearance_users_controller_with_invite.rb
Created July 16, 2011 22:56 — forked from mchung/clearance_users_controller_with_invite.rb
Fix: so a user can only use their own invite code
class UsersController < Clearance::UsersController
# Override and add in a check for invitation code
def create
@user = User.new params[:user]
invite_code = params[:invite_code]
@invite = Invite.find_redeemable(invite_code)
# Invite code is present, there is an associated invite, and it is the user's invite
if invite_code && @invite && @invite.email == @user.email
@cacciatc
cacciatc / vis.js
Created January 10, 2013 20:26
JavaScript to be used with ScriptCraft to create static sorting algorithm visualizations in Minecraft.
load($SCRIPT_DIR + "/../drone.js");
var arr = [{i:1,b:'35:1'},{i:5,b:'35:5'},{i:3,b:'35:3'},{i:2,b:'35:2'},{i:4,b:'35:4'},{i:7,b:'35:7'},{i:8,b:'35:8'},
{i:6,b:'35:6'},{i:0,b:35},{i:14,b:'35:14'},{i:13,b:'35:13'},{i:12,b:'35:12'},{i:10,b:'35:10'},{i:9,b:'35:9'},{i:11,b:'35:11'}];
var render = function(a,d){
d.up(a.length);
for(var k =0;k< a.length;k++){
d.box(a[k].b).down();
}
@cacciatc
cacciatc / towers-of-hanoi.js
Last active December 11, 2015 05:19
Towers Of Hanoi
var hanoi = function(n, source, by, dest){
if(n == 0) return;
// Move all the disks but the bottom disk (n – 1 disks) from the left pole to the middle pole.
hanoi(n-1,source,dest,by);
// Move the bottom disk to the right-most pole.
print("Move " + n + " from " + source + " to " + dest);
// Move all the disks from the middle pole (n – 1 disks) to the right-most pole.
hanoi(n-1,by,source,dest);
}
@cacciatc
cacciatc / move-viz-towers-of-hanoi.js
Created January 16, 2013 22:58
Render move solutions to n-disked Tower Of Hanoi puzzles.
load(__folder + "drone.js");
Drone.extend("toh",function(dc){
var d = this;
var tf = function(dc){
var ta = [];
var tb = [];
var tc = [];
Python Mistakes
===============
* It's not Ruby.
@cacciatc
cacciatc / simple-scriptcraft-plugin.js
Last active December 11, 2015 18:08
Simple ScriptCraft plugin.
load(__folder + "../core/scriptcraft.js");
/*
definition
*/
var simple = simple || plugin("simple",{
setString: function(str){
this.store.str = str;
},
getString: function(){
@cacciatc
cacciatc / wolf-bot-func.js
Created January 26, 2013 01:01
Wolf bot functionality.
var bot = bot || plugin("bot",
{
/* helper methods for a player's bot */
get_bot: function(player){
return this.store.players[player.name];
},
set_bot: function(player,bot,inventory){
this.store.players[player.name] = {bot:bot,inventory:inventory};
},
/*
@cacciatc
cacciatc / wolf-bot.js
Last active December 11, 2015 18:09
Basic Wolf-bot.
/*
Usage:
/jsp summon
/jsp dismiss
/jsp come
/jsp stay
/jsp pack
*/
load(__folder + "../core/scriptcraft.js");
@cacciatc
cacciatc / spawn.js
Last active December 12, 2015 10:09
Bukkit Villager spawn.
spawn:function(){
var player = getPlayerObject();
var world = player.getWorld();
// create a villager
var quest_npc = world.spawnCreature(player.getLocation().add(1,0,0), org.bukkit.entity.EntityType.VILLAGER);
quest_npc.setProfession(org.bukkit.entity.Villager.Profession.PRIEST);
quest.store.npcs[quest_npc.getUniqueId()] = quest_npc;
// listen for interaction events
@cacciatc
cacciatc / quest-init.js
Last active December 12, 2015 10:09
Quest initialization.
initialize_quest:function(player_name){
quest.store.players[player_name] = {
current:-1,
accepted:false,
skeleton_counter:0,
steps:[{
step:1,
text:"Hello, " + player_name + ". I have an unpleasant task if you desire some work."
},
{