Install Ruby on Rails (web development) environment on Chromebook using Crouton

Web development on a Chromebook. Is it possible? Even if its possible, does it work well? It does! I develop web applications, mainly using Ruby on Rails on my Chromebook. I used to use to 15 inch MacBook Pro, but since I travel almost every month, after a while, lugging my macbook around was a real pain in the back. For the last year or so I've been using an Asus C302A Flip Chromebook. At first, I wasn't sure the Chromebook was going to be able to cope with web app development using Ruby on Rails, but I was pleasantly surprised.

In this post I'm going to document how I set up ubuntu on my Chromebook for local web development. Please note that I've already put my Chromebook in developer mode, installed Crouton and created an ubuntu chroot. If you haven't done it here's a guide on installing crouton and chroots on your chromebook.

Once you're all set up, follow these steps to set up Ruby on Rails on your new Ubuntu Chroot.

  1. Open Chrome
  2. Press CTRL + ALT + T
shell
sudo enter-chroot -n ubunutu

The '-n' let's you pass a name to your chroot. Hopefully you named your chroot. If you only have one chroot, you can skip the '-n ubuntu'. If you have multiple chroots, and you didn't name yours then the default name will be the release name, something like 'xenial'.

Congratulations, you're now logged in to your virtual ubuntu machine. Now for the fun part.

Install Git:

sudo apt-get install git

Install Curl:

sudo apt-get install curl

Install RVM (Ruby Version Manager)

sudo curl -sSL https://get.rvm.io | bash -s stable

Ah, I got a failure. Something to do with GPG keys.

sudo curl -sSL https://rvm.io/mpapis.asc | gpg --import -

OK now rerun the previous curl command to get rvm. You should see a success message like this:

Installation of RVM in /home/user/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/user/.rvm/scripts/rvm` or source ~/.rvm/scripts/rvm
    in all your open shell windows, in rare cases you need to reopen all shell windows.

Let's check we have the latest version installed.

rvm get stable

Now we need to get the system ready for Ruby

rvm requirements

What ruby versions can we install? Let's check.

rvm list rubies

2.4 is the latest. If I'm not mistaken the app I want to work on runs on 2.2, so I'm going to install that.

rvm install 2.2

Wait a while….

ruby -v
ruby 2.2.7p470 (2017-03-28 revision 58194) [x86_64-linux]

To avoid conflicts between ruby versions, we'll create a gemset to use with this ruby version.

rvm use 2.2@r2.2_default --create --default
Using /home/chirag/.rvm/gems/ruby-2.2.7 with gemset r2.2_default

Before we install rails, we should tell rubygems not to create any documentation. Use your text editor to edit the file. I'm using VIM.

vim ~/.gemrc

Add the following two lines in the file and save.

install: --no-rdoc --no-ri
update:  --no-rdoc --no-ri

Now you can install rails. I'm using 4.2.10

gem install rails --version 4.0.8

We need to perform some one time set up if this is the first time you're using git.

git config --global user.name "Your Full Name"
git config --global user.email your.email@mydomain.com
git config --global alias.co checkout

Once you're in a folder where you want to work

git init

If you're working on code that's already on a repository

git remote add origin git@bitbucket.org:username/projectname.git

To use this we need to set up ssh keys for bitbucket.

ssh-keygen -f ~/.ssh/<bitbucketusername>
ssh-add ~/.ssh/<username>
cat ~/.ssh/<username>.pub

Paste the contents into bitbucket. Follow these instructions. 

Now grab your repository. Use clone instead of pull as it will set up remote tracking.

git clone git@bitbucket.org:team/project.git

You should be ready to roll if you downloaded an existing rails project. Enjoy!

Review: SoundPeats Q12 Bluetooth Headphones

Looking for Bluetooth headphones, there’s a lot of variety on offer. I wanted something out of the way so opted for in ear headphones. 

Now, a quick amazon search will return so many different types of Bluetooth headphones. What’s the difference? Which one to choose?
There is a mix of name brands and no name brands with varying reviews and features. It’s easy to get paralysis by analysis. There is so much choice.
Just before i made my purchase the powerbeats3 were released. I was SO tempted. They had a price point of over £120 GBP.
For me, headphones don’t last long. Usually about six months before one ear stops playing sound. So I wasn’t sure if it was worth spending on the powerbests3.
After some careful research I settled with SoundPeats, specifically their Q12 model. 
The Q12 had a lot going for it.

  • 6hour battery life
  • apt-X
  • magnetic earbuds
  • carry case
  • 3 sets of earbuds and eartips
  • inline controls and mic
  • £15 GBP

And so on. You can look up the spec on Amazon.

The magnetic earbuds are great. You can just clip the eabuds together to form a necklace when you’re not listening to tunes.
The sound quality was on par with my wired Samsung headphones. That said, I seemed to have more sound in my right ear. I could feel the bass clearly on one side. It made me feel unbalanced and a little uneasy. One email to SoundPeats and they replied with an offer to refund me or send a new set of headphones. I’m requested the latter.
For a value pair of headphones the customer support was a great touch. Better than some of the bigger brands. (Samsung you could learn something here.
Let’s talk a about the biggest issue with bluetooth Headphones. Battery life.
? ? ?
I use the Q12s about 2 hours each day for my commute. I find myself charging them every 4 or 5 days.
Battery life is great. I haven’t tested them continuously so i cant tell you total playback time. 
The one annoying thing is that they don’t have a battery level indicator so it’s hard to tell how much juice you have left. A couple of times I’ve started my commute and heard the headphones interrupt my music to let me know the battery was low. This is really annoying. The constant interruption and the fact there’s no way to know how much battery life is left.

I don’t like to charge products too much, if they have enough power. So not knowing what’s left may cause you to charge these headphones daily to ensure you have enough power for the day ahead.

Charging takes around 2 hours.

Build quality of the headphones is good. Reviews of other headsets on Amazon said that they broke. Mine travel in my jacket pocket when not in use and don’t show any sign of weakness yet. The feel is plasticy and not premium, but I’m not complaining for the super low price point. The cable that joins the two earbuds is flat which means it rarely gets tangled and your headphones are always ready to go.

The brains of these headphones are in the earbuds so they’re a bit bigger and heavier than normal in ear headphones. That said, I’m using the supplied ear wing tips and they sit safely and securely in my ears, even when I’m running for a train or at the gym. You couldn’t sleep with these headphones on though. They do protrude out a little more than non Bluetooth units.

Recommendation

Overall, I would rate these a buy and say give them a try. They’re not perfect but great for the majority of use cases. Also you can buy so many of these for the price of the beats equivalents. Don’t forget that customer service was also really helpful which is often something I overlook when making my buying decision.

#soundpeats

#bluetooth

#bluetoothheadphones 

#q12

#wireless

#beats

#powerbeats3wireless 

#samsung

The Web App Challenge: £0 to £3000/month in six months

It’s a new year. Time to re-focus on those life goals and keep life heading in the desired direction.

I was reading Nathan Barry’s blog today and have decided to join him in the Web App challenge. Unlike Nathan, I have some idea about the web application I want to build, but I’m still researching and planning at the moment. To be honest Nathan’s post couldn’t have come at a better time. I’m hoping to be just as transparent and take inspiration from his aggressive approach and tight timeline (leaving me less time to procrastinate!).

What our challenges have in common

– Extracting ideas in the style of Dane Maxwell

– Building a web application

– Using Ruby on Rails

– Looking for to create a SaaS (software as a service) product.

How our challenges will differ

Unlike Nathan, I’m assigning a budget of ZERO. I plan on doing the design / development / marketing etc by myself, whilst working full time at my job (which is often more than the usual 9 to 5).

I have experience in programming with Ruby and Rails, but have never built a full web app, especially one I intended to sell. I’m hoping the next few months will solidify my knowledge of Rails and allow me to create software that provides real value to my eventual target market.

Join in?

Whilst the Web App Challenge isn’t an official challenge (as far as I know), I encourage you to join in. It would be nice to have some community to share the ups and downs and building a software product with. Besides, what better way to start the new year than to start working on a new project?

To our successes in 2013! Happy new year 🙂

— CD

Project Ideas

Recently I’ve had the urge to make something. I have random ideas about cool things I’d like to have in my life and start researching how to build them.

My problem is I’ve now got several ideas in my head and no clear starting point so my progress has been unimpressive.

Below is a list of ideas I have. If you know how I should tackle any of the below please get in touch. The list is to serve as a reference for myself.

1. Sip door phone
I’ve seen expensive consumer products but reckon I can build one myself using raspberry pi or similar. The idea is someone pushes the button and it calls the phones attached to my asterisk (in my home, in my office and on my mobile). Whilst ringing the person at the door is asked for their name and purpose so this can be played when I answer. (Useful when packages are delivered and I am not in – also when friends visit and I am out.) Extra: add a picture or webcam feed, ability to notify an iOS or android app, and possibly the ability to lock unlock the door from any phone that answers the doorbell.

2. Sip loudspeaker
I don’t know why, but I’d like my house to talk to me. I’d like to know how the underground lines look in the morning while I make my tea. I’d also like to be able to leave messages for family members when they return to the house (use of motion sensor). I’d also like two way calls via the speaker, so I could call the speaker and talk to whomever might be in. This would also be good in my grandfather’s house so we can talk to him without him needing to operate a phone.

3. Home automation (general)
I have lights I can control via iOS or android apps. I’d like to make them smarter e.g. know I was heading upstairs and that no lights are on and either ask if I want them on (can use sip speaker, motion sensor + voice command software) or just turn them on anyway.

4. Money management app
I am planning to build this in Rails. This is for a friends business so I’m not going to say much here.

5. Git server
I’d like to host my own github style site to backup my work

6. Android management Either the ability to remotely manage family members android devices e.g. initiate app updates, backup images etc via a web interface. Also ability to provide remote support I.e. ability to see the screen of a family members device and show them how to perform common tasks. (Vnc style).

7. Follow me music system I would like a sonos style setup whereby I can dictate what is played in each room. If I could tie this in with the sip speaker project that would be great.

8. Android sip client I know many of these exist but I’d like to build one just for fun. That’s it for now.

9. Home security
I’d like to be able to tell what’s going on in my house at a glance (phone/tablet).

10. Media displays
Use “small computers” (e.g. raspberry pi / arduino) to power 4 large TV screens with advertising. Using XiBo or similar.

11. Home Check-in
Use the Raspberry Pi to monitor the MAC addresses connected to my home network. Use these addresses and a few logical conditions such as time etc to determine whether members of the family are at home or not. This can then be extended to tie in with home automation and turn lights on when returning home and nobody else is at home.

Will update when more ideas keep me awake at night.

Asterisk setup and config tutorial

Asterisk PBX (private branch exchange) is a fully featured phone system. From what I’ve read, it’s used by companies in all shapes and sizes, and can be made to do some pretty amazing things.

My current set up has 3 different incoming UK numbers (for three different companies) hitting my Asterisk. Each number is handled differently. They forward calls to mobiles, take voicemails, record all calls, email call alerts, forward to SIP Phones or a combination of these options. My aim is to show you how to configure asterisk to do all of the above and more.

This guide is covers installation of Asterisk 1.8 on a CentOS 5 VPS in 2012. The intention is for this guide to serve as a reminder to me and a tutorial for you. I had an installation running for about 6 months until RAID crashed on the VPS and I lost the whole asterisk. Starting from scratch, I realised I had forgotten where to start and how I’d configured the system. The new system is better now. I digress.

What you’ll need

  • A server, preferably Linux. As mentioned I’m using a VPS with CentOS 5.
  • A SIP based VOIP Phone. This can be software (I recommend X-Lite (free) for windows and mac – the site is geared towards selling, if you can’t find the files please comment and I’ll update with direct links.) You may also use a Hardware SIP Phone.
  • A VOIP account – I use RXHost in the UK to provide my UK inbound number and handle the outbound calls (I added credit to my account). They also provide US and other international numbers too.  A trial account is free but will take about 24 hours to set up because they call you to confirm your identity and help you get set up.

We’re not covering physically attaching asterisk to “real” PSTN phone lines, in favour of using “virtual” sip trunks with real phone numbers.

Installing Asterisk

I don’t intend to re-invent the wheel here. You’re going to need root access to your server and be comfortable at command line. There were two resources I found online that got me installed: Installing asterisk 1.8 on CentOS 5 (opens in new window) and Installing asterisk 1.6 on CentOS 5.2.

I followed the Asterisk 1.8 and CentOS 5 guide and it seemed to do the trick. If you get stuck please just leave a comment and I’ll do my best to help.

 Starting Asterisk

Now, I hope you have Asterisk all installed and didn’t end up stuck or with too many errors. Presuming everything went to plan, you can now type

asterisk

to start asterisk. Then the following to “connect” to the asterisk server.

asterisk -r

After running the above command you’ll see (or something similar):

Connected to Asterisk 1.8.15.0 currently running on pbx (pid = 1799)
pbx*CLI>

Congratulations! You have a running PBX.

Preparing to make and receive calls

Now since Asterisk is going to be routing your calls over the internet you’re going to want to make sure you have a firewall set up and open up the ports required for it to work. You need to make sure you only open as many ports as you need to make sure you are safe. Getting hacked could be hostly, not just because you’ll have to clean up, but because a hacker could take advantage of any outbound calling lines you have and run up the bill.

Also, not having the right ports open has been reported to cause lack of sound.

Follow this guide (opens new window) on setting up your IP Tables, and we’ll carry on once you’re back.

CentOs IPTables Set Up and CentOS Start IPTables  (for reference and background reading)

Receiving Calls with Asterisk

The fun begins now. There are two ways we can place our first call with asterisk, using your SIP Phone, or not. I’m going to presume you’ve set up Asterisk but do not have a SIP Phone handy (just like me the first time I set up Asterisk).

Accepting calls from PSTN (real phones) on Asterisk

You set up a RX Host account right? We’re going to be using it now to place a call from a real phone to our RX Host number. The RX Host number will be answered by Asterisk and play us a message or some music.

If it’s prohibitively expensive for you to call a UK or international number (as provided by RX Host) then I will be covering set up using SIP Phones further down. So you can scroll down, or google some SIP providers that provide free numbers in your local area 😉

On your server you need to change into the asterisk directory:

cd /etc/asterisk

If you type the command ‘ls’ (without quotes) now, you should see a lot of .conf files. These are the files that we edit in order to let asterisk know how we want our calls handled, set up new extensions, voicemail boxes etc.

The first file we want to edit is called sip.conf.

vim sip.conf

Now I’m not presuming you know vim, because I didn’t when I first installed asterisk so here are some basic commands that will help.

  • Arrow buttons (up, down, left right) for moving the cursor.
  • Shift + up or down (scrolls up our down an entire ‘page’)
  • i – type the letter i when you’re ready to start inserting text or editing. Press esc to stop editing.
  • :q – quit without saving. (make sure you push esc if you were editing)
  • :w – write aka save
  • :wq – save then quit

The sip.conf file will have a lot of commented out text example text in it. It’s recommended you read through it to see what is possible (I haven’t). Somewhere after you see

[general]
context=default
allowoverlap=no

You want to insert the following to allow Asterisk to log in to your RX Host account.

[rxhost]
type=friend
host=rxhost.co.uk
fromdomain=rxhost.co.uk
fromuser=1234567 enter your numerical username here
callbackextension=1234567 numerical username again
defaultuser=1234567 numerical username again
context=rxhost_in
outboundproxy=rxhost.co.uk
qualify=yes
secret=password
insecure=invite
allow=g729
allow=gsm
allow=ulaw
dtmfmode=rfc2833

The fields are where you need to input data from your RXHost account. The numerical username is referred to as your SIP ID on RXHost website. Once you are logged in you need to click settings then overview to find your SIP password (NB: it is not the same password you use to log in to your RXHost user account).

Don’t forget to type :wq to save and close the file. Asterisk should now have enough information to log in to your RXHost account. (You can check asterisk registers successfully and I’ll show you how in a moment.)

A key line to pay attention to is the line that reads context=rxhost_in. This tells asterisk where to look next for instructions on how to deal with the call.

The next file we need to edit is the extensions.conf file.

vim extensions.conf

Again, this file will have some sample text in it. Find some space in the file and make sure you start inserting BEFORE a line that has text in square brackets. For example you would insert your text immediately before [demo] or whatever the line may read.

The text in square brackets defines a context (more on these later) and we’re going to define out own context now. Any guesses what it will be called? Did you say rxhost_in? Well, then you’d be right. Here’s what we have to insert:

[rxhost_in]
exten => 1234567,1,Playback(vm-goodbye)
exten => 1234567,n,Hangup()

Make sure you replace 1234567 with your RXHost SIP ID (aka username from the sip.conf file). That’s all that needs doing. Don’t forget to save and quit (:wq).

The sip.conf file tells asterisk to look at the context [rxhost_in] for details on how to handle the call. In this context, asterisk simply plays a file called vm-goodbye and then hangs up. You can’t dial your number just yet, but we’re nearly there.

Connect back to asterisk CLI (command line interface).

asterisk -r

You may need to type asterisk on its own first if it isn’t running. Now we need to let asterisk know we’ve updated some files and that it should reload them. Run these commands, one after the other:

sip reload

Reloads the sip.conf file

dialplan reload

Reloads the extensions.conf file

reload

Not strictly necessary but done for good measure. (You may see some errors and warnings from this one, but you can probably ignore them).

Let’s check if Asterisk is connected to rxhost properly.

sip show registry

If you see an entry for rxhost and the word Registered under state, you’re good to go. If not, you need to double check your sip.conf file and make sure your password etc are correct. Don’t forget to come back to the Asterisk CLI and reload the file before showing the registry.

Make your test call using your normal phone and dial your RXHOST number. 

You should hear “goodbye” and then be hung up on. Et voila, you have a working PBX!

You can also use Asterisk to make calls via your RXHost number, to either other RXHost or SIP users or to normal phones, although you’ll need to pay RXHost for credit. You can also set up with multiple providers to use the ones who give you the cheapest rate depending on where you’re calling.

Oh and for more Asterisk CLI commands you can type help or look here.

Making calls with Asterisk

Whether you set up Asterisk with RXHost or not, you can still have some fun. The real power of asterisk is providing an office like phone system where each user can have their own extension and voicemail. Calls can be passed to an auto attendendant (menu system e.g. push one for sales, two for billing) or and IVR (interactive voice response) which is more like when you call your bank and are asked to enter details like your date of birth or customer number and the system checks your details against a database before reading your balance. This is all possible with Asterisk.

Let’s start with adding some extensions. I’m hoping you’ve read the part above, so you’ll understand the editing of sip.conf and extensions.conf.

On your server, if you haven’t already:

cd /etc/asterisk
vim sip.conf

Where you’ve entered  (or would have entered) the RXHost entry directly below this you want to enter the following:

[phone1]
type=friend
defaultuser=phone1
nat=yes
host=dynamic
secret=abcdefg
regexten=1003
regcontext=phone1
context=rxhost_out
insecure=invite
canreinvite=yes
allow=all
[phone2]
type=friend
defaultuser=phone2
nat=yes
host=dynamic
secret=abcde
regexten=3001
regcontext=phone2
context=rxhost_out
insecure=invite
canreinvite=yes
allow=all

Make sure you change the secret to something secure. Save the file and quit.(:wq).

You can also see that the context on both phones we’ve registered here is set to rxhost_out. This means that when either of these phones are connected to asterisk, it will look in extensions.conf at [rxhost_out] to determine how to hand the digits dialled. So let’s add something to extensions.conf.

vim extensions.conf

Underneath the entry we made for [rxhost_out] (or where you would have made that entry) add the following:

[rxhost_out]
;this context is assigned to phones/users so that they may call
;9 should be used to make a call out via this RXHost line.

exten => _90[1-9].,1,Set(CALLERID(num)=rxhost_number_here)
exten => _90[1-9].,n,Dial(SIP/${EXTEN:1}@rxhost,30,trg)
exten => _90[1-9].,n,Hangup

;here come general extensions for all users.

;first is to record some messages.
exten => 3003,1,Answer()
exten => 3003,n,Wait(2)
exten => 3003,n,Record(/var/lib/asterisk/sounds/recordings/recording.gsm) ; # to stop recording.
exten => 3003,n,Wait(2)
exten => 3003,n,Playback(/var/lib/asterisk/sounds/recordings/recording)
exten => 3003,n,Wait(2)
exten => 3003,n,Hangup

;3001 to dial phone 1
;tmpA(beep) performs call screening
exten => 3001,1,Dial(SIP/phone1,18,tmpA(beep)
exten => 3001,n,Hangup()

; 3002 dials phone 2
exten => 3002,1,Dial(SIP/phone2,18)
exten => 3002,n,Hangup()

The comments in the dialplan should explain what is happening clearly. If user on phone1 or phone2 dials 9 followed by a number, asterisk attempts to place the call via RXHost. If the user dials 3001 or 3002, asterisk attempts to call the relevant phone. Dialling 3003 allows you to record your voice and save a file, this will come in useful later when we record our own menu system.

Now for this to work you need to set up your hardware or soft phones. All you should need is the IP address of your server running asterisk and the username e.g. phone1 or phone2 and the corresponding password (the secret field from sip.conf).

Don’t forget to connect to the asterisk CLI and reload everything.

asterisk -r
sip reload
dialplan reload
reload
sip show users

This last command should show all registered phones. If your phone1 or phone2 is not listed then you need to double check your settings. I believe on x-lite you can set up two accounts on one device. If you’re all set up you can dial either 3001 or 3002 and see if you can call the other phone. You can also dial
910005 (9 for RXHost line) and 10005 being the RXHost echo test. Where you should be able to speak and hear yourself. Alternatively you can dial 3003 to record your voice and have it played back via the asterisk system.

To be continued

I didn’t realise it would take this long to write this guide. There’s lots more I’d like to share, so I this post will be followed up by others. If you liked it or have any comments or questions please leave them below and feel free to tweet and share this post too!

The Definitive Guide

Within the asterisk community there seems to be one book that everybody loves. I’ve had to check it out and found it VERY informative. If you have any interest in playing with asterisk a lot I recommend you pick up a copy of Asterisk: The Definitive Guide.