iOS, Bluetooth Low Energy (BLE), CoreBluetooth and Swift – for noobs

This talk by Yoav Shwartz on the Realm.io site and this post by Ryan Jones on Medium are the best starting points I have come across.

The official documentation by Apple on CoreBluetooth is in Objective-C, which sucks because Objective-C looks like gibberish to me and i want to write Swift code. You can still read the docs though, they have listed best practices to work with BLE and CoreBluettoth.

You do need to have an iOS device in order to use CoreBlueooth, it is not supported in the Simulator. It was, originally, but they removed it after a year because BLE got more advanced and it was difficult to remove inconsistencies between Mac and iPhone implementations, or sumthin’ like that..

Look at other people’s Swift code dealing with CoreBluetooth on Github.

Install/Upgrade Node.js on Raspberry Pi (Raspbian Jessie)

tl;dr

Run this one command in Terminal:

This will automatically run a script i wrote that takes care of removing existing Node.js stuff, downloading and installing the latest version, and cleaning up afterwards. It also confirms the Node.js version once the installation is done.


The Node.js version that comes pre-installed with Raspbian Jessie is old. If you check the version using node -v, it’ll give you v0.10.29. The latest ARM-version of Node.js as of this writing is v4.2.1. Let’s remove the old and install the latest version available on our Raspberry Pi.

Remove existing Node.js

Run the following commands one by one:

Install latest Node.js ARM-release

Download:

Install:

That’s it, you now have the latest Node.js version available for the Raspberry Pi. You can confirm the version using node -v.

Re-install Node-RED

We uninstalled Node-RED as part of removing Node. If you want to re-install it, you can do so by running the following command:

source

Linux is 20 years old. The web is less than 7000 days old. Together they have changed human civilization more rapidly than any pair of invention in the history of the world.

Eben Moglen

Automated MySQL Backups to Amazon S3 with AutoMySQLBackups

This how-to will teach you how to take automated backups of all your MySQL databases and send them to Amazon S3.

Access (Logins) required

  1. root login for the server (sudo is required to run automysqlbackup, root is req. to add to root user’s cron)

  2. admin login for the mysql server (to provide for backup config file)

  3. IAM access keys to use with s3cmd (to configure s3cmd)

sudo is required to run the AutoMySQLBackup script, so when adding the command to cron, you’d need to add it to the root user’s cron (so that it runs successfully on set intervals without asking for a password).

Tools

  1. AutoMySQLBackup

  2. s3cmd

  3. SSH client (Terminal on Mac / putty on Windows)

Installing S3cmd on Debian

Check the Repos page for install on other systems.

  1. Import S3tools signing key:
    wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | sudo apt-key add -
  2. Add the repo to sources.list:
    sudo wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list
  3. Refresh package cache and install the newest s3cmd:
    sudo apt-get update && sudo apt-get install s3cmd

Run s3cmd --configure to add IAM access keys for Amazon S3.

Installing AutoMySQLBackup

Download and extract the latest tarball and run the install script.
1. Create a directory where you want to download and extract the AutoMySQLBackup file and move to that directory.
sudo mkdir /automysqlbackup && cd /automysqlbackup
2. Download automysqlbackup (v3.0_rc6) to the server. (Check Sourceforge for the latest version of AutoMySQLBackup. As of this writing v3.0_rc6 is the latest)
wget http://kaz.dl.sourceforge.net/project/automysqlbackup/AutoMySQLBackup/AutoMySQLBackup%20VER%203.0/automysqlbackup-v3.0_rc6.tar.gz

  1. Extraxt the downloaded tarball tar zxvf automysqlbackup-v3.0_rc6.tar.gz
  2. Run the installer ./install.sh

By default it will install the configuration files in /etc/automysqlbackup and the executable files in /usr/local/bin.

Configuring AutoMySQLBackup

Edit the /etc/automysqlbackup/myserver.conf file to customise your settings.
The myserver.conf file is VERY well documented, all you have to do is read and it’ll tell you what setting is supposed to do what and how you should configure it. You do not need to edit beyond the basics. What you generally edit are basic settings (username, passsword, host and backup directory), database settings (which ones to backups, which ones to not), rotation settings (when to backup), and notification settings (who and what to tell when a backup is complete).

Adding AutoMySQLBackup to Cron

Edit crontab sudo crontab -e and add the following at the end.

Linux Directory Structure

Home ~

~ represents the home directory of the user. ~ is the same as /username. All user specific files are saved here and the user has permission to write files by default in the home folder. Files in a user’s home directory can not be listed or viewed by other users.

Root /

/ is the root directory. Do not confuse it with /root. While / represents the root directory of the system, /root is the home directory for the root user. Do not save files in /.

/usr

/usr contains the user applications and all the files needed to run them like documents, images, source code and more. /usr is the biggest directory on the system so it is recommended to give it its own partition.

/etc

/etc stores your configuration files for the linux system and other software. Most of these are text files and can be tweaked using a text editor. For example, /etc/init which contains your boot procedures, can be easily tweaked in a text editor.

/dev

/dev has your device files that relate to your computer’s hardware components. For example, your keyboard and printer’s info is located in /dev/input.

/mnt

Similar to /dev, /mnt shows you your physical storage devices like hard drives, externals, dvd roms and such.

/lost+found

contains all your restored files that would have been lost after your system crashes or something strange happens to the mounted device. Kernel panics don’t mean you have to panic. Every partition has a lost+found directory.

Redirection in Linux

In Linux, everything is a file. Redirection comes in very handy because you can move data from a file to another file, from the resulting output of a command to a file. You can also redirect the output of one command and feed it as an input to another command.

Output >

The > symbol is used for redirecting output of one command to a new file or another command.

For example:

or

> writes the output. Meaning, if there is anything already in that file, or if there is an existing file with the same name, it’ll be overwritten. To append the redirected output at the end of a file, use >>.

For example:

Notes:

  • >& redirects the outputs of one file to another while < is the input redirection operator.
  • You can use error using its corresponding File Descriptor 2.

[Video] More about Redirection, Input, Output, Error Redirection and FD (File Descriptor)