Thursday, July 16, 2015

What To Do And How Much It Costs: Iceland

So you are planning an awesome trip to the best Scandinavian tourist economy, Iceland! Iceland was a fishing-and-sheep economy until recently, and then a banking economy until more recently, and then it realized that it is ideally positioned to have tourists stop over for up to seven days at a time on their way elsewhere.

The country - specifically the south-west of the country - has pivoted to embrace their geography. Iceland is very pretty, and full of tourists like you. No matter what you do, you will enjoy yourself. Also, it is very small. You can definitely drive the whole thing pretty easily.

Iceland is rural.
There are many pleasant guest-houses, but towns are largely functional and oriented to supporting hikers rather than walking-tourists. Iceland's big thing to see isn't a church or a museum, it is waterfalls and cliffs and glaciers. In June and July, it is also puffins.

Iceland is an island.
Things cost money here. Things cost approximately double in Iceland what they do anywhere else. Groceries are the exception - they cost about the same amount as they do in downtown Toronto. Everyone not from a major urban centre is in for some sticker-shock.

There are a lot of people in technical clothes, make yourself liked by wearing human clothes.
North Americans are not the only visitors. Stopovers apply from Europe, too, so you will see fit Germans and rangy Italians and everyone in between. They will be wearing technical gear. You will become fluent in the language of what technical gear belongs to which country. If you see fancy-ass North Face, it's American, and they are from New York.

What this means is that Iceland is a tourist economy and they have a high season, and you are probably going in the high season, and they are fully prepared for you to come and be entertained with beautiful rocks, so tip at coffee shops and bars and act like the natural resource extraction you are. But be human about it.

Blackout curtains are a lie.
If you're there in summer and you like dark, at all, you are shit out of luck, because that isn't a thing Iceland has in summer. It does have the sensation of endless afternoon naps, though. I love afternoon naps. I've heard some people wear eye masks, but they fall off your face at night.

Special tourist things are expensive and fun.
I paid to go snorkelling in Silfra and to ride an Icelandic horse at Laknes Horse Farm. I would like to see a lava tunnel, though I have not yet. These things are expensive. They are also 100% worthwhile. Most things have The Blue Lagoon attached as part of a package deal. Book up your Blue Lagoon overnight dates, as those book early, but it's fine with daytrippers.

Book everything in advance.
This is almost wholly a tourist and sometimes farming, fish-processing or aluminum-manufacture economy. Things book up with other tourists. Book in advance.

Fish soup and lamb.
If you find fish soup on the menu, order the fish soup, it is invariably excellent. There is a lot of fish soup. If fish soup is not to your taste, or you are allergic to shellfish which form the main broth for the soup, the other option is lamb, which is omnipresent and very good. If you are vegetarian, you're in for an expensive trip filled with self-cooked meals.

Booze
Hit the duty-free. Booze taxes in Iceland make Ontario and Pennsylvania feel like New Orleans or Montreal, in terms of price, and there is a 24% VAT on basically everything nice in the world. At Geysir you can buy a bottle - a bottle - of beer for $18.

Sheep come in groups of three.
Sheep are everywhere. They are behind your guest-house and on your plate. They hate people - as would you, if your interaction with people were death and forcible hair-cuts - and have a wicked turn of speed, so if you want a photo, be fast on the shutter. Do not resist the sheep. They are your destiny.

Reykjavik is tiny.
Reykjavik is tiny. Like, smaller than that tiny. Everything in Reykjavik is entirely walkable, and there are only perhaps six cabs in the city, total. Mostly, tours and transit to tours is provided by Reykjavik Excursions, who also run the Fly Bus from the (excellent) Keflavik airport for about $20 a ticket.

There is a very small shopping district, which is incredibly expensive, and has some okay gift-shops. You can get whatever you can find in the gift shops at the airport.

Reykjavik contains about one day's worth of entertainment. This is where the whale-watching tours go from, and the puffin tours, which are worthwhile mainly if you're not planning to go to other puffin cliffs.

Things To Do:
---- eat at Bergsson Mathes in downtown, get the lamb.
---- there is a happy-hour app, which you might use, because beer is $10-$15 a pint otherwise.
---- Fish restaurant is pretty good, also.
---- the good cafe is called Reykjavik Roasters.
---- buy some groceries from Bonus, it's much cheaper than eating out. Lamb is $14 for a leg.

Cars are how you will get around, unless you are a Tour Bus Person.
If you're comfortable with a stick shift, rent a yaris from Sadcars - about €110 for two days and ~$65 per half-tank of gas, and a half-tank is all you will really use in a day of driving. Gas was $2.25 a litre in July 2015. If you need an automatic, they're available, but cost more.

Get the gravel insurance. Icelandic gravel is unexpected, everywhere, and brutal.

Go to Vík
Vík is only 2.5 hours' drive from Reykjavik and there are a number of beautiful - like, unreasonably beautiful - waterfalls on the way, including Skogafoss. Also on the way is Dyrholæy, the big stone troll arch, and Reynisdrangar, which are a cathedral of columnar basalt cliffs. Vík itself is also beautiful, mainly for the famous black-sand beach.

Small Towns: Hveragerði of the Ground Farts.
On the way to Vík is Hveragerði, which has a hot river. You can take a hike up it and nap in the moss. The geothermal springs at Hveragerði are largely gone now - an earthquake did them in - but the volcanic molasses bread ("nature's own Dutch Oven") is quite good.

The Golden Circle
The Golden Circle is the equivalent of spending a day at the Louvre or going to a special exhibit at V&A elsewhere: beautiful, packed with tourists, has the best gift shops. You're already doing this, or you're not seeing the geysers. Stop in Alafoss on the way to Thingvellir and look at the actually-cool shops, particularly the knife-maker's.

Try the blue mint chip ice cream at Geysir. It's delicious even if you don't normally like mint.

Snæfellsnes Peninsula is where all your scenery ran away to.
There's very little in Snaefellsnes except horses, farms, horse-farms, rogue sheepsies, horses making more horses, and the best mountains and waterfalls anywhere. It is unreasonably pretty.

Borgarnes' Saga Museum has one of the better restaurants in west Iceland attached. The museum also contains a Scorn Pole (unsettling) and the saga of Eoill (ale, a big jerk). The restaurant's prix-fixe menu is great.

Further along by two hours is the small town home to the witchcraft museum, with famed latex model of necropants. Nearby is cafe Riis, which is pretty good. Get the fish soup. Always get the fish soup.

Basically, as long as you love road-trips and walking around near Scenery, you're set.
Enjoy your trip!

Thursday, July 24, 2014

AngularJS: Injecting HTML into ng-html-bind using $sce

HTML injection is one of those things that gets subject to Nerd Wars, and howling that directives should be used instead of things your designers will like (anything, anything at all, other than Directives).

Here's How To Inject HTML That You Have Coded By Hand Into Your Angular App:

.filter('makeMineATagInjection', ['$sce', function($sce){
        return function(message) {

            var hashCatch = new RegExp(/\S*#\S+/gi); 
            var tagIt = message.match(hashCatch);
            
            var msg = message.replace(hashCatch, "<span class='tag'>$&</span>");

            // $sce returns a string that plugs in to ng-bind-html
            return $sce.trustAsHtml(msg);
        };
}])

In your front-end HTML partial...
--> message.body is from your repeated values
--> the pipe means "filter this shit!

<p ng-bind-html="message.body | htmlize">
     this part here will be replaced with your sanitized HTML
</p>

That is actually all there is to it. There are a ton of very clear NERD WARS going on with this feature, which: I'm not super keen on HTML injection, but you know what? Hashtags are useful, get over it.

Monday, April 14, 2014

Raspberry Pi - init.d script to run a node app on boot using Forever

References
http://labs.telasocial.com/raspberry-nodejs-init.d/ << the big one.
http://blog.podrezo.com/init-d-startupshutdown-script-for-node-js-applications-via-forever/
https://www.exratione.com/2013/02/nodejs-and-forever-as-a-service-simple-upstart-and-init-scripts-for-ubuntu/
http://www.stuffaboutcode.com/2012/06/raspberry-pi-run-program-at-start-up.html

This should be easy, but it really, really isn't, primarily because it relies super heavily on your use of the correct directory structure, which is tricky when you're new to command-line computing.

In the end, I made this work by copying all my files to a directory in /home/pi (which, weirdly, displays as a simple directory when one types "ls" with no arguments) and then running it directly from there using a very, very basic init.d file. All of the above have many more options and commentary about what they're doing.

By convention, init.d scripts live in /etc/init.d. If there is something obviously wrong below, feel free to comment.

So!

  • Put your node application into the home directory, or somewhere you can reliably find it.
  • Make sure it actually boots when you run forever normally.
  • Then do this bit.

sudo nano /etc/init.d/MyScriptName

#!/bin/bash
### BEGIN INIT INFO
# Provides:             MyScriptName
# Required-Start:       $local_fs
# X-UnitedLinux-Should-Start:
# Required-Stop:        $local_fs
# X-UnitedLinux-Should-Stop:
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    MyScriptName does a thing
# Description:          MyScriptName does a longer thing
### END INIT INFO

case "$1" in
        start)
                su - pi -c "forever start --spinSleepTime 5000 --sourceDir=/home/pi/MyScriptDirectory MyScriptName.js"
                ;;
        stop)
                su - pi -c "forever stopall"
                forever stopall
                ;;
        restart)
                su - pi -c "forever restartall"
                forever restartall
                ;;
        status)
                su - pi -c "forever list"
                forever list
                ;;
esac

sudo update-rc.d MyScriptName defaults

This should add your file to the list of services that turn on at boot.

Notes
You do need to include the superuser command. It won't work properly without it.

There is some discussion in the reference pages of how forever handles services as versus how upstart handles services as versus how init.d handles things. The main point is that Forever will keep your app running, even though Node apps crash a lot, and node apps that serve gigantor quantities of static video files crash even more. I don't think there is a good way to serve huge amounts of video. YouTube is an illusion. Netflix ditto.

It happens.

Thursday, April 10, 2014

Raspberry Pi - Node App Host Setup List

This is a public aide-memoire for the build chain to host media-intensive Node applications on a build of debian, which happens to live on a Raspberry Pi.

I have been setting up many, many raspberry pi builds this month. Buy the 32Gb card.
  1. Buy a 32Gb< SDcard << what is this, 1999? 32Gb.
  2. Image with latest Wheezy.
  3. raspi-config:
    1. Expand the memory.
    2. Turn on SSH.
    3. Turn on "boot straight to desktop" if you plan to ever use a monitor. Ever.
      1. Set the memory split to half for the GPU.
    4. Set up your keyboard to your location.
    5. Reboot.
  4. sudo apt-get upgrade && sudo apt-get update
  5. sudo apt-get install usbmount rsync hostapd dnsmasq
  6. Configure internet and ethernet connection
    1. SSH/WiFi
    2. Captive Portal up at boot
  7. Install and test node/npm
    1. install Forever if you're going to have it serving a node app
  8. Take a backup.
After this, there are lots of places to go and things to add - HAProxy, for example, if you'd like to serve your app on a cluster from your house, or your actual node app. This utilities and chores list should help get everything running right at the start, though, and make it somewhat easier to get things running faster when they break.

Tuesday, April 8, 2014

Raspberry Pi - USB mount

This is relatively straightforward, but if you don't set up USBmount before setting up hostapd and dnsmasq and then disconnecting your pi from whatever internet it's feeding off of, it can be a pain in the ass to remember how to do it.

So: When setting up your raspberry pi, I highly recommend adding USBmount to your initial "I'm setting up a computer" boot list.

Mount Your USB Stick To Your Pi
How to Mount Your USB to Your Pi

Once you manage this part, you will start to have crazy warnings on boot, because it's unlikely that all of these instructions are going down smoothly. This will make the Pi look for your specific memory card the moment it starts up. It may get cranky when the card is not present, such as the nth time you've removed it to plug in a keyboard and work directly with the tiny computer.

Configuring Your Mount Drive
This bears some thinking about, because the /media/ folder is clearly for media, and you are instead choosing to run a program off of the drive. subnod.es suggests making it your www drive, for world wide web, but subnod.es is also running everything off the SD card. Pick your poison! I picked /media/usb because that's the same convention as is used by usbmount (see below).

For now, find your plugged-in USB gizmo by listing the the things plugged into dev:
sudo ls /dev/sd*

If you've been following along, yours is almost certainly named "/dev/sda1".

So make a directory for it to be addressed at:
sudo mkdir /mnt/USBSTICKNAME;

Then mount it to that directory
sudo mount -t vfat -o uid=pi,gid=pi /dev/sda1 /mnt/USBSTICKNAME/

Now you can poke around in your storage, which probably includes mainly your program.

sudo reboot

Which will kick you out of your Pi, so watch the lights on the darn thing until they're stable again, about two minutes, then:
ssh pi@[static ip]

Oh look. Your USB drive does not automatically mount at boot. Problem.

Automatically Boot Your USB Drive
How to Boot Mount External Memory

Find out the actual name of your external memory card:
ls -l /dev/disk/by-uuid

Write down the UUID of your USB stick.

Take a moment to marvel that your normal operating system is clever enough to do this by default, wonder how it manages that. Detour through:
sudo apt-get install usbmount
and then return, because whatever, do it by hand per computer, why not.

sudo chmod 775 /mnt/USBSTICKNAME
sudo sp /etc/fstab /etc/fstab.bak
sudo nano /etc/fstab

Add:
UUID=YOURUUID /mnt/USBSTICKNAME vfat rw,defaults 0 0

CTRL-X, Y to save, then
sudo reboot
ls /mnt/USBSTICKNAME

... which should now display the contents of your USB key when you go looking for it.


The Easy Way


On a fresh USB stick, type:
sudo apt-get install usbmount
sudo reboot

USBmount is a utility to manage plug'n'play USB memory. I recommend copying things your application is dependent on out to store locally anyway.


Storing all your node-called boot files in the same place
Although I have optimistically tried to make this a headless box, realistically, lots can go wrong with the SSHing process. You will probably eventually want a keyboard, and it is _much_ easier to store your access point as a single image per card.

To store your games locally, rather than in the USB stick:
sudo cp -ru /mnt/USBSTICKNAME /home/pi/YOURDIRECTORYNAME

Once this is working, it may be a good idea to back up your raspi to make sure you don't have to do this part again, as it can be time consuming. 

A word about cp - you should probably look up the arguments for using it. It is not a terribly friendly utility, as it doesn't tell you much of what's going on in the process, so if your process hangs, you'll be trying to check logs. rsync is supposedly better at this. 

Troubleshooting
Sometimes, halfway through your CP process, it will spontaneously declare your USB to be disconnected, or connected to a different port.

Speculation: this may have something to do with shoddy power consumption. the raspi really sips its amperage, and large copy processes pass a lot of heat through the USB.

So! This is why we cp -ru <- the u stands for update.

You can tell this has happened by touching the dev/sd* list, and noting the drive letter has changed to sdb1 or sdc1.  When this happens, I like to quit and reboot and try again. The raspi is flaky, just like its namesake. This is why, whenever you get something actually working, you should take a backup copy of your SD card image.

Monday, April 7, 2014

Raspberry Pi - Get Chromium --kiosk Running at Boot

Tutorials Examined
A kiosk browser on Webkit: https://github.com/pschultz/kiosk-browser
A method for booting to Webkit http://pikiosk.tumblr.com/post/38721623944/setup-raspberry-ssh-overclock-static-ip
Wired Watershed on NFS-Controlled Pi: http://blogs.wcode.org/2013/09/howto-boot-your-raspberry-pi-into-a-fullscreen-browser-kiosk/

ToDo
  • Fresh image your pi
    • Expand the memory
    • Turn on SSH
    • Set the memory split to half for the GPU.
    • Turn on "boot straight to desktop"
    • Set up your keyboard.
  • Do your internet/access setup
Required Software
sudo apt-get install chromium-browser x11-xserver-utils unclutter

chromium: the fat webkit browser. Possibly not essential with node-webkit, but might be! Hard to say.

x11-xserver-utils: This is the Unix GUI generation server.

unclutter: hides the mouse cursor after a period of inactivity. Possible to mod so only the highlighted areas of browser show?

Set Up the Webkit Boot
sudo nano /etc/xdg/lxsession/LXDE/autostart

@pcmanfm --desktop --profile LXDE
#@lxpanel --profile LXDE #turn off taskbar
#@xscreensaver -no-splash

## autoboot chromium after desktop load
@chromium-browser --kiosk http://yoursitehere

## turn off screensaver
@xset s off
@xset -dpms
@xset s noblank

Friday, April 4, 2014

Raspberry Pi - NodeJS and npm install -g

This is how you get node up on your pi. I recommend using an older build - the fresh ones (v0.10.19) have some difficulty grabbing packages.

Install NodeJS
This is pretty much from Josh on Design.
Create a directory for Node to live in:

sudo mkdir /opt/node

Get Node:
Please note that this can be node-v whatever as long as it ends in arm-pi.tar.gz.

wget http://nodejs.org/dist/v0.10.2/node-v0.10.2-linux-arm-pi.tar.gz
Observe the cute ASCII progress bar.

Unzip (desticky from tarball) it:
tar xvzf node-v0.10.2-linux-arm-pi.tar.gz 

Copy the contents of the newly unzipped folder and paste them to your new directory. This leaves a copy of the tar and a copy of the unzipped tar at their original locations. You can probably remove them using sudo rm when you're sure everything is where it should be.

sudo cp -r node-v0.10.2-linux-arm-pi/* /opt/node

Edit - or create - a .bash_profile file, which is a type of script that runs when you turn on the pi. In this case, it runs and tells Node that it exists on your computer, so that typing node runthisprogram will do something. What is a .bash_profile?

From your root directory:

sudo nano .bash_profile to open a new nano text file

PATH=$PATH:/opt/node/bin 
export PATH

Control-X, Y to save it.

Node lives in the /opt/node directory you created above. This adds the commands "node" and "npm" to what are called "environment variables," or "shit your computer understands when you type it at the terminal prompt." If you are curious, and god knows you must be to play with a raspi, you can type ls /opt/node/bin and see the little programs sitting there in their bin.

suod reboot and we'll see if we can get it to load things.

Test Node Out, Make Sure It Can Install Modules
How To Globally Install Node Modules Even Though The Raspi Hates That
Now to test that Node can get some packages from the internet itself. This is important, because we would like the raspi to be responsible for reading and serving web apps to the internet, and the web apps to live on a USB key where they can be comfortably added, removed, backed up, and yanked when we don't want them there any more. Also lost in the wash, if you go for a very tiny key.

I did this by reading a great deal, and deciding I wanted to use forever to monitor and run screenPerfect, the weird HTML5 video app I've been working on. I also want to use Nodemon to automatically check if any of my files have changed, and to restart the server when they have.

The latter is, in this situation, a Nice To Have, not a Have To Have. I don't expect to push many updates through the internet to my internet-disabled installation box, but you know what would be fun?

If I could do that. So why not throw in the kitchen sink.


To install a node package - or "module" - you type 
npm install PACKAGENAME

To install one globally, type
npm install PACKAGENAME -g

To crush the thing under your boot and force it to install properly, follow the instructions in the link:
sudo su
PATH=/opt/node/bin/:$PATH
npm install PACKAGENAME -g
exit
That would be: become a super user, set where the super user account looks for the command npm, install the package globally, then exit the superuser privilege set.

You should go ahead and
npm install forever -g
npm install nodemon -g

Per StackOverflow on running Nodemon and Forever together....
forever start /usr/local/bin/nodemon /path/to/YOURAPP.js

This should work to start and run your app, once you have your app, more or less forever. This is important, because your app will otherwise stream crash for no particular reason and you will not be able to work out how to fix it. Daemons are pretty great.

Notes On Patience
When I tried to install forever the first five times, it timed out, gave me a 404 error repeatedly, and declared I had insufficient permissions to do a global install no matter what. This is where computer science faith, confidence, and patience come in. When the install did not work for half an hour, I took a break, came back, and discovered that it installed the next day.

Try not to forget in this process that you're relying on a massive network of computers and people, and it's quite likely things are going to go wrong that are way out of your perception, much less control. Going for a break will help you keep patient and reduce the panic of typing what appears to be gibberish into a terminal all day long, in between crossing your fingers and sternly doubting the utility of your work.