Daniel Ennis (Aikar)

The Return

So, the past 2 months have been hectic.

I’ve purchased my first house… So i’ve been busy with all of that process, moving, etc, spending loads and loads of money into the new house… There was no time for programming. 🙁

But I think I’ve finally gotten back to a resting point in life, as another major goal in life knocked down (and man are they falling this year!, New job, new car, new home!) so I should hopefully be able to return to developing my projects again.

Although I haven’t done much coding on my open source projects recently, I’ve still been keeping up with Node.JS, so still aware of everything. Now its time to get back and get dirty with some MongoDB…

Google Traceur for Node.JS

I’ve written aother node module to provide Google Traceur support for Node.JS

If you are not familiar with Traceur, read up on it here: http://code.google.com/p/traceur-compiler/
And the features it provides: http://code.google.com/p/traceur-compiler/wiki/LanguageFeatures

http://github.com/aikar/traceur

Examples: http://aikar.co/projects/traceur/

To use:
npm install traceur
then require(‘traceur’)

then all require() calls can be traceur syntax files.

Note you can’t use Traceur syntax on the file that includes Traceur,
since this extends require() itself to go through Traceur first before
being passed to normal node require().

Get sucked in… Wormhole!

I have finally released my 2nd module to the Node.JS community, Wormhole!

Wormhole provides a message queue system over network streams using the MessagePack library for serialization. The streaming deserializer is great for performance and memory usage, and allows you to have very high performance compared to JSON or traditional message queues.

Check out the Wormhole library on github

It’s magic…

So, I was reading over the V8 docs yesterday and found a really neat feature in the C++ API… Interceptors.

Interceptors let you provide a global getter/setter on an object so you can get a callback for ANY property request/set without specially adding a setter/getter by name for it. This is something that I’ve found lacking in V8 JS Land to mimic PHP’s __get and __set methods, but it appears it does exists, just only on the C++ side!

So I wrote Magic this weekend, my first full 1.0.0 (1.0.1 actually, slight fix) release of a module to the public (advertised). This lets you play with a Magic Object with your own custom getters/setters (Interceptors) and do creative things with it.

Hopefully some modules that use promised based approaches will find creative ways to use these magic objects and create useful things out of it!

Download/Instructions @ GitHub

2 Way local folder synchronization with lsyncd

So I have a use case scenario at work where 2 way folder synchronization is of use for me. I tried using rsync but its not designed for 2 way.
Then some lovely people in #rsync on Freenode told me of some other tools, namely unison and lsyncd.

Unison does a good job of syncing between 2 dirs, and would solve the problem just fine, but it requires running the tool to do the sync process.

Ideally, I wanted something that would sync immediately on file change, which is exactly what lsyncd does.

However, it’s based on 1 way sync, but due to how it performs it doesn’t have deletion problems like my first attempts at rsync did.

So to provide 2 way with lsyncd, you simply run the tool twice, 1 for each direction.

I’ve wrote a quick bash script that can auto start the sync process for you, designed to be ran as a cronjob to ensure the daemons are running.

Create the file

~/bin/syncdirs

and paste the following in it

#!/usr/bin/env bash
#########################
## syncdirs
##
## syncs 2 directories with 2 directional sync using lsyncd
## apt-get install lsyncd
##
## written by aikar@aikar.co
## http://aikar.co/2011/03/07/2-local-folder-synchronization-lsyncd
##
#########################

sync="lsyncd --delay 0"
if [ $# == 2 ]; then
    if [ -d $1 ] && [ -d $2 ]; then
        d1="$(readlink -f $1)"
        d2="$(readlink -f $2)"
        
        sync1="$sync $d1 $d2"
        sync2="$sync $d2 $d1"
        
        found=0
        ps ax | grep -v grep | grep -q "$sync1" 
        if [ $? != 0 ]; then 
            $sync1
            found=1
        fi
        ps ax | grep -v grep | grep -q "$sync2"
        if [ $? != 0 ]; then 
            $sync2 
            found=1
        fi
        if [ $found == 1 ]; then
            echo "syncing $d1 and $d2"
        else
            echo "was already syncing"
        fi
    else
        echo "syncdirs: ERROR!"
        if [ ! -d $1 ]; then
            echo "$1 is not a directory"
        fi
        if [ ! -d $2 ]; then
            echo "$2 is not a directory"
        fi
    fi
else
    echo "syncdirs usage:"
    echo "syncdirs directory1 directory2"
fi

and then

chmod +x ~/bin/syncdirs

then if you have ~/bin in $PATH, type

syncdirs /path/to/sync /path/to/sync/with

and you should be told the dirs are now syncing.

to add ~/bin to PATH if not already done, edit ~/.bashrc and add

export PATH="$HOME/bin:$PATH"

Now to ensure they are always syncing, type

crontab -e

and add to bottom

* * * * * ~/bin/syncdirs /path/to/sync /path/to/sync/with >/dev/null

Now you should have the sync daemons auto start by cron on system start, and auto relaunch them if they die for any reason.
Disclaimer: I take no responsibility for what this tool does nor my starter script does to your files. (I didn’t even make lsyncd!)
make sure you have backups of your files before running these tools on them!!!

Minimal Gnome – My Ubuntu Theme / Layout

I’ve tweaked my OS layout quite a bit lately to highly customize it to give me alot of screen real estate. I’m pretty satisfied with it and decided to share.

Minimal Gnome (monitor 1)

Minimal Gnome (monitor 2)

 

Minimal Gnome 3 (apps)

I will give you instructions on how to setup your Ubuntu 10.10 to be like this, however note this guide will expect you to be moderately technically experienced with the Linux OS… not going to hand feed things here.

First, download my theme: http://aikar.co/dropbox/MinimalGnome.zip
And the background: http://aikar.co/dropbox/GNOME-AlphaGnome_1024x768.png

This theme is based off the Clearlooks theme, which was very white. I based off this because alot of apps are not friendly to dark backgrounds for input boxes and web pages, messing up websites without full CSS rules, and apps like Evolution having dark backgrounds and people setting black fonts made it impossible to read. So we want to keep some aspects white still while making the overall OS dark.
I’ve modified the colors of Clearlooks to do this. With a very nice blend of dark greys.

Unzip the MinimalGnome theme into your ~/.themes/ folder. Then go to System > Preferences > Appearence and choose it.
Go to backgrounds tab and choose this background, and select a background color thats dark. This background is transparent and will blend to what ever background color you choose!

You should now be dark!

Next steps is to rearrange Gnome panels to be like mine to get a nice minimal theme.

First, delete the Menubar on the top panel, then add a “Main Menu” to the panel (Not Menu Bar!) This gives you the same things as the Menu bar but all in 1 Ubuntu button.
Then beside that button add a Drawer.

Put all your apps inside the Drawer. Simply click it to open, open app, it closes.

Next move your Window List off the bottom panel and drag it to the top (there is a little handle to the left of the Window List, right beside show desktop if you still have that on panel, look closely)
If you cant drag it, simply delete it and readd it to your top panel flush to the left of the Ubuntu menu and Drawer icons. (Add to Panel > Window List)

Note you can right click on any panel and click move to move the panel easily and get each one tightly flushed to each other. Get that Ubuntu menu, Drawer and Window list flush left!
Then delete the bottom panel to get rid of it. (Move workspace/trash/showdesktop to top if you really want those)

Repeat the same on other monitors, and that will cover your base OS layout.
Simply drag apps into Drawer or right click on Drawer and Add to Drawer to add things.

Next up is the Firefox slim down.

You need a few addons for Firefox 3.6. I have not done this for 4.0 yet so this guide is for 3.6!

Get the following:
Theme: https://addons.mozilla.org/en-US/firefox/addon/ace-foxdie-graphite/
Tree Style Tabs: https://addons.mozilla.org/en-US/firefox/addon/tree-style-tab/
Hide Caption Titlebar Smart: https://addons.mozilla.org/en-US/firefox/addon/hide-caption-titlebar-plus-sma/
Compact Menu 2: https://addons.mozilla.org/en-us/firefox/addon/compact-menu-2/

Now from a base line installing these addons and maximizing firefox should get you to nearly where I am.
You don’t need to mirror my settings exactly and I dont know how to get you to exactly where I am, but you should be close now. So go tweak your setup to YOUR liking from here.

Tabs setup is in Tree Style Tabs addon, the hidden title bar is in Hide Caption Titlebar addon, and the theme itself is Foxdie in your tools menu and the fox icon in status bar, and it auto popups the configuring page on first start.

Tweak things to how you want them. Good luck!

Ubuntu – Prevent sleep while sharing files over samba

Windows has a little feature that Ubuntu/samba server sadly does not seem to have: On Linux, If another user is accessing files on your samba server, the system will still enter an S3 Sleep / suspend, where as Windows will stay awake until the share is no longer active.

After some research I have developed a script that will prevent Ubuntu from sleeping while sharing files. If your HTPC is accessing videos on your desktop, this can prevent your desktop from sleeping.

These instructions were designed for Ubuntu 10.10 with the GNOME desktop as it relies on a command “gnome-screensaver-command”. If you find another command that can reset the system idle timer, the script could work for you.

To Prevent sleeping while samba is active, create the file ~/.checksmb with the following script: (scroll down for instructions creating file if you don’t know how)

#!/usr/bin/env bash

# sleep prevent command - "gnome-screensaver-command --poke" resets idle timer
PREVENTSLEEP='gnome-screensaver-command --poke'

# gnome-screensaver-command uses X11 which expects this ENV to be set
export DISPLAY=:0.0

#### DO NOT EDIT ####
smbstatus | grep -q "DENY_WRITE"
if [ $? == 0 ]; then $PREVENTSLEEP ; fi

open a terminal (control + alt + T or use menu > Accessories) and type gedit ~/.checksmb and then paste that code into the file, save and close.

Then in the terminal, run chmod +x ~/.checksmb
Nothing should of printed from that.

Then type crontab -e to open the editor for crontab.

If prompted to select an editor, choose what ever number nano is. its the default on Ubuntu 10.10.

Scroll to bottom of file (page down key) and add ON A NEW LINE

* * * * * ~/.checksmb

That line should be all by itself. Now press Control + X, and then press Y to confirm save.

Now, if you haven’t already, you can go configure your PC to go to Sleep after inactivity under System > Preferences > Power Management.

Every 1 minute this script will run and check if anyone is accessing files over Samba (SMB) and it will prevent sleep / suspend.

BareNPM: A bare minimum NPM package installer.

Just wanted to update on what i’m currently working on.
Nova is pretty much in a releasable state except that I ran into another idea to do at work and it was something I could use asap at work so I began work on it.

I’m creating an alternative package installer for NPM, with a few key differences:

  1. No symlink hell: Maybe no symlinks at all. I’m designing it to install a package from NPM without any symlinks (i think I may make it so that if you link to a non JS file as a module it will symlink, but undecided yet as that feature doesn’t even work on default NPM, so possibly wont do any symlinking)
  2. Lightweight packages: A module package will not include tons of references to other dependencies in its folder. It will simply be the folder that was published to npm (usually the project on github)
  3. Per Project basis: Modules will be installed to a specific projects libs folder and not on a global level. Letting you manage the packers needed for your specific project, and no needing to worry about file permissions, and no need to worry about deployment ensuring your server has all the needed npm packages installed at the correct version.

The recursive symlinks of npm destroy some IDE’s and overall makes a hard to figure out folder structure. They also do not play as nice for windows, causing it confusion.
So that was the main reason for making this. As I could no longer work on my project due to the symlinks (yes it’s an IDE bug that should be fixed, but the linking isn’t really necessary, at least not recursively)

Also, the idea of global modules does not serve well for packaging modules into a projects version control. Trying to configure npm to install to a projects folder instead of global was a nightmare.

So barenpm is designed to be a tool for people who want to bundle packages as part of their project and included in a much leaner fashion.

I also am writing this in order to show to Isaacs so he may take some ideas from this implementation of the install method and hopefully get NPM to provide these features and not need symlinks. That is my ultimate goal,
but I needed the solution now and could not wait for NPM to officially support these ideas.

If you want to check out the current code, hit it up on my github http://github.com/aikar/barenpm
It’s not done, but it’s getting close.

I will finish up Nova documentation and do a proper release afterwards.

Nova: A JavaScript based template engine for Node.JS

Previously I wrote that I will be releasing a JavaScript based template engine very soon (HOPEFULLY this weekend) for Node.JS, so I wanted to talk a little on that.

One big annoyance with template engines these days for me is the idea that the syntax has to be some special unique format, in which no IDE or editor will ever support out of the box unless it gets extremely huge like Smarty. That to me is very annoying, as you lose all the benefits syntax highlighting and other features your editor can provide.

So I decided to make a template engine where the syntax is simply JavaScript, and the DOM can be controlled fully through JavaScript.  Now your site could be fully coded in JavaScript (Client Design, Client Feature, Server, Database (mongo))! JavaScript is on the way to world domination!

The promise is simple. Provide a template system that is 100% JavaScript code (the code is evaluated just like it was a Node.JS module), where your editor can provide out of the box support for syntax highlighting and common errors. Also the ability to lint your template too.

Since the code is fully ran JavaScript, you also have the ability to utilize Node.JS functionality into your template.

Wait you say, “functions and logic inside a template engine?! That goes against the point of a template engine!”

No, It doesn’t. Some random guy on the Internet made a blog post saying HE thinks you shouldn’t have any logic done in a template and it spread, and now everyone thinks that its bad to have logic in a template.
But no, it’s not. You’re end goal is to make use of the tools available to you, and accomplish your goals cleanly, efficiently, and as quickly as possible.

If you only have a flat head screw driver, which fits into the size of a Phillip head screw, would you run to the store to buy a Phillip head screwdriver, or would you use the Flathead and just unscrew the screw?

A tool or library should not necessarily restrict you from doing things. It should be you, the user of said library, who decides the best practices and implementation for your project. If you want to keep all logic out of a template, then do it. If you feel having logic in a template makes your task easier, then do it.

This concept that the tool should dictate what you use it for needs to go.

Nova will be flexible, and not restrictive. So you can build your template however you want. You give it data in its expected fashion, and it will act on that. It’s not going to spank you for using logic in your template. (Although if you’re into that kind of thing I can write a special version for you for a price… :))

Here is an example (very basic) template for Nova:

======

======

as you see, its very simple JavaScript, and since its JavaScript and not JSON, you dont even have to wrap the keys in strings

{h1:{id: ‘header’}}

would work just as fine. Again it’s YOUR choice for standards.

Now. Nova caches templates on load to pure HTML so this syntax isnt parsed EVERY time the template is rendered. But static templates are no fun of course… we need to be able to render dynamic content!

Well, notice that nova variable I didn’t use in the example? That has helper functions! One of those functions is nova.onRender
This function will let you specify a callback function to execute anytime the template is rendered. Note the object notation format is parsed and processed on COMPILE time, ie the very first request, then on render the onRender functions are called to fill in dynamic data.

So how do you use them? take the following template above and lets replace the [‘My content’] with:

=====

=====

So when you call template.render() in your application, you pass it 2 arguments, with the first (optionally) being render variables.
These are variables you can build in your applications logic before rendering to the client, then pass it to template to use just like any other template engine.

The difference here is that since most of the HTML is cached and this is a JavaScript oriented language, the processing and printing of the variables in the template is done through JavaScript functions.
Also, because templates can render Asynchronously.

Notice in the above example, we give a different call to render based on if username was set or not.
Firstly to explain render, anything passed to this function will be the ‘answer’ to what content should fill the onRender spot. So if my username was Aikar, I would see:

<div id="content">  <span>Greetings Aikar</span></div>

Also notice I was able to still use the Nova style syntax of the template, and did not have to type raw HTML!
Nova is extremely flexible, and will give you the tools you need to write fun templates.

Also, again they are Asynchronous. The template runs all onRender async, and will wait for all of them to ‘answer back’

So say you wanted to do some async operation like a database query (again, do what you want with your templates, it’s your choice), you would do something like this:

========

========

Check the Nova docs when its released for more helpers such as partial/include support!

Giving to the Node.JS community: Nova, Meteor, Wormhole

I’ve done a lot for communities in Final Fantasy XI and other games, and been a good community leader, but now I’m finally ready to release a library to open source! (I’ve worked on projects to release but never finished…)

Over the past week or two I’ve been working on a new Template Engine for Node. Why another you ask? Well cause I felt like it mainly, and wanted to do something interesting.

On our websites we have our client side code in written in JavaScript, and with Node.JS, our server side code is also JavaScript. Then add on the database layer where NoSQL is a more popular choice, and then some of the more popular databases are also founded on… JavaScript! (CouchDB/BigCouch, MongoDB, and maybe sure others?).

So I thought, why not a JavaScript based template engine too!

So now I am working on Nova. As you may know (by either knowing me or reading my blog), I am working on a space game, so I’ve chosen the space theme as a naming scheme for my modules I write. I am wanting to write a lot of the modules Starlis will use, and then release them to the public.

I already have plans to do a MongoDB wrapper similar to Mongoose as my next library, named Meteor. I also have some code I’ve already written a base for message framing and sending over streams, and plan to do an RPC layer on top of, using the MessagePack format for serialization which is a lot better in performance than JSON. It will use pgriess’s node-msgpack library which I’ve forked and added support for Node 0.3.x.

I also plan to add a CSS layer onto Nova shortly after release, providing the same syntax for CSS.

Read my next blog post for details on Nova!

Look forward to my modules soon, First being Nova, then Meteor and Wormhole sometime after.

I am Senior Software Engineer and Entrepeneur. I am an enthusiast and love creating things. I operate my own side company in my free time called Starlis LLC, working in Minecraft.

I enjoy doing things right and learning modern technologies.