CHROMABITS

1 minute

I’ve recently been working on a Minecraft bot built in Node.js as part of my final project for my artificial intelligence class. The Minecraft-Node connection is possible thanks to a library called Mineflayer which acts as a Javascript bridge between Minecraft and Node.

So far the bot can do the following things:

  • Stare silently at the last player who talked in the chat
  • Pick up dirt blocks from a pre-set resource area
  • Navigate around (using the Mineflayer-Scaffold plugin)
  • Keep track of state using a Knowledge Base
  • Respond to events through logic rules
  • Execute tasks by priority and dependencies (Example: Go to resource site before digging, or prioritize fighting back from digging)

The final goal is to have the bot build a simple column it can climb at night so it can survive longer than a day, and possibly have it build other things during the day.

Demo:

Source code

Test it yourself or make your own changes: The source code is available at http://github.com/etcinit/minebot. It requires Minecraft 1.8 (not lower or higher) to work.


2 minutes

Ensure.js is my JavaScript dynamic type checking library. For more information go here

It’s been a while since I worked on Ensure.js, but I finally got around polishing and writing new features. In this release you can find the following:

New documentation

Documentation screenshot

Most of the library is now documented using JSdoc. Most functions should have explanations of their behavior and some of them have usage examples.

The documentation for the latest version will be online at: http://assets.chromabits.com/ensure/docs/ and it is also included with the source code.

Shields: Protect your functions

One of the most common use cases for Ensure.js that I’ve encountered is checking the input arguments of a function. However, adding a bunch of ensure statements at the beginning of each function can get a bit repetitive after a while.

Version 0.5.0 now comes with a factory function called Shield (ensure.shield), which allows you to add a simple wrapper around your function that will type check your arguments and your return values automatically for you:

// First we create our shielded function
var myFunction = ensure.shield([Boolean, Array], Number, function(arg1, arg2) {
  if (arg1 === true) {
    return {};
  }

  return 1337;
});

// This works fine
myFunction(false, [1, 2]);

// This throws an error since argument 1 is not a Boolean
myFunction([1, 2], [3, 4]);

// This throws an error since it does not return a Number
myFunction(true, [1, 2, 3]);

Production mode

This is a feature I’ve been thinking about ever since the first version of Ensure.js came out: Dynamic type checking can be heavy on your application if you use them extensively. However, once your application is in production, there shouldn’t been a need for type checking (unless your parsing some unknown input or server response).

So, Ensure.js now comes with a global variable for disabling type checks:

ensure.enforce = false;

// This will not throw an error
ensure('Hello', Array);

// This will always return true
ensure('Hello', Array, true);

However, I’m aware that this does not cover every single scenario. Maybe version 1.0 will include a way of instantiating Ensure so you can have multiple instances of the library with different configurations.

Other changes

  • [Breaking] Improved the behavior of has() functions
  • More unit tests for various parts of the library
  • Added ensure.isNotIn()

Source code for Ensure.js is available at GitHub: https://github.com/eduard44/ensure and it is available as a package on Bower and NPM as ensure.js

Please submit any bugs reports or feature requests at https://github.com/etcinit/ensure/issues


1 minute

Here are the slides for my presentation on Modern PHP development with Laravel and Symfony from November 4th:

…or you can find more in the archives.

CHROMABITS
Copyright © 2015-2021 - Eduardo Trujillo
Except where otherwise noted, content on this site is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.
Site generated using Gatsby.