Skip to content

Instantly share code, notes, and snippets.

@walterhiggins
walterhiggins / make-blog.js
Last active Aug 29, 2015
A hypothetical server-side javascript blog-making file.
View make-blog.js
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 = [];
View node-auth.js
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 Aug 29, 2015
Trying to call an overloaded constructor with vararg parameters.
View varargs-overloaded-constructor.js
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 Jan 31, 2015
Initialization file for use in modding workshop on student servers
View init.js
'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 / arduino-light.js
Last active Aug 29, 2015
Updated arduino-light code
View arduino-light.js
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 / boing.js
Last active Aug 29, 2015
Javascript Code to make Players bounce when they step on sponge
View boing.js
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 / trampoline.js
Last active Aug 29, 2015
A Minecraft Trampoline (Version 2)
View trampoline.js
/*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 Aug 29, 2015
Trampoline Version 1
View trampoline.js
/*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);
View skyscraper.js
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
View cookies-4-all.js
var inventory = require('inventory'),
items = require('items'),
utils = require('utils');
function giveCookie(player){
inventory(player).add( items.cookie(1) )
}
utils.players(giveCookie);