Skip to content

Instantly share code, notes, and snippets.

@walterhiggins
walterhiggins / make-blog.js
Last active August 29, 2015 13:55
A hypothetical server-side javascript blog-making file.
var fs = require('fs'),
_ = require('underscore'),
markdown = require('markdown').markdown,
tinymake = require('tinymake');
// all posts are .md (markdown files)
var posts = _.filter(fs.readDirSync('posts'), function(name){
return name.match(/\.md$/)
});
var pages = [];
var username, password, creds;
var challenge = function( res ) {
res.writeHead( 401, { 'WWW-Authenticate': 'Basic realm="Acme Web Application"'} );
res.end();
};
if ( req.headers.authorization ) {
creds = new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString('utf8').split(':');
username = creds[0];
password = creds[1];
// authenticate here
@walterhiggins
walterhiggins / varargs-overloaded-constructor.js
Last active August 29, 2015 14:07
Trying to call an overloaded constructor with vararg parameters.
var cmRecipe = Packages.net.canarymod.api.recipes.CraftingRecipe;
var cmRecipeRow = Packages.net.canarymod.api.recipes.RecipeRow;
// see https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/api/inventory/recipes/CraftingRecipe.html
var rows = [
new cmRecipeRow("ESW", [ enderPearl, stick, string]),
new cmRecipeRow("SEW", [ stick, enderPearl, string]),
new cmRecipeRow("ESW", [ enderPearl, stick, string])
];
var signature = "(net.canarymod.api.inventory.Item, net.canarymod.api.inventory.recipes.RecipeRow[])";
var enderBowRecipe = new cmRecipe[signature]( enderBow, rows);
@walterhiggins
walterhiggins / init.js
Created January 31, 2015 17:28
Initialization file for use in modding workshop on student servers
'use strict';
/*global require, events, server, Packages*/
var slash = require('slash');
slash([
'groupmod permission add visitors canary.world.build',
'groupmod permission add visitors scriptcraft.evaluate'
],server);
/*
WARNING: The following code makes all players ops.
Only use this for local servers .
@walterhiggins
walterhiggins / boing.js
Last active August 29, 2015 14:15
Javascript Code to make Players bounce when they step on sponge
function bounceOnSponge(event){
var player = event.player;
var location = player.location;
// need to convert coordinates to integers
var x = Math.floor(location.x);
var y = Math.floor(location.y - 1 ); // what's underfoot?
var z = Math.floor(location.z);
var block = location.world.getBlockAt(x, y, z);
if (block.typeId === blocks.sponge){
player.motionY = 2; // springs player high into air
@walterhiggins
walterhiggins / arduino-light.js
Last active August 29, 2015 14:15
Updated arduino-light code
var mqtt = require('sc-mqtt'),
slash = require('slash'),
client = mqtt.client('tcp://localhost:1883','sc-ard-light'),
preDawn = 22000,
JavaString = java.lang.String;
client.connect();
client.subscribe('arduino-light');
var max = 0;
function updateTime(topic, message){
@walterhiggins
walterhiggins / trampoline.js
Last active August 29, 2015 14:15
A Minecraft Trampoline (Version 2)
/*global require, events */
var blocks = require('blocks'),
sounds = require('sounds');
var bouncers = {};
function bounceOn___(event){
var player = event.player;
var id = player.ID;
var bounce = bouncers[id] || 0.75; // get bounciness (default 0.75)
var location = player.location;
@walterhiggins
walterhiggins / trampoline.js
Last active August 29, 2015 14:15
Trampoline Version 1
/*global require, events */
var blocks = require('blocks'),
sounds = require('sounds');
function bounceOn___(event){
var player = event.player;
var bounce = 0.75;
var location = player.location;
// need to convert coordinates to integers
var x = Math.floor(location.x);
var Drone = require('drone');
var blocks = require('blocks');
function skyscraper( floors ) {
var i = 0;
if ( typeof floors == 'undefined' ) {
floors = 10;
}
this.chkpt('skyscraper');
for ( i = 0; i < floors; i++ ) {
this
var inventory = require('inventory'),
items = require('items'),
utils = require('utils');
function giveCookie(player){
inventory(player).add( items.cookie(1) )
}
utils.players(giveCookie);