DatsBlog

Clojure on Bukkit minecraft server

Posted in Everything Else by cmdrdats on December 12, 2011

 

This morning, I finally managed to get the basic skeleton of the bukkit clojure plugin “host” working correctly. Clojure doesn’t like having to straddle across classloaders in order to find the resources it needs! I can’t say I blame it :)

It’s a fantastic feeling being able to code plugin stuff on the fly – and as a glimpse into that world, I’ve created a small timelapse video demo’ing some basic possibilities. Apply some imagination though, I’m sure you’ll come up with some awesome stuff..

Most importantly for me is the exploratory nature of Clojure – It fits very well into the nature of Minecraft. It’s thrilling to be able to discover and tweak code for your plugin on the fly.. But see for yourself: Make it full screen btw.

And yes. I get killed by a spider.

Check out the code that makes this little thing tick:

The Clojure plugin source is at : https://github.com/CmdrDats/clj-minecraft

The code (memorystone v2) used in this video: https://github.com/CmdrDats/clj-memorystone

I’m planning to build a leiningen template so that starting a new clojure bukkit plugin is as simple as lein new bukkit-plugin [plugin-name]. I’m also re-implementing my MemoryStone plugin just so that I have a base to work from in order to really flesh out the shared clojure library.

One idea I’m toying with is making a more intuitive way of registering listeners to Bukkit. I’m not sure if I’ll actually end up with anything other than a convenience wrapper function for .registerEvent, but it’s worth messing with.

As you can see in the clj-minecraft project, I’m wanting to provide a fairly solid set of basic plugin building blocks so that you have simple access to the fundemental building blocks of plugins. My goal is also to implement and wrap some common plugins, such as SpoutCraft and the various Economy managers.

I would like the 3rd party libraries to be supported in a way that automatically “switches off” when the plugins aren’t present, so that plugin developers don’t have to worry about it besides actually making sure they have alternative methods of using their plugins.. But we’ll see as I thresh this out.

Feedback will be hugely appreciated and I always welcome a helping hand! So please, contact me, fork my repo’s and make pull requests!

 

Clojure TopCoder Timelapse, Rainy Road, SRM 525, Div II, Level 1

Posted in Coding by cmdrdats on December 1, 2011

I figured out how to make a timelapse video. Yay! Then I decided to tackle another topcoder challenge. RainyRoad -

At the beginning of the video, you’ll notice that I have my browser open – I hadn’t read the problem statement yet, which is dangerous since it could be a really tough problem!

Turns out, it was a dead simple problem. At first it looked like I needed to do some pathfinding (was about to brush up on a*).. but then it was just a matter of checking if both sides of the road is occupied with a “W” or not.. Fairly simple.

So I recorded myself building two solutions and have checked in another (better, imho) solution into the mix. The video is recorded at 5 fps, and each frame is 5 seconds apart, so each second is 25 real seconds..

Take note that I had not prepared at all for the problem. I hadn’t created a project yet or setup anything on my emacs. In the first second or two you’ll see me ‘lein new’ and cd to the new project folder. And then a little later start the swank server for emacs to connect to (about 15s in).

My first approach was to map pairs of path together so that I could just test each pair individually – the second approach, i didn’t bother with that, just doing a for over and index range, concating the letters together and checking for “WW”, then filtering the result for the word “NO” and check the count

The third approach, which you can view here as the function (another-reachable) was a lot more interesting – It interleaved the characters, then used a loop / recur to take pairs off the resulting array, concat the characters and check for “WW” – returning immediately with “NO” if not possible to cross.

You’ll notice that I’m running functions in a *slime-repl clojure* buffer – that’s connected to my running project (lein swank), so I could fire off a thread and have it continue without me being connected.. that’s pretty cool :)

Otherwise – enjoy the video – As always, feedback is really appreciated :)

Clojure + TopCoder SRM

Posted in Coding by cmdrdats on November 30, 2011

I’ve recently started delving into the interesting world of Functional Programming. This was sparked by an amazing video by Rich Hickey called “Simple Made Easy” – I highly advise every programmer to listen closely, this man has his head screwed on right and has given a lot of thought to his subject matter. Even if you’re not interested in Clojure, as a developer, I believe every one of his talks are highly valuable and worthwhile pondering.

In line with adopting Clojure, I’ve mostly switched to Emacs. I still use PhpStorm for PHP development and Eclipse for Java development – I would prefer to move away from them, but emacs has a rather significant “bootstrap” time, so I don’t think I’d really make much of a return on investment there.

Rather, I’m leveraging the excellent emacs clojure-mode with paredit, slime, lein and swank which really makes clojure development shine. I still can’t get over how amazing on the fly development is with emacs + clojure. I have to remind myself that I’m actually working on a program every now and then and not just having fun.

On that vein, my biggest challenge now is wrapping my head around Functional Programming thinking. And I don’t mean just how to do recursions, but to really get to grips with how to leverage the powerful constructs of Clojure – lazy evaluation, lazy sequences, macro’s, immutability, lambda functions, agents, refs, atoms and so on. There’s a lot of good stuff locked away just behind the doors of FP if I just care to take the time to pick the lock :)

To that end, I’ve decided to start doing past TopCoder SRM challenges in Clojure, as thinking practice. I could be doing something, you know, actually useful. But I’m looking for something that’s highly mentally stimulating but small and of a throw-away nature.

I’ve decided to host my solutions at GitHub so that others can see my code, maybe comment and perhaps even learn from the code.. Or at least it’s just there :P

(more…)

Hosting Change

Posted in News by cmdrdats on March 4, 2010

I’ve finally managed (after almost 2 years) to make some time and get my dats.co.za domain updated. I was using HostRocket, but the 2 year renewal is coming up soon and I felt I didn’t use the facilities enough to warrant the price tag any longer.

In order to keep the functionality of my dats.co.za domain though, I needed these things :

  • DNS Server
  • A new blog server
  • An app server of some sort (so I can host code)
  • Basic site

The DNS server is by far the toughest of the lot, lucky I own the dats.co.za domain directly with the co.za registrar, so I could make changes there without much hassle. I looked at, and almost switched to, http://freedns.afraid.org/, but then I found out that they share the domain amongst all their users. Which is quite terrible.

I eventually settled on http://www.zoneedit.com, which is free up to a certain amount of traffic. I’m happy with that since I don’t think my dats.co.za traffic is that great. ZoneEdit is quite minimalistic, but it works extremely well, so I’m very chuffed.

Another thing about ZoneEdit that I mustn’t forget to mention is that they support WebForwards and EmailForwards directly – which is great. I don’t know if all dns servers provide this, but it works like a charm!

Next up, a blog server. A major issue with running and hosting my own blog online is that hackers have an absolute field day – you need to keep on top of things and keep your software up to date so that they don’t exploit all sorts of arbitrary vulnerabilites. I found two or three folders on my dats.co.za site that were using my site as part of a botnet. fantastic. Not to mention the times I’ve had to entirely restore my site from backup because some script kiddie thought they were clever.

Anyway, to my point – I’m enjoying using an externally provided blogging solution, since the admin I have to do on my side is minimal.

It was a tough choice between wordpress and blogger – WordPress has more advanced features, and I’m familiar with it – where blogger is simpler and is a Google product, so integrates more easily and tightly with other Google products. In the end, I customized wordpress and blogger to what I thought was the nicest way, and WordPress just won me over. So here I am :) (To be honest,  I think it was the fact that I could nicely display my buzzes on the side – blogger didn’t do as good a job on that – ironic, no?)

App server was a simple choice – Google App Engine – It supports Java now, so I’m going to be having a field day!

Basic site – I settled on using Google Sites since it already integrates well with the Google App Engine and I could see that it handles nicely when you point your DNS server to it. I enjoyed setting up the site, and while there’s more that could be done there, it serves it’s purpose well. Minimal effort for a well functioning site, what more could I ask for.

On the flip side I don’t have my Eashi wiki any longer, which is a little sad, but it was hardly being used so I think I can get away with running that locally, should I ever want to. I also don’t have the 5gb space any longer, but I don’t think that will ever be a problem, with the kind of free space floating around the internet.

Bottom line, my single point server from HostRocket has been fragmented across an array of free online services. That fragmenting is great because I get to drop and switch if I need to, without paying a cent.

Now, I just need to figure out how to do some kind of automated backup on all of this :P oh well, if all my stuff gets wiped from the face of the earth I doubt anyone will even really notice.

Legoduino!

Posted in Electronics by cmdrdats on March 2, 2010

Tonight I got a bee in my bonnet again.. was curious to see how the arduino would fit on a lego plate (well, technically not quite reaal lego, but let’s pretend for a while), and how I’d go about breaking that out into usable lego chunks..

Again, rather than bore you to tears with the explicit details, I’ll let the pictures do (most of) the talking :

Arduino Duemilanove, mounted on a lego plate.

As you can see, there’s an extra mounting hole – I had started off mounting it to the bottom of the plate, but I think that was just a disaster – there’s not enough space on the plate to break out properly with my paperclip method and trying to hold the whole thing up with just the top studs (against gravity) is precarious at best.. So I decided to put it on top.

Here’s the bottom view, to show the mountings :

I then decided I’ll use some header pins and break that out into sections – Luckily I have a bunch of old serial ports with their connector cables that I could salvage :D (thanks to the guys at work donating me a bunch of old pc parts and stuff) :

If you’re sharp, you might notice the twisted red wire and the odd red wire in the next .. and if you’re an electronic engineer, you’ll probably also instantly guess that I’ve chosen the red wires on each set of connectors to go to ground.

Very handily (is that even a word?), there are 3 ground pins on the arduino, so perfect, since I’ve got 3 connectors out :D

Here’s the finished product :

Now I just have to figure out how to connect those ends up to lego and break it in from there…. Any ideas?

Legotronics

Posted in Electronics by cmdrdats on March 1, 2010

Something that’s been intriguing me for a couple of days now is the possibility of integrating classic electronics directly into Lego. A quick prototype kind of thing where you can just clip things in and out and have them work.

Now, I could fork out a sizeable amount of cash and get a Mindstorms NXT 2.0, or, I could use the Lego I already have, my dremel and some paperclips lying around to make things happen..

I’ve got an Arduino, so I would like to break that out directly into Lego. My first obvious question is how to modify a brick with simple materials easily on hand (and a high-speed, teensy tiny drill press) and get them to be quickly stackable to build a circuit out of them.

I’ve seen a solution out there, using small nails and then clipping wires onto them, I’m not sure I like that approach though – way too many fickle wires to worry about..

A couple of minutes at the workbench, fiddling, and here’s what I came up with – Holes on top and on the sides, bend paperclip, and voila. It’s kinda springy too! I’ll let the pictures do the talking:

Top view:

Bottom View:

Two clipped together, has a sturdy electrical connection:

So will see where this ends up!

PS. Yes, I’m mauling my spare MegaBlocks which I consider aliens to my collection first :) No sense in experimenting with the real thing just yet!

Microprocessors.. Part 1

Posted in Electronics by cmdrdats on April 23, 2009

Frans (my youngest brother) has me suddenly hooked on microprocessors, and now I have a whole design in my head.. Thus a project is born.. Not sure what to call it yet, but the name that seems to stick in my head is ‘Raven’, so we’ll see how it pans out?

From the top – My dad gave me a ‘Fundamental Electronics’ handbook so I can get to grips with the basics and not lose my head in a random electrical explosion, and Frans gave me an Atmel AVR STK500 board with an Atmega48 processor to mess with.

My end goal of my project is this : Build a modular rapid prototyping system, where I can slap in components like wifi, flashdisks, gps’es, motors, etc together via a unified interface (USB seems a logical choice) and quickly code something (in java, of course) to make it all work together.

As far as rapid prototyping languages go, assembler is definitely out of the question with C not far behind.. My choice of language is obviously Java, so I have my eyes fixed on a Sun SPOT – The $750 price tag isn’t going to happen plus getting it here is going to prove painful, so another solution is required.

After a bit of research, I found the Squawk VM, which (hey, surprise) is used on the Sun SPOT – perfect for the job. Now I need to find a chip that can support it – the ARM920T is what the SPOT uses, so something based on that design should work with the least amount of hassles.

Googling somewhat finally turned up the Atmel AT91RM9200, based on the ARM920T it looks perfect for the job – now I just have to source it from an electronics company closeby and maybe find a development board for it, else I’ll have to figure out how to get it programmed manually. fun.


Back to reality, I’ve had to clean up my garage somewhat and I still need to order a semi-decent soldering iron and multimeter (probably from somewhere like rabtron.co.za), put up some shelving and source some organizers and bunches of components.

I’ve downloaded the datasheets and software (AVR Studio 4 and WinAVR) for my AVR STK500 and coded a little bit-runner.. the 8 LED’s simply flash down (in binary) to the number of the button you pressed.. quite simple, except for the weird peculiarity that the high 2-bits are on PORTC and the low 6-bits are on PORTB… I’m thinking there’s some kind of mis-wiring, if you ask me.. but anyhow, here’s my source code :

#include 

int main() {
	DDRB = 0xFF; // Output LED's
	DDRC = 0xFF; // Output LED's
	DDRD = 0x00; // Input buttons

	PORTB = 0xFF; // Set the default lights (0 = on and 1 = off)

	int pressed = 0xFF; // Set the default run value

	int gotoState = 0xFF;
	while (1) {
		// If a button is pressed, run to it
		if (PIND != 0xFF) {
			gotoState = PIND;
		}

		// While we're not at the last pressed button, run to it
		if (pressed  gotoState) {
			pressed --;
		}

		// Wait a little, else everything happens instantly!
		__builtin_avr_delay_cycles(500000);

		// Update the LED's according to the pressed value.
		PORTC = 0xFF & (pressed >> 6);
		PORTB = 0xFF & pressed;
	}
}

Going forward, I’m going to start sourcing all the components for my end-project, start doing a little more formal design-work (so that this becomes a lot less of a blur) and hunt for a victim lone calculator whose LED screen I can steal.. maybe I’ll get myself a full little LCD, but I’m not sure how much I can fit into 4k – i’ll have to figure out how to extend the execution size somewhat, i think, but lets see what pans out..

Till next time!

Phun Challenge: Factory

Posted in Everything Else by cmdrdats on July 18, 2008

First off: whoever hasn’t got Phun – download it here! It’s a very cool 2D physics simulator.

I built an interesting challenge in Phun last night,  Download it here, and now I’m curious to see what solutions people could come up with to make this work, so I’ve decided to issue it as a competition with a small reward of R200 (approx $26) for the best solution.

Objective : Successfully and completely assemble as many of the 5 objects as illustrated in the orange zone example and place them in the demarcated delivery bays. This means you have to move the original pieces to the bays, they have to be attached together correctly and be placed right-side-up.

The simplified rules are :

- Don’t touch yellow area
- Of the existing items you only modify RED gear
- Don’t try looking for loopholes. :P

The extended rules are :

- You may not work in, or modify anything in the demarcated yellow areas – Those areas have to be exactly identical in your solution as the original state.
- You may not move or modify any existing items/hinges except the RED gear.
- You can create whatever you wish and attach to the background or floor plane.
- At no point is your solution allowed to interfere with the orange (example) area.
- I will be the sole judge of the winner, so you’ll be disqualified if I consider something cheating :)
- If you submit multiple entries, I’ll only be testing the last one I receive.

Update: No closing date – if you’re the first to send me a solution, I’ll edit this post and you get the R200 (via pocit – www.pocit.co.za)

After the closing date, I will choose a winner on the best, valid submitted solution – A solution is valid if it gets at least 1 properly assembled object into a delivery bay at least once in the 10 times I run it.

I will be scoring each entry based on the amount of fully correct objects are assembled and placed correctly into the delivery bays over 10 tries (getting all 5 in all 10 runs = max score) – if there is more than 1 solution that can do that, I will tie-break it by the entry that is the most amazing and goes the extra mile – I favour faster, cleaner and more stable solutions.

Good luck and have fun!

How IDE’s could simplify Generics and Annotations in Java

Posted in Coding by cmdrdats on May 8, 2008

This blog entry by Michael Nygard got me thinking, what Michael says is quite true, Java is getting a little rough with all the compiler typesafety ‘help’ we’re getting. Most of the pain is mitigated by all the friendly IDE help these days.. Seriously, I only ever type Map<String, List<String>> in once when I need it.. The rest propagates through the method declarations, instance creation and field declarations through alt+enter (or, ctrl+1, in eclipse)

My thought is that the major problem Michael is outlining is in the view of the java code.. Since IDE’s have full control of the view, we’re in full control to simplify somewhat.. Let’s take an example piece of code :

A bit of a contrived example, purely just to view some code with both generics and annotations. This kind of code is fairly commonplace though, just more prolific – so it gets much messier real fast. What would we prefer to see while working with the code though? I imagine the IDE could easily compress it to something like (ignore the errors for now :P ) :

I can easily imagine it expanding as you move your cursor, or move over it when you’re interested in the actual detail, and it feels a lot simpler than the previous code listing.. The IDE could easily take it a step further by displaying it as subscript – kinda like so (excuse my slightly inconsistent photoshopping) :

I think, however, that all of this info can just disappear though, into a seperate editable popup so that the extra compiler hints and functionality is edited in a separate popup (properly keyboard editable though – you might need to spend some time figuring out what feels correct) :

Again, excuse my quick photoshopping here.. I went all the way here and added icons for the ‘private’ and ‘public’ keywords as well – that may be a little overkill, but my point here is that we don’t need to stick to plain two-dimensional text in editors any more.. In my opinion, once you’re done writing the code, and want to glance it over, you don’t necessarily want to have all the in-depth information in your face all the time.. Which is what attracts people to dynamically typed languages in the first place (well, for me anyhow).

Using the IDE to clear up your view of the code a bit could be a nice bridge between compiler type-safety and code brevity for maintenance.. I’m sure it could open up a whole can of interesting squishy things that you could do, but I’ll leave that as an exercise for you :)

As a sidenote – this kind of functionality is one of the reasons I’m taking a liking to Groovy where, in its essence, it expands easier-to-read shorthand to the full java shebang (in the compiled class file)..

Getting setup for some Netbeans development

Posted in Netbeans by cmdrdats on March 28, 2008

And this means some serious reading to be done (prepare for a bit of a link-fest) :

My starting point is within the Community part of the Netbeans site – there is quite a bit that goes on here but it’s fairly straightforward. After a little digging I find some useful Guidelines, the most notable of which (to me) is the Code Conventions.

Luckily, the Netbeans Code Conventions follows the Sun Code Conventions for Java, which I’ve been following for as long as I remember :) Take special note on the “How to Write Doc Comments for Javadoc” – It contains some really neat info.

With the basic coding guidelines out of the way, the next thing to do is to get the Netbeans source code and get it compiled. To setup Mercurial, I need to download the Mercurial Client. I personally opt for TortoiseHg since I have experience with good old TortoiseCVS and TortoiseSVN – The shell integration is great when things outside IDE’s give hassles and I am personally not a fan of the command line.

Moving on, After installing TortoiseHg and restarting my machine, I just follow the steps outlined here and here to properly get my Mercurial setup inside Netbeans 6.1Beta. And then wait for the clone to happen. This will take a while since, and I quote, “A clone can take anywhere between 1 and 5 hours to complete depending on connectivity”. I’m downloading it over iBurst, so it will likely take 10 hours.. More to come.. :)

Follow

Get every new post delivered to your Inbox.

Join 33 other followers