to type or not to type…

that is the question.  Rather than a Shakespeare reference, I’m here referring to a term in software development which determines how a language deals with variables, for example.

Define: type

When you create a variable in a computer language, it’s usually something like this:

var someVarName = 1;

In a case like this, we might infer that someVarName stores a number (an integer).  We might say that the someVarName‘s type is integer.  Using a pet-ownership metaphor, it’s like purchasing a dog house first (“someVarName”) and then next buying a dog to put into it (“1”).  You wouldn’t buy a fish bowl to store a dog… although this seems to work out great if you own a cat.  JavaScript, e.g., is like this picture:  it doesn’t seemingly care if you want to store a cat in a fish bowl.

cat-in-a-bowl

Two Schools of Thought

There are two camps out there:  those who like languages which force the variable type and those who don’t.

A statically-typed language usually involves a step in which your code is converted into something else (compiling) and any type-related issues must be fixed before a program can be created.

A dynamically-typed language is run “as is” and the code is evaluated at the moment of truth—determinations about the type of a variable are made at this time.  If there is a type-related issue, your end-user could be the first person to see the error.

Statically-Typed Dynamically-Typed
Java JavaScript
C++ Python
C# PHP
C Objective-C

The Pendulum Swings

Over the past three decades, the popularity of either approach has waxed and waned.  It’s safe to suggest for the moment that the less-strict languages are gaining rapidly in popularity over their stricter counterparts.

most-popular

We have the world of open source to thank for the popularity and speed of development we’re currently seeing in these dynamically-typed languages like JavaScript and Python.

Seeing the Future

Honestly, though, there are too many people in that strict-is-better camp and their influence is felt within software development companies.  If I were to guess at the future of JavaScript, I’d probably have to say that TypeScript and Flow will gain in popularity as larger development teams look to lower the number of bugs in their code.

I don’t know, though.  Maybe it’s time that we just relax and let the cat hang out in the fish bowl.

 

blinking the raspi’s built-in LED

I’ve just added a repository of some JavaScript code to take over and exercise the built-in activity LED on a Raspberry Pi Zero W (and presumably other models). It’s called gpiozero-toggle-led and it’s a pretty simple interface with installation instructions and some sample code. It works with the underlying js-gpiozero JavaScript port of the popular original Python code. This would be an excellent way of simply demonstrating GPIO without any additional wiring, components, breadboards, extra power supplies or electrical knowledge (like finding a 330-ohm resistor using its color bands).

zero-wireless

Note that the “zero” in the title of the repository and in js-gpiozero does not refer to the Raspberry Pi Zero but to the original gpiozero Python library.

This should remove some of the guess work when attempting to use the relatively-new library since their documentation examples at the moment are taking a back seat to their code port from the more-extensive Python offering.

This approach can easily be modified to instead exercise external LEDs (as soldered or otherwise attached to the header pin locations seen below).  Note that you’ll use “BCM numbering” for APIs such as this one. For external LEDs, you would need to connect it inline with a resistor from a selected pin to one of the grounds for this to work with correct orientation of the LED’s anode/cathode, of course.

raspberry-pi-pinout

If you’re trying to use this with a Raspberry Pi of a different model, you’ll likely want to adjust the JavaScript slightly as seen below.

/routes/index.js:

// Existing code, for a Raspberry Pi Zero
var ledActivity = new LED(47, false);
// For Raspberry Pi 3, for example
var ledActivity = new LED(47);

And that’s it. Since the Raspberry Pi Zero assumes an opposite value for true/false than the bigger models, it’s necessary to configure this in the device constructor to make things work as expected. Since BCM pin 47 is the activity light on the board itself, this will allow you to control it.

o please, gentlemen, a little bluer…

Today’s inventiveness involves a new teaching method for music, a synesthetic approach to colorizing musical notes. The title’s quote comes from Franz Liszt, a 19th-century composer who was a synesthete—he saw music in full color.

Although western doctors probably think of synesthesia as a malady, I would suggest that it is a product of beneficial neuroplasticity. The brain has cross-wired itself across the senses to allow for better recognition and appreciation of something. There’s a long list of famous musicians and composers who wrote of this personal condition and in each case it helped them to succeed.

vexflow-syn

In order to promote this cross-wiring in young musical students, I’ve created a repository to colorize musical notes in client-side JavaScript. I’ve developed an organized method for this and have described the process there.

Compatibility

Given that the client-side JavaScript approach requires the newer HTML5 canvas features, this will work on newer browsers (and seems to be working in IE11 if you “allow blocked content”).

Musical Talent

I have always had a fondness and an early aptitude for music. In fact, I had such a brilliant audible memory and an ability to play anything I’d just heard, that I used this as a crutch when confronted with the task of learning to read musical notation. I didn’t actually have to read the notation in band since the sound of the music was in my head. So although I was a slow reader with respect to notation, nobody actually could tell.

My earliest formal training was for the saxophone, noting of course that you only play a single note at a time. Unfortunately, this led to my later difficulties in learning to play the piano in my thirties. Piano chords on a stave? To me, this just seemed like jumbles of notes piled on top of each other. I had no easy way of interpreting what I was seeing.

After many weeks of painstakingly trying to decypher these heiroglyphics, if you will, I began to have a small breakthrough. My brain started to recognize some patterns. Due to some unfortunate timing, I had to stop all this training and abruptly move and had to sell the piano. It would be another decade until I’d bought another piano to re-learn piano notation.

Attacking the learning of chords-in-notation anew, I realize that colorizing the notes would be a benefit to me.  All C notes are red.  All E notes are yellow.  C-E-G are primary colors (C-maj).  The Eb in the middle of the C-min chord is more orange than the original yellow. A synesthetic approach to musical notation is a wonderful adaptation to a centuries-old teaching methodology I’d suggest, at least in my own case.

too much fun

My two packages arrived today at the post office so I just hauled in all the loot from this earlier post in which I’ve purchased some new toys.

Raspberry Pi Zero W

The photos from their website don’t really describe how truly small this computer is now. They’ve somehow managed to stack the RAM on top of the microprocessor to save space. As I’ve apparently ordered the wrong video adapter cable, I’ve got a trip over to Best Buy Frye’s Electronics this evening so that I can sort that one out. I need a female HDMI to DVI, in other words. Otherwise, I’m still pretty stoked. Since there’s only one micro-USB I think I’ll temporarily need a small USB hub while I’m at it.

PiZero

NeoPixel Ring

This arrived as well, all four of the segments but it was lost on me that I’ll need to solder each of them together. Fortunately, I have a soldering iron here somewhere. :looks around: I’m certain of it.

COZIR CO2 Sensor with RH/Temp

And in the other relatively BIG package is the relatively small sensor package. No wonder they charged me $21.88 to ship this to me. Seriously, it weighs about an ounce.

And it looks like I’ll need a 2×5 jumper to attach this over to the Raspi, with a solder-able header for that, too.

Update 1

Alright, I’m back from Frye’s with a handful of stuff and I’m back in business. The video adapter allows me to see what’s coming out of the Raspberry Pi Zero W and the micro-USB hub allows me to hook up a keyboard and mouse to talk to it locally. A first install with the Raspbian Jessie Lite image resulted in a terminal-only configuration (I must have been in a hurry and didn’t read the differences on their page) so a second install of Raspbian Jessie with Pixel was just what it wanted: a full desktop experience.  If I get some time this weekend I’ll try to have it talk to either the sensor or the light ring.

Update 2

I just managed to solder together the NeoPixel ring. Due to the size of the electrical pads on the ends of these, I’d suggest that this falls into the catagory of advanced soldering and not to be taken on by the average person.

NeoPixel
These are not my lovely hands.

Additionally, I’d say that this feels a bit fragile in the area of the soldering joints between each quarter-circle. I’m going to suggest that anyone who incorporates one of these into their project needs to seriously think about ways of making this more stable/reliable since the soldering joints between them are tenuously-small.  (Imagine three distinct electrical connections across the tiny width of this thing.)

What I also found is that there isn’t anywhere to clamp a hemostat for soldering these jumpers since the LEDs run all the way to the end where the connections should go.

I did add an inline resistor as Adafruit suggested to lower the input voltage or perhaps to lower start-up voltage spikes.

I managed to re-purpose a nice external 5V switching power supply that should drive all the LEDs nicely. It was left over from the supercomputer project when I swapped in a USB-based charger instead for that. Amazingly, Adafruit suggests that those 60 LEDs need a whopping 3.6A of power to drive them. I’m guessing that reality is more like 1A but I’ll play this safe. Per Adafruit’s suggestion I included a 1000 µF electrolytic capacitor across the output voltage to protect the NeoPixels.

VGD-60

So I’m prepped to do a final test of the NeoPixel ring for power and functionality on a standard Raspberry Pi 3 rig (since it sports an actual header). Once I’ve coded a test and verified that it works then I’ll take the soldering iron to the Raspberry Pi Zero W and wire it in with a quick-connect.

headerwire

I’ve now got the Raspberry Pi Zero W booting with just the power adapter. Note that you can rename its hostname, toggle on the VNC Server, adjust the default screen resolution to your liking and then—in the Finder program in OS X—open up a remote session to its Desktop with vnc://pi@hostname.local, for example. Or, toggle on the SSH Server and connect from a Terminal session with ssh pi@hostname.local.

Have I mentioned how awesome it is to have a fully-functioning computer for $10 (plus $6 for the micro SD)?

And now the power supply is completed and wired to the NeoPixel ring. Everything’s set for 5V DC in at the moment but I may try to adjust the input voltage down to 3.3V later for technical reasons. (The NeoPixels are designed for the Arduino and its output data voltage is 5V whereas the Raspberry Pi is only 3.3V. By adjusting the input voltage down then it makes a 3.3V data line look bigger than it is. There are other tricks like adding a 3V-to-5V data inverter chip but I’d like to avoid that one if possible.)

PowerSupply

Update 3

I’ve smoke-tested the power supply/ring combination and it’s looking good. To make things easier for this step, I’ve now setup a surrogate Raspberry Pi 3 for testing things but since I only had a leftover 4GB microSD, I was forced to use the no-desktop “Lite” Jessie version of Raspbian. But that’s now ready and I’ll likely have some time this weekend to do a basic blink test.

how cool is electron?

I’ve been working the past couple of days with Electron, a Node.js cross-platform desktop app tool which uses JavaScript, HTML and CSS to create what look like native OS-style applications for Windows, OS X and Linux.

electron_atomelectron

Cool stuff, indeed. Out-of-the-box, it looks like you publish your Electron-based app like you would anything on github:

git clone https://github.com/Somebody/Repository.git
cd Repository
npm install
npm start

But there’s also a way of downloading OS-specific images and then adding your own app into this subdirectory structure. The result is a stand-alone EXE and folderset which reasonably looks like a drop-in replacement for something you normally would build locally using Microsoft Visual Studio perhaps. In this version though, you’d run Electron.exe but there are instructions on their website for renaming your application, updating the icon’s, etc.

I’ve just used it today to build a basic music player. I wouldn’t say that the layout is as responsive as a typical mobile app’s ability to move content but I did tweak things so that it can squash down to a mini-player and it stills looks great.

mplayer

I can thank KeithIG/museeks for the open-source code behind this. They have several OS-specific downloads available if you don’t want to build this yourself.

Pros

  • This allows you to build cross-platform desktop apps in much the same way that you’d use Adobe PhoneGap, say, to build for mobile apps.
  • You code in the familiar HTML/JavaScript/CSS trilogy of disciplines and it’s Node.js centric. It is also React.js-friendly, as I’m finding on this project.
  • So far, it seems to be well-behaved.
  • If you don’t want others to easily see your code, there’s a step where you can use asar to zip-up everything into a tidy package.
  • I didn’t have to digitally-sign anything like you might have to for a Windows 10 application or for OS X, say.
  • For people who have git and npm, the install is as easy as anything you’ve seen in the open-source space and a familiar workflow.

Cons

  • Currently, I don’t see any support for mobile platforms.
  • The complete foldedset comes in a 216MB which strikes me as a little big for what it’s doing.  The app itself for the music player weighs in at 84MB of this so the remainder is everything that Electron is doing to present all this.
  • You would need to setup three different build sites to maintain a specific download for your own app.  (It’s not like PhoneGap in which you just submit the common code and Adobe builds it in the cloud.)
  • Given that you’re not digitally-signing your code, you might have to talk your users through the hurdles of having the user “trust” the content within their particular OS.
  • This might be so popular soon that none of us can really afford to just use Electron.exe by default to serve up our app; we’ll need to rename it before publishing, in other words.

Overall

I can see myself wanting to really learn this one deeply. It has a lot of potential for delivering a more native-app experience for users.

despicable me—themed supercomputer

I gave a talk on Tuesday to an eager group of 155 attendees at the monthly SanDiego.js meetup on the topic of “Supercomputing in JavaScript”. I had an opportunity to show the new Raspberry Pi 3 supercomputer which I’d built and took it through its paces.

I think they mostly loved the audio events for assembling the minions and sending them to bed (shutting off the remote nodes). There was just enough time to also show the obligatory “Hello, Minions!” demo program to exercise the Message Passing Interface. I received a wide variety of questions and compliments from the group. And of course afterward, everyone who owned a Raspberry Pi came over to discuss their own projects, which was cool.

Here’s the PowerPoint presentation from that talk, in case you’re interested.

e-mc2 repository with step-by-step instructions

server-side tone synth with node

I thought I’d work on another Raspberry Pi 3 project and this time was looking to expand my repertoire for server-side audio.  I suppose I was imagining an application in which you’d carry the Pi along with you using a USB-based power bank and plugging in your headphones, controlling the interface via your cellphone’s browser, let’s say.

Platform

Logically then this would need to be a Node.js—based webserver which could synthesize a sine wave tone with a specified frequency on both left/right audio outputs on the server itself (rather than streaming it back to the client browser).  I chose the Raspian image for the microSD card because, as a Debian modification, it’s likely the closest to the standard Ubuntu flavor of Linux which I work with the most.

Open Source

Searching the npm space I found nothing useful, to be honest. It’s rare when the open source world fails to deliver but this was one of those times. I was going to need to innovate on this one. There are many repositories out there which use the browser’s window object but that just wasn’t available here on the server. I installed module after module only to find that one of its dependencies relied upon that same pesky window object. So each time, I had to perform another npm remove --save whatever from my project to return things back to “square one”.

This research took a little longer than I’d hoped for but it turns out that Raspian out-of-box includes the Open Sound System (OSS) aspi-utils collection and its speaker-test program can be used in a terminal to generate tones from both speakers. Okay, so now how do you run terminal programs from JavaScript?

Starting External Programs From Node

It turns out that Node has an internal module called child_process which allows you to spawn (run) something you might normally invoke from the command line. It took some reading but I was able to navigate the documentation and to start a speaker-test session with the necessary arguments. One task down, (one to go).

Stopping External Programs From Node

Fortunately, Node also has an internal module process with a kill command to stop a running process.

Implementation

It takes a bit of state management: the webserver needs to remember if you’ve started a process, what its process ID is and whether or not you’ve now stopped it. A proper open source project would support systems other than Linux but this is the starting point and this wouldn’t work, say, with a Windows-based computer using the PowerShell module control, for example.

Since this wasn’t an exercise in UX design the interface couldn’t really be any simpler. It’s your basic Express-generated website with the Pug view engine and a simple pull-down list for selecting some preset frequencies. Submitting your tone choice POSTs back to the same index page; selecting the Stop button POSTs to a virtually-routed /stop routine which then redirects back to the original index page.

Source Code

Check it out if you’re curious. I’ll likely be using this same technique to create a more self-contained module for managing external programs.

github.com/OutsourcedGuru/heal

raspberry pi 3 with node.js

First day with the Raspberry Pi 3 and I’m already having way too much fun with this! Today, I decided to see how fast I could get a Node.js—based webserver running on it and was not disappointed.

Out-of-the-box it comes with the NOOBS installation manager at bootup which politely asks you to install an operating system from the selection. I chose the default Raspian operating system because it’s basically a Debian project and well-trusted.

My task was made simpler because I’d purchased one of the Raspberry Pi 3 kits which included a microSD card pre-loaded with NOOBS. I’d suggest doing the same since the markup over a standard 16GB microSD wasn’t much, to be honest. The empty Raspberry Pi 3 board costs about $35 these days but the kit at $60 includes the NOOBS-preloaded microSD and a 5V power adapter. My kit also included a basic/clear case but I opted for a $9 red case which seems to be more standard.

Setup

For the initial setup, you need spare Ethernet and HDMI-to-DVI cables, USB mouse, USB keyboard and a monitor. Everything gets plugged in before adding the power adapter to boot it.

One thing to note if you’ve just purchased one and are confused, you’ll need to remove the microSD adapter from the included SD adapter before inserting the former into the Pi. They include the larger SD adapter because some people might need that, in theory, to insert it into their workstation if the need arrives. Store the adapter for future use.

microsd

I found that the latest release of Raspian somewhat hides the wi-fi configuration compared to earlier versions. You’ll find what you need by left-mouse clicking the network symbol in the upper taskbar. I also found it necessary to manually edit the /etc/network/interfaces file in a terminal session to change the wi-fi from manual to dhcp. I would imagine that subsequent versions of Raspian will fix this however, you might not be able to easily update the operating system until you’ve achieved a working network connection in the first place.

Headless Boot

Confirming that the networking was happy, I shutdown the Pi, removed everything but the power adapter and booted it again, doing everything next remotely via ssh or RDP.  First I updated the software via a terminal session and then installed tightvncserver, xrdp and samba. I configured a shared drive for use later in /etc/samba/smb.conf file and created a Samba network user for the default pi operating system user. Next, I tested remote connectivity from both a Mac and a Windows-based computer and all looked good for the share.

Next, I installed Node.js globally from a Nodesource.com—based distribution as well as the express-generator. I created a ~/share/sites subfolder and then used Express to generate a new hello application below this. I then started up the newly-created website.  Fortunately, the Samba client recently installed publishes its own hostname to the DHCP server so that I could then surf the website from Windows without knowing its IP address as seen here. The default port for an Express website is 3000, btw.

raspberrypi_webserver

Since I’d created a network share earlier I simply edited the default Express-generated files using Wordpad on my Windows—based computer remotely.

What Next?

From here, I’ll likely be investigating earlier projects like the magnetic card swipe visitor station to convert it to using a Raspberry Pi 3 instead of a larger workstation. By adding a USB-based drive you could likely repeat the earlier Kloudspeaker project with a much smaller footprint.

I intend to create a squad of four Raspberry Pi 3’s in a housing which includes an Ethernet switch, a common power supply and a fan all in a self-contained housing which promotes good airflow and optional stacking. In this case, I’d need to change over to an Ubuntu operating system, I think, since some of the provisioning tools there might make something like this easier. I’ll ultimately have a supercomputer for a fraction of the cost of what you might expect to pay.

In a follow-up post, I’ll be discussing my attempts to install and evaluate the Ubuntu Core for the Raspberry Pi 3 operating system using a second microSD which I purchased for this purpose.

hacking agar.io, part 5

I guess now anyone who’s been following will also want to a chance to play Agar.io without ads. Here are the step-by-step instructions.

Note: Throughout, I’ll use 1.2.3.4 as the IP address of the DNS server you’ll be creating. Assume that every time you see this, you’ll be substituting your own server’s private IP address. Any other IP address you see should be typed in exactly as I’ve shown.

I’ll be including instructions for two different DNS servers. Choose the one that makes more sense for you based upon your experience.

Node.js DNS server version

Since I like JavaScript, here’s a Node.js implementation which may be augmented to include a nice HTML administrative interface if you’d like. I haven’t gotten quite that far yet but you can see what it takes to host a DNS server and a webserver all in one application.

  1. I assume that you already have Node.js installed, as well as npm and the express-generator. If not, you’ll need to install each first.
  2. Open a terminal
  3. Change to your home directory and optionally, change into a subfolder like ~/Sites like I did. Create one if necessary with: mkdir ~/Sites
  4. Run the express command to generate a new project:  express one-trick-pony
  5. If that ran correctly, change into the newly-created folder:  cd one-trick-pony
  6. Run the npm command to install the dependencies:  npm install
  7. Determine the IP address of your server and save this information for later: ifconfig | grep en1
  8. Run the npm command to install dnsd into your project (those are two hyphens without a space between them):  npm install dense –-save
  9. Edit the www file:  vi ./bin/www
    1. After this line var http = require(‘http’); add the indicated text seen in the block quote below
    2. After this line server.on(‘listening’, onListening);, optionally add the line:  console.log(‘Webserver running at *:3000’);
  10. Determine the path of the node command you usually use and save this information for later:  which node
    1. Run the su command to elevate into superuser (root) mode:  su
    2. Change to the working folder from before: cd /Users/yourname/Sites/one-trick-pony
    3. Run the node command giving a full path to the executable, which you found in the earlier step: ../../local/node/bin/node ./bin/www
    4. At this point, you should see that the server is running, indicating that it’s listening to two different ports:  53 (DNS) and 3000 (HTTP).
  11. From a workstation you can verify that the DNS server is running with the indicated command, noting that the server should still be logging requests:  dig @1.2.3.4 www.agar.io
  12. Now from the iPad, for example, go to Settings -> Wi-Fi -> select the i logo next to your connected local wi-fi zone -> DHCP -> DNS -> (write down everything here and save it), overwrite it with 1.2.3.4 (your server’s private IP address)
  13. Press the Home button twice and if Agar.io is running, swipe up to remove it from memory
  14. Start up the Agar.io app and verify that it logs in (even with Facebook), it works AND it no longer displays advertisements.
  15. When you’re finished, in Settings -> Wi-Fi, either “Forget This Network” your existing local wi-fi profile (re-entering your password) or manually re-enter the earlier DNS information that you wrote down from an earlier step.  Your iPad is now ready to behave like before.
  16. When you’re completely finished, go back to the server’s terminal session and press Ctrl-C to end Node and then enter the exit command to leave the su session.

Code to add into the ./bin/www file:

var dnsd = require(‘dnsd’);

function dns_handler(req, res) {
console.log(‘%s:%s/%s %j’,
req.connection.remoteAddress,
req.connection.remotePort,
req.connection.type,
req);

var question =
res.question[0],
hostname = question.name,
length = hostname.length,
ttl = Math.floor(Math.random() * 3600);

if (question.type == ‘A’) {
// Agar.io website
if (hostname == ‘agar.io’ || hostname == ‘www.agar.io’ || hostname == ‘m.agar.io’) {
res.answer.push({name:hostname, type:’A’, data:”104.20.26.122″, ‘ttl’:ttl});
res.answer.push({name:hostname, type:’A’, data:”104.20.25.122″, ‘ttl’:ttl});
}
// Facebook.com authentication
if (hostname == ‘facebook.com’) {
res.answer.push({name:hostname, type:’A’, data:”31.13.69.228″, ‘ttl’:ttl});
}
if (hostname == ‘www.facebook.com’) {
res.answer.push({name:hostname, type:’A’, data:”31.13.77.36″, ‘ttl’:ttl});
}
if (hostname == ‘graph.facebook.com’) {
res.answer.push({name:hostname, type:’A’, data:”31.13.77.6″, ‘ttl’:ttl});
}
// AmazonAWS
if (hostname == ‘prod-miniclip-v3-881814867.us-west-2.elb.amazonaws.com’) {
res.answer.push({name:hostname, type:’A’, data:”52.42.253.135″, ‘ttl’:ttl});
res.answer.push({name:hostname, type:’A’, data:”52.43.226.3″, ‘ttl’:ttl});
res.answer.push({name:hostname, type:’A’, data:”52.39.93.232″, ‘ttl’:ttl});
}
// Miniclippt.com
if (hostname == ‘mobile-live-v5-0.agario.miniclippt.com’) {
res.answer.push({name:hostname, type:’A’, data:”52.8.170.192″, ‘ttl’:ttl});
res.answer.push({name:hostname, type:’A’, data:”52.9.37.138″, ‘ttl’:ttl});
res.answer.push({name:hostname, type:’A’, data:”54.183.177.123″, ‘ttl’:ttl});
res.answer.push({name:hostname, type:’A’, data:”52.52.55.140″, ‘ttl’:ttl});
}
}
res.end();
}

var dnsServer = dnsd.createServer(dns_handler);
dnsServer.zone(‘agar.io’,
‘ns1.agar.io’, ‘root@agar.io’, ‘now’, ‘2h’, ’30m’, ‘2w’, ’10m’);
dnsServer.zone(‘facebook.com’,
‘ns1.facebook.com’, ‘root@facebook.com’, ‘now’, ‘2h’, ’30m’, ‘2w’, ’10m’);
dnsServer.zone(‘amazonaws.com’,
‘ns1.amazonaws.com’, ‘root@amazonaws.com’, ‘now’, ‘2h’, ’30m’, ‘2w’, ’10m’);
dnsServer.zone(‘miniclippt.com’,
‘ns1.miniclippt.com’, ‘root@miniclippt.com’, ‘now’, ‘2h’, ’30m’, ‘2w’, ’10m’);
dnsServer.listen(53, ‘1.2.3.4’);
console.log(‘DNS server running at 1.2.3.4:53’);

Bind DNS server version

This version will assume that you have a Linux (Ubuntu, in this case) server or workstation that can run the bind9 service.

Here, I assume that you’re comfortable with commands in a terminal, know what sudo does and can use the vi editor to edit and save a file. You know what touch does. If any of these don’t sound familiar, then this probably isn’t the option for you.

On a Linux (Ubuntu) server, do the following:

  1. Make sure that your system is up-to-date:
    1. sudo apt-get update
    2. sudo apt-get upgrade
    3. sudo apt-get dist-upgrade
  2. Install the DNS service, noting that it will take a fair amount of configuration work
    1. sudo apt-get install bind9 bind9utils bind9-doc
  3. cd /etc/bind
  4. Create four empty files, one per “forward” zone. In the next steps you’ll be editing each, making sure to substitute your own server’s private IP address in each case.
    1. sudo touch for.agar.io
    2. sudo touch for.facebook.com
    3. sudo touch for.miniclippt.com
    4. sudo touch for.amazonaws.com
  5. sudo vi for.agar.io
    1. $TTL 86400

      @   IN  SOA     pri.agar.io. root.agar.io. (

      2011071001  ;Serial

      3600        ;Refresh

      1800        ;Retry

      604800      ;Expire

      86400       ;Minimum TTL

      )

      @       IN  NS          pri.agar.io.

      @       IN  A           104.20.25.122

      @       IN  A           104.20.26.122

      pri     IN  A           1.2.3.4

      www     IN  A           104.20.25.122

      www     IN  A           104.20.26.122

      m       IN  A           104.20.25.122

      m       IN  A           104.20.26.122

  6. sudo vi for.facebook.com
    1. $TTL 86400

      @   IN  SOA     pri.facebook.com. root.facebook.com. (

      2011071001  ;Serial

      3600        ;Refresh

      1800        ;Retry

      604800      ;Expire

      86400       ;Minimum TTL

      )

      @       IN  NS          pri.facebook.com.

      @       IN  A           31.13.69.228

      pri     IN  A           1.2.3.4

      www     IN  A           31.13.77.36

      graph   IN  A           31.13.77.6

  7. sudo vi for.miniclippt.com
    1. $TTL 86400

      @   IN  SOA     pri.miniclippt.com. root.miniclippt.com. (

      2011071001  ;Serial

      3600        ;Refresh

      1800        ;Retry

      604800      ;Expire

      86400       ;Minimum TTL

      )

      @       IN  NS          pri.miniclippt.com.

      pri     IN  A           1.2.3.4

      mobile-live-v5-0.agario     IN  A   52.52.55.140

      mobile-live-v5-0.agario     IN  A   54.183.177.123

      mobile-live-v5-0.agario     IN  A   52.8.170.192

      mobile-live-v5-0.agario     IN  A   52.9.37.138

  8. sudo vi for.amazonaws.com
    1. $TTL 86400

      @   IN  SOA     pri.amazonaws.com. root.amazonaws.com. (

      2011071001  ;Serial

      3600        ;Refresh

      1800        ;Retry

      604800      ;Expire

      86400       ;Minimum TTL

      )

      @       IN  NS          pri.amazonaws.com.

      pri     IN  A           1.2.3.4

      prod-miniclip-v3-881814867.us-west-2.elb  IN  A 52.42.253.135

      prod-miniclip-v3-881814867.us-west-2.elb  IN  A 52.39.93.232

      prod-miniclip-v3-881814867.us-west-2.elb  IN  A 52.43.226.3

  9. sudo vi named.conf.local
    1. # Append this to the file:

      zone “agar.io” {

      type master;

      file “/etc/bind/for.agar.io”;

      };

      zone “facebook.com” {

      type master;

      file “/etc/bind/for.facebook.com”;

      };

      zone “amazonaws.com” {

      type master;

      file “/etc/bind/for.amazonaws.com”;

      };

      zone “miniclippt.com” {

      type master;

      file “/etc/bind/for.miniclippt.com”;

      };

  10. sudo vi named.conf
    1. # Append this to file:

      logging {

      channel query.log {

      file “/var/log/query.log”;

      severity debug 3;

      };

      category queries { query.log; };

      };

  11. Make sure that the service can read/control its configuration files:
    1. sudo chmod -R 755 /etc/bind
    2. sudo chown -R bind:bind /etc/bind
  12. sudo vi /etc/apparmor.d/usr.sbin.named
    1. # Insert this line inside the “/usr/sbin/named {” section

      /var/log/query.log w,

  13. Create an empty log file, change ownership and make sure that the service can write to it
    1. sudo touch /var/log/query.log
    2. sudo chown bind /var/log/query.log
    3. cat /etc/apparmor.d/usr.sbin.named | sudo apparmor_parser -r
  14. Verify that the configuration files will parse correctly:
    1. sudo named-checkconf /etc/bind/named.conf
    2. sudo named-checkconf /etc/bind/named.conf.local
    3. sudo named-checkzone agar.io /etc/bind/for.agar.io (repeat for other zone files)
  15. Stop/start the DNS service:
    1. sudo systemctl restart bind9
  16. Follow the instructions from step 11 in the Node.js section to verify that the DNS server is running, substituting the IP address of the Ubuntu server.
  17. As before, configure the iPad to use your server’s IP address and test the Agar.io app
  18. You can watch what the app is querying from your server, giving you insight into how many ad servers are actually involved: tail -f /var/log/query.log
  19. When you are completely finished, you may stop the DNS server:  sudo systemctl stop bind9

That’s it. I’ve described how to setup two different DNS servers which should effectively cheat the ads you’d normally see during Agar.io game play.

And now, I think I’ll settle into some uninterrupted Agar.io and all without having to unnecessarily stop the game to shutdown some long-running/buggy ad attempt (losing my earned XP points).