How-to: Merge multiple RTF files into a single PDF

[easyreview title=”Complexity rating” icon=”geek” cat1title=”Level of experience required, to follow this how-to.” cat1detail=”Linux only. And newbies may find this tricky.” cat1rating=”3.5″ overall=”false”]

I recently needed to generate a large quantity of forms automatically (around 2,500 of them) and printing them. I was using PHP as the generator – it’s great at processing and transforming text. And my base (template) file was originally created as a Word document, converted to RTF for ease of processing.

There is no easy and free way of printing out 2,500 RTF files from Windows, not that I’ve been able to find. It didn’t make sense to pay for a £200 application for something that I do so infrequently. So here is my (free) approach.

Make Linux do the hard work

I’m using an Ubuntu virtual machine for this how-to, but you can use almost any distribution, with a little modification of the steps below. When it comes to command line or scripted activities (which this tutorial lends itself to), Linux/Unix is simply more mature than Windows. This means that someone, somewhere has probably already created a tool for whatever activity you’re thinking of and moreover, made that tool free.

Converting to PDF: Ted

Ted is a fairly full-featured text processor for Linux. We’ll just be using some of Ted’s command line wizardry today.

Installing Ted

Ted logoYou can download a Ted package here. I’m installing this on an Ubuntu 12.04.1 machine so I chose this package: ubuntu12041:ted-2.23-amd64.deb.

I keep all third party packages I install in a directory, /root/installed-packages, for future reference. So this is what I did, from a command line (SSH connection). First, I know that Ted has some dependencies, so I dealt with those:

apt-get update
apt-get install libxpm4 libtiff4 libgtk2.0-0 libpaper1
apt-get -f install

Then downloaded and install Ted:

wget http://ftp.nluug.nl/pub/editors/ted/ubuntu12041:ted-2.23-amd64.deb
dpkg -i ubuntu12041\:ted-2.23-amd64.deb

Combining files: pdfmerge

Abiding by the principle of “do one thing well”, guess what pdfmerge does?

Installing pdfmerge

If you’re using a RedHat-derived distribution, you’re in luck, there’s a pre-built package. If you’re using Ubuntu though, here goes. Download the source [iwrtooltip title=”a compressed archive of files”]tarball[/iwrtooltip] from here. Again, I’m starting in my directory /root/installed-packages.

wget http://dmaphy.github.com/pdfmerge/pdfmerge-1.0.4.tar.bz2
tar jxf pdfmerge-1.0.4.tar.bz2
cp pdfmerge-1.0.4/pdfmerge /usr/local/bin
rm -rf pdfmerge-1.0.4

Put it all together

Now the utilities are installed, you can run the following simple bash script to convert your individual RTF files into PDFs, then merge them all into a single PDF. I put the RTF files in one directory, then the PDF into the directory above it in the directory tree. We use a script that is bundled with Ted – you may need to check the precise location.

for filename in ./*.rtf
do
/usr/share/Ted/examples/rtf2pdf.sh $filename
done;
pdfmerge *.pdf ../all.pdf

Acknowledgements

Thanks to Mark de Does for Ted and to Dominic Hopf for pdfmerge.

Review: SoundWave SW100 Portable Bluetooth Speaker

As for many other people, my phone has become my go-to device for all my mobile entertainment needs. I currently have a Samsung Galaxy Note 2 (yeah, the one with the ludicrously large screen), so it’s great for anything from internet browsing to watching films in HD quality. I also use it as an MP3 player and for listening to podcasts and audiobooks.

I recently started looking around for a portable speaker that I could take on my occasional travels and, not to put too fine a point on it, use in the bathroom. Surely I’m not the only one that likes to listen to audio books while I shower?

The Note 2 isn’t, er, noted for its high quality speakers. Very few smartphone manufacturers have been able to complete with Apple on this front. But even the mighty built-in speakers of an iPhone struggle to compete with the noise of my geyser-like shower or electric shaver.

As Dummy will tell you, I’m a bit of a tightwad when it comes to my technology purchases, so I was looking for a device that could combine the impossible requirements of sound quality, power and cheapness. I wanted the convenience of connecting by Bluetooth, with the option of a 3.5mm socket for greater flexibility.

Having considered many products and read a lot of reviews, the device I settled for was this, the SoundWave SW100:

Rear view
Rear view

Here are some vital statistics:

  • Small – about three inches tall
  • Reasonably light – I haven’t put it on the scales, but it feels about the same weight as my Note 2 + case
  • Loud – I can’t find any official information on wattage, but when I turned it up to max in my small kitchen, it was louder than I could tolerate; at that point, there was some mild distortion
  • Built-in microphone – theoretically you can therefore use this device for conference calls; I have not tried this, but for the sound alone it can only be better than putting your phone into speaker mode
  • A claimed 10 hours music/talk time
  • A claimed 800 hours standby time – I’m not sure what use this figure is though; I’ll either be using it or charging it

Out of the box, the speaker was fully charged in less than an hour. It comes with a microUSB cable for this purpose. For my first trial, I took it into my company’s noisy server room. About 80% volume was sufficient to hear music clearly and without distortion, over the cacophony of fans and aircon.

It paired over Bluetooth without fuss. I have noticed the occasional blip when playing through Bluetooth, but I think this is more likely to be down to the phone (of which I demand a lot!) than to the speaker. In any event, you can use a 3.5mm audio cable (supplied) if you prefer.

SoundWave SW100 and matThe speaker has a non-slip base, great for most surfaces. The manufacturers have thoughtfully included an additional non-slip mat, making the speaker very unlikely to budge during normal usage. The non-slip mat also slightly neutralises the effect of resonance transmitted through the surface on which you place the speaker. Unless you’re an audiophile (I confess I’m not), this probably won’t mean a lot, but for some, it will be important.

For the size of the speaker, I was impressed by the bass response. In fact this was one of the reasons I bought the speaker – to improve bass experience, without having to lug around a sub woofer and without having to spend thousands on a high-end miniaturised speaker system.

Build quality is good. The case is mainly brushed aluminium, and not unattractive. It passed the spouse test; no exclamations of,”Oh how hideous! What horrendous technological monstrosity is that?!”

SoundWave SW100 mic and buttonThere are two controls. First, there’s a button labelled with a phone symbol, for answering calls and setting up the initial pairing. Secondly there’s an on-off switch. There’s an LED to indicate connection status and charging status and there’s a microphone port along with the USB charging port and 3.5mm audio socket.

I paid £20 for the speaker. Although at one time it was available for less, it is still a bargain at this price. It receives favourable reviews (wherever you look) and I can only confirm what other reviewers are saying. Well worth the money, especially when you consider you can pay four times the price for a product that may have a pretty label but is otherwise no better.

Entirely up to you, but you can pick one up from Amazon here, or from eBay,
[easyreview title=”Geek rating” icon=”geek” cat1title=”Ease of use” cat1detail=”BlueTooth synced very easily. There’s an off/off switch. Simples.” cat1rating=”5″ cat2title=”Features” cat2detail=”It has no on-board track control buttons and lacks the ability to daisy-chain other speakers. Higher-quality speakers may handle bass better, but that’s being very nitpicking.” cat2rating=”3.5″ cat3title=”Value for money” cat3detail=”It competes well with speakers three times its price.” cat3rating=”4.5″ cat4title=”Build Quality” cat4detail=”Very solid. Has survived several downward lunges!” cat4rating=”4.5″ summary=”If you want a portable speaker, on the go, don’t mind that the output is mono, and don’t expect the sound to fill a concert hall, this is the device for you. Highly recommended.”]


How-to: Rooting the Nook Simple Touch

UPDATE: If you’re looking for a super-cheap, colour, Android tablet, you might like to know that Amazon has recently slashed the price of the 7″ Kindle Fire to £99. Find out more here.

[easyreview title=”Complexity rating” icon=”geek” cat1title=”Level of experience required, to follow this how-to.” cat1detail=”The latest rooting process is fairly straightforward, if you’re patient and pay attention to all the details.” cat1rating=”1″ overall=”false”]Nook browsing webAt the time of writing, the Nook Simple Touch is still on offer with Barnes & Noble, but out of stock. Which is to say, it’s dirt cheap, but ner ner ne ner nerrr, you can’t have one…

If you were one of the lucky ones to pick up the reduced-price tablet before stocks ran out, or if you already had one of these, you might be interested to know that you can unleash some of its secret powers through a process called “rooting”. The tablet is based on the well-known operating system Android and has hidden talents that Barnes & Noble would rather you didn’t find out about (like loading a Kindle app onto the tablet for example – gasp)!

When my Nook arrived, it was running firmware version 1.2.0. The Nook has since been silently upgraded by Barnes & Noble to 1.2.1. I mention this because manufacturers tend not to like having their devices’ security bypassed (I’m looking at you, Apple). It’s entirely possible that one day B&N will release an upgrade that makes it significantly harder to root the device. Thankfully, with all versions up to 1.2.1, it’s still possible.

Before you proceed any further, there are a few points to highlight. I apologise for the extreme emphasis, but they’re such important points, I didn’t want you to overlook them.

  1. Rooting your Nook will almost certainly void your warranty. Don’t rely on the possibility that you may be able to reverse the rooting process. By the time you need to call on the warranty, your device may be in such a state that you’re not able to “unroot”. Only root your device if you’re satisfied you can afford to lose the money you just spent on the Nook.
  2. Rooting your Nook may “brick” it, that is, render it inoperable. It’s rare, but it can happen. Once this has happened, you can still use it as a rectangular frisbee, if you wish.
  3. You must, repeat must go through the Barnes & Noble registration process before you attempt to root the NST. Follow the wizards and make sure your Barnes & Noble store is working. Don’t skip this step.
  4. Nook Devs is a great site to visit if you want to know a lot more about this process.

Pre-requisites

You’ll need:

Rooting

  1. This process wipes the MicroSD card you’ll be using. I had already copied some files to my card, so I copied them back to my laptop for now. You may wish to do the same, or you can use a dedicated card for the rooting process.
  2. Download and unzip NookManager. This will leave you with a single file, NookManager.img.
  3. Download and unzip Win32DiskImager.
  4. Insert your MicroSD card and ensure it’s mounted (visible in Explorer).
  5. Run Win32DiskImager.exe. It will probably request elevated permissions. The interface might take a while to appear. Be patient. You’ll eventually see something like this:
    Win32DiskImager
  6. Use the folder icon to browse to the location of NookManager.img. Make sure the “Device” selection is pointing to your mounted MicroSD card.
  7. Make triply sure you’re writing to the correct device and click the “Write” button. Heed the warning and if you’re ready to proceed, click “Yes”. In a little less than 10 seconds, the writing process should be complete.
  8. Unmount the MicroSD card from your computer, but don’t install it in the Nook yet.
  9. Unlock your Nook, then power it down, by holding in the power button for three seconds, then tapping the “Power off” option.
  10. Insert the MicroSD into the Nook, and power it up.
  11. You should see the NookManager loading screen:
    Nook Manager Loading Screen
  12. For this procedure, it really makes little difference whether or not you start with wireless capability. It’s quicker if you don’t:
    NookManager start wireless
  13. When you arrive at the Main Menu, click the button next to “Root->”:
    NookManager root
  14. Next, click the button next to “Root my device->”:
    NookManager root my device
  15. If you’re an Olympic swimmer, you can hold your breath during the next bit:
    NookManager rooting in progress
  16. There’s no progress bar. After a while, you should see the following (note the word “Success!” at the bottom):
    NookManager rooted
  17. Click “Back” then “Exit”:
    NookManager exit
  18. Eject your MicroSD card when prompted:
    NookManager eject
  19. You can and should use NookManager to take a backup during this process. I didn’t, because I didn’t have a spare MicroSD card to dedicate to backups. I possibly need to research this area more. Backups are good. I, obviously, am a Bad Boy. I tried taking a backup (the process took about 15 minutes), but then I wiped the card for other use. Go me.
  20. When first unlocking, post-root, you’ll be presented with a slightly cryptic message: “Complete action using Home/ReLaunch”:
    Nook Complete action using
    The checkbox, when selected, means “Always” do this. Just choose whichever you want at the time and leave the checkbox unticked. “Home” takes you to the Barnes & Noble interface. “ReLaunch” takes you to an Android interface designed for the Nook. You’ll see these this choices again, whenever you press the Nook button, followed by the “home” icon.
  21. Hang onto your NookManager MicroSD card for now. You’ll need it for installing Google apps (next section).

If your first attempt at rooting didn’t work, don’t panic. You can safely repeat this process as many times as you like.

Installing Google Apps

If you still have your NookManager-prepared MicroSD card, you may wish to install some Google apps. This gives you Google Market (the earlier version of the Play Store), Gmail, Calendar and a few other bits and bobs.

  1. Download NGTAppsAttack. The version number you download should be the same as the version of NookManager you’re using.
  2. There are quite a few “gotchas” with this process. I strongly recommend you follow the instructions at the start of this thread at XDA Developers. In particular, note the comment, “Once your Nook has booted you need to follow the next steps without delay. You don’t need to rush but you need to move through them without interruption.”

Despite what I’ve read elsewhere about needing to use a Google account ending in “@gmail.com”. this worked fine with my Google Apps Domain account (which I use for my Android phones). You can now start installing apps using the Google Play web interface (from your computer), but bear in mind that many apps won’t be compatible with the Nook‘s old version of Android.

At this stage, I completely wiped the SD card, removing all existing partitions, using Parted Magic.

Apps to install

Nook with Play Store

Since the Nook is running Android 2.1 that’s a significant limitation. All apps to be installed must support 2.1. Also, the Nook has limited memory, so RAM-hungry apps won’t run at all.

I’d recommend the following apps:

  • The current version of Opera Mobile seems to be about the best web browser for the Nook (better than Opera Mini). But remember that web browsing with an e-ink display is never going to be slick.
  • For reading comics and certain magazines, Perfect Viewer is great. The last version to support Android 2.1 was 1.9.2.2. You can download that direct to your Nook, by using Opera to browse here. In case you’re hand-typing URLs, here’s a shortened URL for your convenience: http://is.gd/m6eSSk
  • If you install the Perfect Viewer PDF Plugin, you can also read PDFs, with full zoom control. The current version of the plugin (1.1.2) is compatible with the Nook, so you can install it via the web.
  • Version 2.1.0 of Aldiko Standard is compatible with the Nook and enables you to read ebooks in many formats other than epub. Download the APK here. Shortcode: http://is.gd/O4j6Wz
  • To give you access to Amazon’s catalogue, install the Android Kindle app. You can install the current version via the. Oh, and yes: ha ha ha.
  • Dropbox seems to me to be of slightly limited usefulness, except maybe for conveniently transferring the odd file to the device, but you can install the current version via the web if you’re so inclined.
  • The current version of Fora Dictionary works well. You’ll probably want to install one of the dictionary packages too.


Conclusion

There you have it. At no extra cost (except a bit of time), you’ve flung wide open the capabilities of your eReader. As long as you continue to bear in mind the limitations (and advantages) of e-ink technology, you can’t fail to be impressed by this fantastic device.

Review: Basic XL Noiseless USB Desktop Fan

£5.99 from Amazon.

Noiseless USB Desktop Fan

A simple USB powered fan that claims to be silent.

It’s cheap and it’s cheerful and barely worth a review you might think. I work in a very warm office though and have bought a number of these at varying prices; some have been very poor indeed!

I bought this one from Amazon and it was free postage so all in all a cheap little thing to buy. As you can see from the picture, it looks kinda cool and in the flesh it is a nice little compact fan that’s about 16cm high, 14cm across and 9cm deep. It has a generous USB cable and looks good on my desk.

The first thing you will notice when you take it out of the box is it’s quite flimsy. Whilst the black gloss plastic looks cool, it bends and flexes just getting it out of the box. It is very light though.

Having said that about its general quality, it has 3 foam feet to reduce any vibration and for what it does and how small it is, I don’t think it warranted being constructed of anything more robust. Although it feels a bit flimsy it does seem to be correctly formed and engineered as a product.Noiseless USB Desktop Fan

Plugging it in, it instantly kicks into life with no fuss and has a good quality on/off switch on the back of the main fan body. I wouldn’t say it’s silent but it is very quiet and not a distraction at all to have on my desk.

So then, how does it actually perform? I work in a warm office and on occasions the air con just doesn’t cut it and I need a bit of a breeze to circulate the air without blasting papers off my desk. This fan is no tornado, far from it, and I’ve found it needs to be positioned within approximately 60cm of my face for me to get any kind of effective breeze from it. But do you know what? That’s all it needs to do. It’s small, great looking, very quiet and circulates the air around me nicely if positioned relatively closely. All in all, a great buy and excellent value for money if you remember that it is just a mini USB fan.

[easyreview title=”Dummy rating” icon=”dummy” cat1title=”Ease of use” cat1detail=”Plug it in and away you go. Simple as can be.” cat1rating=”4″ cat2title=”Features” cat2detail=”Maybe would have benefited from a 2nd speed.” cat2rating=”3.5″ cat3title=”Value for money” cat3detail=”At £5.99 delivered it’s decent value.” cat3rating=”4″ cat4title=”Build Quality” cat4detail=”I guess it’s sufficient for what it is but could have been a little heavier.” cat4rating=”3.5″ summary=”A good cheap price for a an above average product that does exactly what it says on the tin.”]


Free, unlimited Dropbox alternative: BitTorrent Sync

BitTorrent SyncUnless you’ve been living in a cave for the last five years, you’ll have heard of cloud sync poster child Dropbox. Dropbox has many flaws, but its great strength is how simple it is to use (my most inept users can manage it).

When you read elsewhere about the weaknesses of Dropbox, privacy seems to be the big one. Your files are stored “in the cloud”. This doesn’t particularly trouble me. Yes, Dropbox has my stuff, but the chances are that Dropbox’s security measures are better than my own. Between my laptop being hacked/stolen and Dropbox being hacked(/stolen?!), my money’s on my laptop. (I use TrueCrypt to encrypt my laptop’s hard drive, as you should by the way, but that’s a different story.) Anyway, any squeamishness we have about cloud storage is likely to die away in the near future, when it’s no longer quite so new and scary.

Of course there are lots of companies on the cloud storage bandwagon, big names and small. There are Google Drive, Microsoft SkyDrive, CrashPlan, Mozy and so on. Typical features include:

  • Mobile apps
  • Entry-level free option
  • File version revision/undelete

This is different. From the company that brings you the controversial peer-to-peer file sharing system and the popular BitTorrent client, µTorrent, comes a new “cloud-less” file sync technology, BitTorrent Sync. The principle of BitTorrent sync is that you use the efficient BitTorrent protocol to distribute your own files privately amongst approved devices.

This year, BT Sync has been in private “alpha” (software in heavy testing, likely to contain bugs, which may be serious). Last week, the public alpha was released. It’s currently available for Windows, Mac and Linux.

The Windows interface is pretty minimal at the moment:

BT Sync Windows

The web interface for the Linux version is more polished:

BitTorrent Sync Linux

During the private alpha stage, I tried syncing between a Windows 7 laptop and a Linux server. Shortly after this, the server suffered a catastrophic disk failure. Coincidence? Not entirely, I suspect. There may be some low-level disk calls that overtaxed drives that were already heading towards the end of their life. Nevertheless, it’s a reminder: this is alpha (experimental) software; be careful.

BT Sync has quite a few limitations:

  • It’s still in alpha state, which means it is liable to eat your data, your hard drive and your children’s pet rabbit.
  • There are no mobile applications yet.
  • No progress indicators within Windows, just an irritating balloon tip.
  • Since there is no central cloud, the devices must be online simultaneously, to perform sync.
  • For the same reason, you can’t download files via the web.
  • Other than creating a folder specifically for the purpose, there’s no option to “share” a single file.
  • No versioning – no backup or undelete facility outside any provided by your operating system.

Despite all this, there are some pretty compelling reasons for using it:

  • There are absolutely no limits. Unlimited file size, unlimited storage, unlimited bandwidth, etc. Of course you will still be limited by other factors – the size of your hard drive and the amount of monthly bandwidth you’re allocated by your ISP.
  • Efficiency. This is not the place to discuss BitTorrent generally, but the more people sharing the files, the better. All connected devices, while online, can participate in the synchronisation process.
  • Privacy. No third party holds your data. Central systems facilitate the peer-to-peer connection, but do not take their own copies of files.
  • Security. The data is encrypted before transmission and only accessible using a “shared secret”.

BitTorrent Sync has an ace up its sleeve. It can be installed on several different NAS boxes, from the likes of Synology, QNAP, Iomega, etc. This is where I can see BT Sync excelling. Want an entirely private, shared data store for remote office workers, but don’t want to invest in high-end storage systems? Give them all a NAS box with BT Sync installed. Want to set up off-site backup for your files at home? Enter into a reciprocal arrangement with a friend, using NAS boxes, where you host each other’s backup files. Want to set up a sprawling hydra-like network of anarchic file storage for your clandestine underground organisation? You get the idea…

Download

So, having read all my caveats above, you still want to give this a whirl? Go ahead, don your crash helmet and download the sucker.

News: Free, unlimited Dropbox alternative: BitTorrent Sync

UPDATE: if the process below seems like a bit too much hassle, we would currently recommend Tresorit. It is similar to DropBox, with the added advantage that your data is encrypted on Tresorit’s servers. In other words, unlike with DropBox, if their servers are compromised, any data recovered would still have to be decrypted before an attacker could access it. They’re so confident no one can get your data that they’ve offered a bounty to anyone who can break into their systems.

BitTorrent SyncUnless you’ve been living in a cave for the last five years, you’ll have heard of cloud sync poster child Dropbox. Dropbox has many flaws, but its great strength is how simple it is to use (my most inept users can manage it).

When you read elsewhere about the weaknesses of Dropbox, privacy seems to be the big one. Your files are stored “in the cloud”. This doesn’t particularly trouble me. Yes, Dropbox has my stuff, but the chances are that Dropbox’s security measures are better than my own. Between my laptop being hacked/stolen and Dropbox being hacked(/stolen?!), my money’s on my laptop. (I use TrueCrypt to encrypt my laptop’s hard drive, as you should by the way, but that’s a different story.) Anyway, any squeamishness we have about cloud storage is likely to die away in the near future, when it’s no longer quite so new and scary.

Of course there are lots of companies on the cloud storage bandwagon, big names and small. There are Google Drive, Microsoft SkyDrive, Cubby (from LogMeIn), Mozy and so on. Typical features include:

  • Mobile apps
  • Entry-level free option
  • File version revision/undelete

This is different. From the company that brings you the controversial peer-to-peer file sharing system and the popular BitTorrent client, µTorrent, comes a new “cloud-less” file sync technology, BitTorrent Sync. The principle of BitTorrent sync is that you use the efficient BitTorrent protocol to distribute your own files privately amongst approved devices.

This year, BT Sync has been in private “alpha” (software in heavy testing, likely to contain bugs, which may be serious). Last week, the public alpha was released. It’s currently available for Windows, Mac and Linux.

The Windows interface is pretty minimal at the moment:

BTSync Windows

The web interface for the Linux version is more polished:

BitTorrent Sync Linux Web Interface

During the private alpha stage, I tried syncing between a Windows 7 laptop and a Linux server. Shortly after this, the server suffered a catastrophic disk failure. Coincidence? Not entirely, I suspect. There may be some low-level disk calls that overtaxed drives that were already heading towards the end of their life. Nevertheless, it’s a reminder: this is alpha (experimental) software; be careful.

BT Sync has quite a few limitations:

  • It’s still in alpha state, which means it is liable to eat your data, your hard drive and your children’s pet rabbit.
  • There are no mobile applications yet.
  • No progress indicators within Windows, just an irritating balloon tip.
  • Since there is no central cloud, the devices must be online simultaneously, to perform sync.
  • For the same reason, you can’t download files via the web.
  • Other than creating a folder specifically for the purpose, there’s no option to “share” a single file.
  • No versioning – no backup or undelete facility outside any provided by your operating system.

Despite all this, there are some pretty compelling reasons for using it:

  • There are absolutely no limits. Unlimited file size, unlimited storage, unlimited bandwidth, etc. Of course you will still be limited by other factors – the size of your hard drive and the amount of monthly bandwidth you’re allocated by your ISP.
  • Efficiency. This is not the place to discuss BitTorrent generally, but the more people sharing the files, the better. All connected devices, while online, can participate in the synchronisation process.
  • Privacy. No third party holds your data. Central systems facilitate the peer-to-peer connection, but do not take their own copies of files.
  • Security. The data is encrypted before transmission and only accessible using a “shared secret”.


BitTorrent Sync has an ace up its sleeve. It can be installed on several different NAS boxes, from the likes of Synology, QNAP, Iomega, etc. This is where I can see BT Sync excelling. Want an entirely private, shared data store for remote office workers, but don’t want to invest in high-end storage systems? Give them all a NAS box with BT Sync installed. Want to set up off-site backup for your files at home? Enter into a reciprocal arrangement with a friend, using NAS boxes, where you host each other’s backup files. Want to set up a sprawling hydra-like network of anarchic file storage for your clandestine underground organisation? You get the idea…

Conclusion

I shared this write-up with Dummy and he gave me a vacant look. “What is it?” he said. Fair comment; it’s a very clever bit of software. But in a nutshell, it gives you a completely private “Dropbox”. You share your folder with your friends and they all automatically get a copy of everything in that folder. You can configure it so that any changes they make are distributed throughout all copies. You can use it as a “set it and forget it” off-site backup – say with a home PC and a work PC. It’s usefulness is limited only by your imagination.

So, having read all my caveats above, you still want to give this a whirl? Go ahead, don your crash helmet and download the sucker.

Easy Password-less SSH logins on Linux

ssh-copy-idI’m storing this as an aide memoire, really, but it may help you too.

Let’s say we have two systems, System_From and System_To. And two users, User_From and User_To. The objective is: log on to System_To as User_To, from System_From as User_From.

The steps

1. One-time key generation for User_From

On System_From, while logged on as User_From, proceed as follows:

User_From@System_From:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/User_From/.ssh/id_rsa):[hit enter]
Enter passphrase (empty for no passphrase):[hit enter]
Enter same passphrase again:[hit enter]
Your identification has been saved in /home/User_From/.ssh/id_rsa.
Your public key has been saved in /home/User_From/.ssh/id_rsa.pub.
The key fingerprint is:
be:e8:98:4a:26:1e:9b:ed:78:a7:e7:fe:d8:9d:3c:6d User_From@System_From
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|  E              |
|                 |
|               Q |
|        S        |
|       .         |
|oo      o     o  |
|+.Bo8ooo.E       |
| BOB++o++        |
+-----------------+

Note: if you use anything other than an empty passphrase, you will need to enter the passphrase each time you log on, which sort of defeats the object of this exercise!

This creates two files: id_rsa and id_rsa.pub. The private key, id_rsa, must always be kept secret. Your system should have marked it read/write for the owner only. The public key, id_rsa.pub is safe to copy to destination systems (see next section).

2. Copy the public key to System_To

OpenSSH comes with a handy script for copying the public key to the remote host (System_To, in this instance): ssh-copy-id. Use it like this, at the system you’re connecting from:

User_From@System_from:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub User_To@System_To
User_To@System_To's password:[type User_To's password and hit enter]
Now try logging into the machine, with "ssh 'User_To@System_To'", and check in:

  ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

If you’re connecting to SSH on a custom port, the command is thus:

ssh-copy-id -i ~/.ssh/id_rsa.pub "User_To@System_To -p custom#"

Repeat this step for all remote hosts to which you intend to connect.

3. Log in to System_To

Now, when you issue the command ssh System_To, you will be logged in straight away, with no password prompt.

SOLVED: “Access is denied, unable to remove” when deleting printer

It’s amazing to see that many years after I first wrote this post, visitors are still finding it useful!

If you really want to understand what’s going on under the hood, the Windows Internals books are the place to start. In the interests of transparency: this is an affiliate link. See my affiliate disclosure page for an explanation.

Many organisations push out printer installations via Active Directory. If you want to tidy up those printers (removing ones you don’t use) you may find Windows 7 doesn’t let you delete them, even though you may be a local administrator and even if you use an elevated Explorer session:

Access denied error

Use the following steps to resolve this annoyance.

From an elevated command prompt:

C:\Windows\system32>net stop spooler
The Print Spooler service is stopping.
The Print Spooler service was stopped successfully.

Then fire up regedit. Navigate to Computer\HKEY_CURRENT_USER\Printers\Connections and delete the offending printer:

printers regedit

Finally, restart the print spooler:

C:\Windows\system32>net start spooler
The Print Spooler service is starting.
The Print Spooler service was started successfully.

From CodeIgniter to Laravel | part 4: managing databases

UPDATE: I have re-written this article for the new Laravel 4. You’ll find the updated article over at Geek & Dummy.

Contents


AVZ DatabaseFor almost all my previous web design, I’ve used phpMyAdmin to administer the databases. I speak SQL, so that has never been a big deal. But Laravel comes with some excellent tools for administering your databases more intelligently and (most importantly!) with less effort. Migrations offer version control for your application’s database. For each version change, you create a “migration” which provides details on the changes to make and how to roll back those changes. Once you’ve got the hang of it, I reckon you’ll barely touch phpMyAdmin again.

Configuration

So let’s assume that I’m creating a new website about ducks. When I created the virtual host, Virtualmin also created my “ducks” database. I’m going to create a MySQL user with the same name, with full permission to access the new database. Here’s how I do that from a root SSH login:

echo "GRANT ALL ON ducks.* TO 'ducks'@localhost IDENTIFIED BY 'newpassword';" | mysql -p
Enter password:[root MySQL password]

This creates a new MySQL user, “ducks” and gives it all privileges associated to the database in question. Next we need to tell Laravel about these credentials. The important lines in the file application/config/database.php are:

<?php
return array(

//...

	'default' => 'mysql',

	'connections' => array(

//...

		'mysql' => array(
			'driver'   => 'mysql',
			'host'     => '127.0.0.1',
			'database' => 'ducks',
			'username' => 'ducks',
			'password' => 'newpassword',
			'charset'  => 'utf8',
			'prefix'   => '',
		),

//...

	),

//...

);

Initialise Migrations

The migration environment must be initialised for this application. We do this using Laravel’s command line interface, Artisan. From an SSH login:

php artisan migrate:install
Migration table created successfully.

This creates a new table, laravel_migrations, which will be used to track changes to your database schema (i.e. structure), going forwards.

My ducks application will have a single table to start with, called “ducks” [Note: it is significant that we’re using a plural word here; I recommend you follow suit]. This table does not yet exist; we will create it using a migration. To kick this off, use the following Artisan command:

php artisan migrate:make create_ducks_table
Great! New migration created!

This will create a new file named something like “2013_04_15_085356_create_ducks_table.php”. If, like me, you’re developing remotely, you’ll need to pull this new file into your development environment. In NetBeans, for example, right-click the migrations folder, click “download” and follow the wizard.

You can deduce from the naming of the file that migrations are effectively time-stamped. This is where the life of your applications database begins. The migrations file will look a bit like this:

<?php

class Create_Ducks_Table {

	/**
	 * Make changes to the database.
	 *
	 * @return void
	 */
	public function up()
	{
		//
	}

	/**
	 * Revert the changes to the database.
	 *
	 * @return void
	 */
	public function down()
	{
		//
	}

}&#91;/php&#93;

As you can probably guess, in the "up" function, you enter the code necessary to create the new table (to move "up" a migration) and in the "down" function, you do the reverse (to move "down" or to roll back a migration).

<h1>Create first table</h1>

Your first migration will probably be to create a table (unless you have already created or imported tables via some other method).  Naturally, Laravel has a class for this purpose, the <a href="http://laravel.com/docs/database/schema" target="_blank">Schema class</a>.  Here's how you can use it, in your newly-created migrations php file:

[php]<?php

class Create_Ducks_Table {

	/**
	 * Make changes to the database.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('ducks', function($table) {
				$table->increments('id');              // auto-incrementing primary key
				$table->string('name', 255);           // varchar field; length 255 characters
				$table->date('birthdate')->nullable(); // can be empty
				$table->boolean('can_fly')->default(TRUE);
				$table->integer('children')->unsigned();
				$table->text('biography');
				$table->timestamps(); // special created_at and updated_at timestamp fields
		});	
	}

	/**
	 * Revert the changes to the database.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('ducks');
	}

}

To run the migration (i.e. to create the table), do the following at your SSH login:

php artisan migrate
Migrated: application/2013_04_15_085356_create_ducks_table

That creates the table, as described. And if you need to roll back:

php artisan migrate:rollback
Rolled back: application/2013_04_15_085356_create_ducks_table

This removes the table.

By examining the Schema class documentation, you’ll see how you can use future migrations to add or remove fields, create indexes, etc. In my next tutorial, I’ll have a look at using databases in your application.

AVZ Database image copyright © adesigna, licensed under Creative Commons. Used with permission.

From CodeIgniter to Laravel | part 3: installing external libraries

UPDATE: I have re-written this article for the new Laravel 4. You’ll find the updated article over at Geek & Dummy.

Contents


LibraryAs a fan of CodeIgniter, I was very pleased when the Sparks project came on the scene, offering a relatively easy way to integrate third-party libraries/classes into your project. Laravel has a similar and arguably more feature-rich analog in Bundles. With a bit of luck, the third-party library you require has already been converted to a Laravel bundle, making installation a snip.

Let’s say, for example, we’re going to build a web-scraping application. The first two libraries I’d consider adding to the project would be the Requests HTTP library and the PHP Simple HTML DOM Parser.

From an SSH login, at the root of your project, issue the following command:

php artisan bundle:install requests phpsimplehtmldom

You should be greeted with the following results:

Fetching [requests]...done! Bundle installed.
Fetching [phpsimplehtmldom]...done! Bundle installed.

The file application/bundles.php will probably contain code along the following lines:

<?php

/*
 &#91;...various comments...&#93;
*/

return array(

	'docs' => array('handles' => 'docs'),

);

Register the new libraries like this:

return array(

	'docs' => array('handles' => 'docs'),
	'requests' => array('auto' => TRUE),
	'phpsimplehtmldom' => array('auto' => TRUE),

);

And use like this:

		$HDM = IoC::resolve('HtmlDomParser'); // Give us a hook into the library; Requests doesn't need this

		// Request the HTML page
		//$headers = array('Accept' => 'application/html');
		$headers = array();
		//$options = array('auth' => array('user', 'pass'));
		$options = array();
		$request = Requests::get('http://some.domain/some/page', $headers, $options);
		if($request->status_code != 200) {
			// Handle error retrieving page
		}

		$dom = $HDM::str_get_html($request->body);

		// Options
		$options = $dom->find('#somediv option');
		foreach($options as $option) {
			echo $option->value.' | '.$option->innertext."<br />";
		}

There’s a lot more to this IoC thing than meets the eye. To be frank, it’s above my head. I’m also not convinced I fully understand registering bundles. But, like CodeIgniter, learning is a process of immersion in the framework. I’m pretty sure than in a couple of years I’ll laugh at the code above. So all I ask is please be gentle in the comments. 😉

Library image copyright © Janne Moren, licensed under Creative Commons. Used with permission.