Trying out Node JS with Synaptic

A few weeks ago I subscribed to the Javascript Weekly newsletter as an attempt to immerse myself more into the frontiers of software development! It worked because I ended up with a list of really interesting articles that I never would’ve read otherwise. I’d recommend it! Check it out here.

One of the articles which caught my eye was this lovely tutorial on Synaptic.js: How to create a Neural Network in JavaScript in only 30 lines of code. As an applications developer, Javascript seems really exciting so I wanted to know more, and this tutorial seemed like a really small piece of code to do something quite cool. So I dove in.

The Tutorial

I worked through the tutorial at various points over the course of a day, just reading through the article and retyping out the elements; making a mental note as I went along. It was a really cool and surprisingly simple experience. The library’s website, Synaptic, gives a slightly more exciting demo of the possibilities of the library, with a neural network for traversing a screen as a group. It was the first time I’ve really tried to look into anything javascript specific that wasn’t basic website functionality and it was pretty exciting to see something relatively complex expressed so simply.

SynapticCapture

The synaptic page, with the demo up and running

You specify neurons and connect them up in layers to form a network. Then you activate and backpropagate that network with two simple calls, helpfully named activate and propagate. I still need to spend some time understanding react, node, angular and things like that. But it’s a nice introduction. But I had a problem. I’m a complete Node newbie. So I needed to spend some time working out how to run javascript with libraries from Node to be able to test.

Running Node Apps

So, I bumbled about for a while trying to work out what I’d need to get this to run. The documentation for synaptic actually does a really good job of telling you once you have the context to understand the things its saying. And it didn’t take me that long to find it out.

First things first, was to install Node js. The Node site is real simple and installs npm at the same time. Npm is a package manager for javascript libraries. What that means, practically, is that people will upload their modules to npm and, when you have it installed, you can type a single command in the terminal to download all the library files to your computer. No searching for links. No find the right versions or distributions. Just a line on the command line. Nice.

So once Node and npm were installed, I did some reading up and rememberes about client and server side code. Node JS is a server side technology. That means that scripts you write are naturally meant to exist on the machine where the web page lives. For Node, that means you can pretty easily run the script on your machine using the terminal. On the command line I just typed

‘node E:\Personal\xorNeuralNet.js’

This should work. But I got nothing. It took me some puzzling before I realized I had Node but I didn’t have the Synaptic library code! The following npm command installs it for you; “npm install synaptic –save” and you’re good to go. You need to provide the node command “require()” to inform the runtime that it needs to grab the Synaptic module. Rerunning the node command worked like a charm!

NeuralNetCapture

But this was only half the battle. I wanted it running in my browser. This is a little trickier (though still pretty darn easy as it turns out). Because Node is a server side technology, your browser isn’t able to compile it, because that’s a client side technology. But! Libraries like Synaptic can be minified/browserified to javascript and the browser CAN run that. In fact, this is even distributed with the lirary itself. Convenient!

Running in the Browser

So to get it running in the browser (I use chrome), I had to create a simple html page:

NeuralNetHTMLCapture

Which includes the Synaptic library code ahead of my script. The script I wrote did need a slight modification though. The “require” line is actually a Node function, which means the browser can’t interpret it. But, we’ve already included the Synaptic library from our script html tag, so we actually don’t even need it. A quick delete and a refresh and I had the code running. You can see this by right clicking and selecting Inspect. The panel that pops open has a tab at the top for console, and with that open you should see the output from the script if all went well.

So there you have it. My experiences with running Node for the first time, using the Synaptic library. I learnt a lot from doing it. And for any beginners out there, I hope this helps!

Looking into Vim

Vim

Vim vs Emacs is one of the big fights in the Software Development vanguard. At least, apparently it is? I had only recently heard about Vim and Emacs tangentially from podcasts that discuss more of the recent news in the software world. I ignored it for a little bit, assuming that if I needed to know the knlowledge would find me in due course. But when it had turned up in most of my listening collection, I decided to find out what in the heck these things are and why everyone seemed to be fighting between them.

So What are Vim and Emacs?

Vim and Emacs, it turns out, are programs which allow you to navigate and edit text documents. At least, they are until you become fluent. In their post, Why I Use Vim, Pascal Precht describes the learning curve more like scaling a mountain and sliding down the other side. And from what little I’ve tried, the description seems pretty accurate. They’re powerful text-based editors which allow you to interact with the file system and traverse, search, and edit documents all without leaving the program or even having to touch the mouse. They can serve as an alternative to a visual IDE in the software development world. The intention is that, without the need for the more graphical elements of modern IDEs, the terminal style editor can be faster and the editing of code can be more efficient due to being able to freely switch between contexts of use with just the soft slap of a single key.

I had done a little bit of research but, to be honest, I still wasn’t getting it. So I thought I’d just give it a try.

Trying it out

Downloading Vim is pretty quick and the install process is simple. I work on Windows for the moment, so that’s what I installed (and also let’s you in a bit on the super graphical world I’m coming from). Opening up the application presents you with a black, terminal-esque window with a bunch of blue tildes. The classic blinking cursor sitting idly, awaiting the divine keystrokes of a User; with a capital U. A short message lets you know that typing :help will bestow upon you the knowledge of the ancients, the commands by which you can control this arcane console. Like an explorer in the midst of a magi-technological discovery, you imagine the Rosetta stone that this must be; the secret to untapped power and your key to understanding. What appears is a wall of text referencing other documents which, if I had read in full would probably have told me everything I needed to know. Except that I had no idea how to navigate it. The help file is extensive and a little daunting. Honestly, I actually set Vim down for a bit at that point. The problem was that I just had no idea how to get started and, since I wasn’t really sure what it did, I didn’t know what problems to apply it to.

A week or so later, my curiosity had not abated. I was sure that if I dug a little further the reason that everyone cared about these, seemingly unwieldy, text editors would become clear to me. So I did what any knowing professional would in my shoes. I googled it. I discovered OpenVim.

VirtualVim

Using a virtual vim terminal, the site walks you through your first few commands of Vim. It is by no means exhaustive. It’s a short and simple tutorial of basic editing and navigation. But that’s enough. With that short sample I became an apprentice sorcerer. The runes had begun to make sense and I could feel that there was something a little more powerful at the end of this journey. I was excited to explore more; to gain more knowledge. So I used it for a real life problem. I was not fast. I was not a super human hacker now. But there was something intuitive about the mode switching and navigation without having to leave the keyboard. It took me a while to realize that that was what I liked about it. What I still like about it. Using Vim made me realize quite how much you could do without having to touch the mouse at all, outside of Vim as well. A lot of the programs proponents say, and I haven’t been able to tell how serious they are about this, “why would you ever want to leave Vim?” But as a mere apprentice sorcerer, there’s plenty of tasks I still need to do away from that editor. And using the mouse felt natural. But there’s something really fun about being able to traverse you’re whole machine without lifting your hands more than an inch from the keyboard. I don’t actually think it made me faster or better. But using Vim forced me to think about what keyboard shortcuts my programs and desktop offers. And I found that I was really enjoying it. It felt much closer to putting what I wanted to do into action without any barriers. I’m not saying everyone is gonna have this experience. The mouse hand is a useful tool and it can help you to think. But I can see why people use Vim. With the right start and if you can keep the commands in your head for long enough, then it can become a really easy way to traverse text documents. Does it replace an IDE? I’m not sure yet. There’s a lot you need to do in order to be able to set it up with any of the features that modern IDEs have out of the box.

There is a best of both worlds solution. It’s possible to install Vim plugins to some modern environments such as Visual Studio and CLion which place the navigation and input aspects of Vim ontop of the functionality provided by more modern development tools. This seems like a pretty promising step to me in terms of development speed. So I might give that a try at some point.

If you’re interested, here’s where to get Vim and some good resources on the commands available for getting started.

Vim Website – The website for downloading Vim

Vim Adventures – A little adventure game based around Vim commands. A fun way to get used to the basics.

Vim Cheat Sheet – Pretty dry but really useful during learning. Just the basic commands one after the other.

5 Favourites: Podcasts

Podcasts have been a staple for me for years. Since I was in my second year of university I can remember having a love for them and I have fond memories of escaping from my life into other worlds during long cold walks to my part time job. They’re pretty brilliant. And with the internet so readily available and data cheaper than ever, you can find all sorts of podcasts, about all kinds of things at various production values. Today I thought I’d share some of my favourites with you!

As usual, I don’t claim these as the best podcasts. I don’t even claim that they are my absolute favourites. They’re just some pretty great ones that I picked out. A small caveat here, my definition of podcast is going to be pretty broad here. I really mean any serial, audio only media. This could include things like audio dramas and weekly web-radio shows. But, without further ado, here we have:

5 Favourites: Podcasts

Critical Hit

criticalhit

Critical Hit is where it all started for me. I was in my second year of university and I was feeling pretty rubbish in general. It wasn’t a great time in my life. But I had finally managed to do something I’d always wanted to do and that was play Dungeons and Dragons. I’d picked up the 4th Edition Red Box and got my friends to play and it was awesome. So much fun. But it wasn’t enough. I wanted more. More to do with DnD. More time spent playing. Or at least in that world. So I googled it. And one of the things that came up was the Critical Hit Podcast. Revelation!

Critical Hit is a real play podcast which begins with the game master, Rodrigo Lopez, introducing the game to the host, Stephen Schleicher, who plays an Eladrin wizard just graduating from wizarding university. What follows is literally hundreds of hours of world building, real honest character progression, dnd game explanation and friendly banter. They cover combat pretty explicitly and thats great. I learnt how to play DnD long before I got to practice much. But what I come back for is the story and the characters and the people. The group is wonderful and friendly. Rodrigo weaves this utterly mind boggling story through difficult moral choices and moments of light hearted fun, all the way through to haunting and painful moments. I won’t spoil any of it. But if you’re at all interested in DnD, give it a try.

Decoder Ring Theatre

DecoderRingCapture

I discovered Decoder Ring Theatre through Critical Hit. One of the episodes CH has is a mail bag and on one such episode, the players were asked to list some favourite podcasts of theirs. Decoder Ring Theatre was mentioned, so I checked it out. And I am so glad I did. Created by Gregg Taylor, Decoder Ring Theatre is the host of two main series’. The lead series is The Red Panda; a show done in the style of a villain of the week type super hero show that follows the hero of the same name and his spunky sidekick The Flying Squirrel. Together they fight various forces sources of strife based on the time period, which ranges from the 30’s era depression on through World War II, mixed in with a little bit of magic, mystery and mayhem. This series is good fun, but it is not where my heart lies in DRT. That belongs to Black Jack Justice.

Black Jack Justice is a detective series following partners: Jack Justice and Trixie Dixon, girl detective. Set post-war in “the big bad city”, the series takes the form of a case log narrated by the two main characters. The cases range from murder mysteries, to jewel heists and moral ambiguity is abound. The mysteries are fun and the host of side characters that you come to know is a bundle of joy in itself. But it’s the slow progression of the detective duo that really grabs me. They develop, as people do. Not with endless virtues but with flaws and the changing of tiny habits. You learn to love their catch phrases. The little details that make them them. Some of the stories are small and a little silly. Some have a harsher tone. But I’ve enjoyed listening to them all for years.

Edict Zero

EdictZero

I honestly have no idea how I found it, but I am so glad that I did. Edict Zero is a beautiful podcast. That might sound like an odd way to describe a podcast, particularly when I tell you that it’s a sci fi special investigation audio drama, in the same vein as the X-Files. But my gosh is Edict Zero a beautiful podcast. The attention to detail is amazing. I have listenes to the whole series through multiple times, and every time I connect a new dot or understand the foreshadowing a little better. I have no idea how the story is planned but there seems to be reasons for everything and they’re revealed organically. Existential themes are everywhere and I think the use of the sounds to convey sequences without any conversation is excellent. Like critical hit, the story builds episode after the episode. It’s a little slower, designed for intrigue and steady progression; but it has it’s fair share of action too. I look forward to every episode, which are largely released on an “as soon as we can” schedule. If you love detail, mystery and paranormal style investigation, Edict Zero is well worth a listen.

The Once and Future Nerd

TOAFNCapture

The Once and Future Nerd is another staple of mine. But I didn’t take to it quite as quickly as the other podcasts in my list. Another audio drama, I found The Once and Future Nerd after having finished a run of Critical Hit. I wanted a new Dungeons and Dragons podcast to listen to, but I was interested more in the story than the DnD. Google delivered again with TOAFN. It is not a Dungeons and Dragons podcast though. What it is is a high fantasy audio drama set in its own world, with its own takes on some of the classic fantasy races. It follows the journey of a group of children thrown together into an unknown realm, as they discover themselves and confront their inner demons.

When I discovered it the series had just started, and I listened not knowing what to expect. It hit some of the tropes hard and I wasn’t sure about how the characters treated each other. I ended up stopping for a while. But it remained in the back of my head for months afterwards. There was something enticing about the ways fantasy realm and the mysterious prophecy that geys introduced. So I tried it again a little later. What a great decision. It turns out that the things that I was worried about are actually deliberately worrying and get used as ways to explore societal issues with the fantasy world as a metaphor. I really enjoy the tough questions and character perspectives explored in the series and, to add to that, the moments of tension are even greater because of the realisation that the situations are somewhat analagous to real world issues. I think it’s well done and I really enjoy it.

Geek History Lesson

GHL

Geek History Lesson is relatively new to my podcast portfolio but it’s one that I’m really  enjoying. A part of the Major Spoilers podcast network set up by the previously mentioned Stephen Schleicher, Geek History lesson is a show which runs through the backstory and histoy of various pop culture characters organisations. It’s hosted by Jason Inman and Ashley Victoria-Robinson, and the main source of characters is from comic books. This is where I think the series does it’s best work, as the hosts are really knowledgeable and clearly excited to tell you about the wonderful world of whoever they’re looking into that week. Ever wanted to know about X-23? Spiderwoman? Psylocke? There are full episodes devoted to these characters and more; covering publication history, fictional history, recommendations, interviews and more. They cover other pop culture such as TV shows like Game of Thrones as well, but I haven’t listened to much of it. The show is an excellent way to cover large swathes of the, sometimes confusing, world of comics and it’s totally free! Give it a try if it sounds interesting.

Special Mention: Sega Mixerdrive

Though Sega Mixerdrive didn’t make my top 5, it will always have a special place in my heart. A part of the Radio Sega family and hosted live by Rexy, a fairly well known remixer and musician, Sega Mixerdrive showcases great remixes of Sega game tunes. I really like the show. It helped me through my degree and I still listen to the archive today. If you’re into videogame music, give it a try!

Well, there you have it! As I said before. These aren’t all my favourites. There really are a wonderful amount of podcasts out there. These are just the ones I couldn’t not put up there. I didn’t even get to mention Welcome to Nightvale! Whatever subject interests you, throw it into google, chuck the word podcast on the end and see where it takes you. The world of radio is born again in the podcast.

Let me know your favourite podcasts in the comments! Or send me an email!

Using AutoHotkey

AutoHotkeySiteOver the past couple of months at work, I’ve been beginning to notice all the little things that I need to do to develop. Things like running multiple applications to test; navigating folders in cygwin to run build scripts; or even adding template code for things like debugging. They never seemed like much. Just a part of the job that takes the time it takes. But, as I’ve gotten more used to using my keyboard to navigate my machine, I’ve had to think about the things that I do in a new light to try to see if there’s some way to replicate that without using the mouse. So all the jobs that had just become muscle memory for me began to really show up.

Now, there’s nothing wrong with being comfortable with your methods; whatever works to get you producing the stuff you want to be making. But if you’re feeling like you want to find a way to do things a little faster, or you’re tired of doing some actions a bunch of times, or you just would like to try some scripting then I may have just the solution for you. It’s called AutoHotkey and I think it’s really cool!

What Is Auto Hotkey?

AutoHotkey is a program designed to make make scripting events on your computer simple and hugely flexible. By entering a triggering combination and a series of events to perform in a simple file, called a .ahk, and then loading that file into the autohotkey program, you’re able to invoke a series of potentially complex behaviours with a single combination. This can become a hugely powerful tool for saving time. It’s also super fun! It’s another one of those tools which starts to make you feel like a techno-sourcerer.

By writing short snippets, you suddenly have the power to automate all the tedious or error prone things that you had to do before. Got a file path you have to type in a lot? Make a hotkey for it! Need to copy files from one place to another every three hours? Make a hotkey for it! A piece of template code you write a lot? Hotkey. You get the idea.

Getting Auto Hotkey

Getting auto hotkey is really simple. Just get on to http://www.autohotkey.com/ and go to the download link that you’re presented with. Grab the latest version, because it’s more fun to live life on the edge! Run the installer and you’re good to go. What you’ll have access to is a desktop application for Autohotkey which will open up a  reference to the autohotkey scripting language.

AutoHotkeyHelp

It’s pretty unassuming, as far as references go, but it hides a wealth of information. The fine people at Autohotkey help you out with a nice opening page, which gives you some first steps to take in having a look at the scripting language. And the search box is super robust! I tend to just think of kind of what I want to do, tap it in there and see what comes up. Usually you’ll get a stream of hits and I’ve not yet had a problem I’ve not been able to find in there, with a bit of rooting around.

I’d advise actually going through the tutorial in there, which is thorough, covers what I will cover here and goes into more depth. But if you want it all on one page, feel free to keep on reading here and then go back to the AutoHotkey Help when you want to dive in deeper.

The application doesn’t actually do anything other than provide access to the reference. What you really need the installer for is for the ability to load the autohotkey scripts that we’ll cover next.

Writing Your First Hotkey

This is all very well and good, you’re saying to yourself, but I’m no cyber-mage just because I’ve got some book filled with words. Well let’s get into the fun stuff then, shall we?

Writing your first autohotkey script is easy as ready made pie; all you’ll need is your favourite editor. Below is the simplest of simple autohotkey scripts:

AutoHotkeyTutCode1

The script is made of three parts: the initiating key combination; the instructions to carry out; and the return statement.

The initiating key combination is exactly that. It comes in the structure of keyboard keys that need to be pressed all at once, followed by two colons and it tells Autohotkey what combination of keys need to be pressed in order to perform the instructions on the subsequent lines. The letter keys are as is but, because you’re probably not going to want your hotkey tp trigger every time you press the ‘d’ key, I’ve added an augmentor to it. The ‘^’ represents the control key (on windows). The colons are just there to signify the end of the key sequence. So that first line means “Autohotkey, please do what comes next every time I press ‘ctrl’ and ‘d'”. We want to be polite to our chip based partners in crime.

The second line is where we tell autohotkey what we want to do. In this case, I decided that I hate having to type all those pesky letters every time I want to log a debug message in my C# scripts for Unity 3D. So I want a hotkey that just writes it out for me. To do this I’m using autohotkey’s ‘Send’ command, followed by a comma. The comma is optional but I find it makes the distinction between command and input super obvious. Then, after that, is the string I want autohotkey to type. This is an important distinction! Autohotkey isn’t taking you’re string and pasting it into the editor. The ‘Send’ command explicitly sends key events for each key you specify, one after the other. That means that if you click somewhere else, autohotkey will start throwing key presses into that new program or new space! It also means you can replicate key presses to any program, this means you could potentially traverse your machine with a hotkey! There are ways in Autohotkey to automate things in the background, with conditions, with loops, with user input; the list goes on. It is a playground of wonderful things to try. You can have as many instructions as your require beneath your intiating key combination, as long as its before a return statenent, so keep going til you find what you need.

Finally, the return statement is the last line needed to finish off your script. All the return statement does is inform autohotkey that there are no more statements to execute for this shortcut. And there you have it! Once you’re happy with your script, all you need to do is double click the file to load it as the active hotkey script and you’re good to go! If you’re loading it for the first time since startup, you won’t see any change. If you want to confirm that auto hotkey has your script loaded, just double click the file again. You should be gifted with a pop up which will inform you that you’re about to replace the active script. This is because you can only have one autohotkey script running at a time. But don’t worry. You can add as many hotkeys to same script as you can remember key combinations for, provided that you have a return between each key combination line.

Combining It With Batch Scripts

I’m sure you’re brain is aflame with the fires of imagination! Your hands busy forging the combinations of which your personalised spell book will comprise. But there’s more! One way to increase the power of your hotkeys is to use them to run and initialize batch scripts.

For those who might not know, batch scripts are another and probably more powerful way to automate parts of your workflows and life in the computing realms. Honestly, I’ve barely scratched the surface on batch scripts so mine are all a bit small and manual still. But by using the ‘Run’ command in your autohotkey script, as shown below, you can call up a batch script or other program. This is one way to keep your hotkey scripts neat whilst also being able to automate complex tasks.

Also shown is the ‘SetWorkingDir’ command, which sets the context for all the following commands until the next ‘Return’ statement. Because this command is a little more serious, I’ve added the ‘!’ key, which represents alt on the keyboard, to the initiating combination too.

AutoHotkeyTutCode2

 

Well! That’s it! I’ve found this to be a really fun and powerful way to increase my productivity without having to spend a huge amount of time learning things. Autohotkey is massive and there are plenty of things to try out. So if you find something that you have to do often, or that you’d rather not do manually, consider an autohotkey script. If you found this useful, or thought something could’ve been done a bit better, then please let me know.

Have a great day everyone!