Professional Documents
Culture Documents
08 Prepare
to deploy
05 Config/deploy
bundle exec cap install creates
the necessary config files and directories. It
is in these that we specify the actions that
Capistrano takes to deploy our app to staging or
to our production servers.
Note that staging and production are created
by default with files under config/deploy, and
you can add a qa.rb file to that subdir if you
wish to add a third stage. Alternatively, you can
create all the extra stages at installation time: “Note that staging and production are
cap install STAGES=staging,production,ci,qa created by default”
08 Prepare to deploy
In deploy.rb, ahead of namespace
:deploy, you should add some lines relevant to
your project:
require “bundler/capistrano”
06 Config
The last step created the Capfile,
www/#{fetch(:application}”
# set :deploy_via, :remote_cache
tasks under lib/capistrano and deployed files
under config/. Start with editing the Capfile by
uncommenting the lines:
07 Secrets
Remember that everything in our app
is being shared with the team and anyone else
# set :use_sudo, false
## repo details
set :scm, “git”
who has access to our Git repository, including set :repository, “git@github.com:jsmith/
require ‘capistrano/rbenv’ exposed passwords. Edit your .gitignore file to myblog.git”
require ‘capistrano/bundler’ add this line: set :branch, “master”
require ‘capistrano/rails/migrations’
/config/database.yml default_run_options[:pty] = true
…and make sure that the line starting Dir.glob at ssh_options[:forward_agent] = true
the end of the above screenshot is present and Now you can edit /config/database.yml for set :keep_releases, 5
uncommented. This line ensures that all of the your database locally and in your staging and
RB files below lib/capistrano get loaded, including production environments. Note that here we’re deploying to just one server.
any custom tasks in lib/capistrano/tasks that Restart your Rails server and check it’s working You might also want to add some specifics for
you’ll want to later define. properly at http://localhost:3000 your Ruby environment:
/var/
simple in this introduction, hence the earlier introductions we give here. The Capistrano /var/log
manual set up of the server. website (http://capistranorb.com) should
be your first port of call, but you’ll find docs
10 Deploy
Now for deployment. Our config wound
up the spring; to set the clockwork in motion we:
elsewhere for integrating Capistrano with
everything from Jenkins to AngularJS –
just double check to make sure that you’re
reading something that has been updated
cap production deploy for Capistrano 3. Integrating Capistrano’s
scripts for continuous deployment into a larger
For that to work first time, you’ll have had to have environment of a continuous integration server
done a bit of work on the config – beyond what like Jenkins is easy enough – a job in Jenkins, as
we’ve specifically outlined in the case of many an example, has cap deploy as its build step (and
setups. Capistrano is designed to expand and your Git repository as its URL).
stretch to cover all sorts of circumstances, and Away from Rails, gems do exist that can ease
your app and server setup won’t be exactly the deployment for most web platforms, from
same as anyone else’s. Although, that said, if you Sinatra to Django. For Drupal (with Drush and
deploy to a large cloud provider then they may the CapDrupal gem) you can automate taking
have Capistrano example configs you can copy. the site offline, backing up the database, cloning
Capistrano’s modularity and flexibility means your new code and pointing the site root there,
there’s a lot to explore to get it doing what you updating the database, and putting the site back Above The numerous usage examples on
need. It is essentially a utility for running tasks, online as well as all of the advantages of cap SSHkit’s GitHub page hint at its potential
in parallel, across remote servers… deploy:rollback.
Generate complex
graphics with ggplot2
Seen as the new version of S, learn how to
create truly impressive plots using R and
the ggplot2 package
Resources R is a GNU project based on S, which is a
statistics-specific language and environment
most other graphics packages is that it has a
deep principal grammar. Learning its grammar,
R Project r-project.org developed at the famous AT&T Bell Labs. You which is based on the book The Grammar Of
RStudio rstudio.com can think of R as the free version of S. Despite its Graphics, will help you design better plots but
simple name, R is a powerful piece of software it is not required in order to follow this article.
ggplot2 ggplot2.org for statistical computing with many capabilities In other words, the grammar tells that a plot is
Documentation and an interpreted programming language. a mapping from data to aesthetic properties of
docs.ggplot2.org/current R packages can greatly extend its geometric objects.
RSQLite bit.ly/1ArJvkc
capabilities. Ggplot2 is an R package, written This article is full of practical examples that
by Hadley Wickham, that is used for producing demonstrate the use of ggplot2 for drawing
statistical and data graphics, working with plots many different kinds of plots, including a plot of
in layers. Despite being a powerful package, the Chrome’s history file!
it is reasonably easy to learn and produces Feeling comfortable with mathematics
sophisticated and beautiful plots that are of and statistics is helpful but not vital for
publication quality. Its main difference from understanding this article.
03 Use
quickplot()
“Experiment with your data and the The presented plot was produced using the
following commands:
01 Install ggplot2
First run R. The ggplot2 R package isn’t
installed by default, so check if you already
03 Use quickplot()
The ggplot2 package offers two
main functions: quickplot() and ggplot(). The
> require(CCA)
> ggpairs(data)
> require(ggplot2)
quickplot() function, qplot(), is similar to the
plot() R function and is good for simple plots.
The quickplot() function hides what happens,
05 Generate bar plots
Now use a sample dataset for
plotting. The LUD dataset, available from
Loading required package: ggplot2 whereas ggplot() is harder to use but flexible. FileSilo, is stored in a plain text file, named
The following commands draw a plot using Lud.data. The titles of the columns are named
If it’s not installed, download and select: columns V2 and V3 from the data variable: to refer to their values. You can load the
> str(data) dataset into R using the following command:
> install.packages(“ggplot2”) ‘data.frame’: 16180 obs. of 3
variables: > LUD <- read.table(“lud.data”,
If you execute the library() function without $ V1: num 0 0 0 0 0 0 0.98 1 1.06 1 ... header=TRUE)
arguments, you’ll get a list of installed packages. $ V2: num 0.01 0.01 0.01 0.01 0.03 0.01
To get a detailed output, run the installed. 0.58 0.85 1.01 1.01 ... The bar plot is very simple. The following
packages() command without any arguments. $ V3: num 0.05 0.05 0.05 0.05 0.05 0.05 command generates it:
0.27 0.48 0.65 0.75 ...
output. RStudio is a more preferable graphical > quickplot(data$V2, data$V3, color=data$V1) If you type ggplot(LUD, aes(x=RAM, y=SSD))
wrapper for R. without specifying a plot, the command will
When visualising data, remember that not show the ‘Error: No layers in plot’ message.
every plot suits every data set. This knowledge
comes from experience, and experience
comes from experimentation, so don’t forget to
04 Work with ggpairs()
The ggpairs() command finds relations
between variables and then calculates the
To change the colour of the bars, try the
following variation:
experiment with your data and the various types coefficient of correlation value. The coefficient > ggplot(LUD, aes(x=RAM, y=SSD,
of plots that R and ggplot2 can generate. of correlation is linked to the statistical fill=Uptime)) + geom_bar(stat=“identity”)
11 Visualising Chrome’s
history file
The following command makes the title blue and > ggplot(LUD, aes(Years)) + geom_
its size larger using the theme() function: histogram(binwidth=1, color=‘gray’)
> ggplot(LUD, aes(x=RAM, y=SSD, Use geom_density() function for a density plot:
fill=Uptime)) + geom_bar(stat=“identity”)
+ labs(title=“This is a Title”) + xlab(“X
Label”) + ylab(“Y Label”) + theme(plot.
> ggplot(LUD, aes(Years)) + geom_
density(binwidth=1)
09 Add smooth layers
Another type of layer is the smooth
layer. It doesn’t display raw data, but rather a
title = element_text(size = rel(2), statistical transformation of the data.
colour = “blue”)) The following command draws a histogram and The (method=“lm”) parameter generates a
a density plot on the same plot: linear regression line instead of a LOESS (local
To change the attributes of the X and Y axes, use polynomial regression fitting) curve, which is
the axis.line function: > ggplot(LUD) + geom_ the default for samples with less than 1000
histogram(aes(Years, ..density..), observations. For bigger samples, the default
> ggplot(LUD, aes(x=RAM, y=SSD, binwidth=2, color=‘white’) + geom_ method is called GAM (generalised additive
fill=Uptime)) + geom_bar(stat=“identity”) density(aes(Years, ..density..), model). The produced plot was generated with
+ labs(title=“This is a Title”) + xlab(“X binwidth=2, color=‘red’) the following commands:
Label”) + ylab(“Y Label”) + theme(plot.
title = element_text(size = rel(2), If you put the geom_density() command first, > q <- ggplot(LUD, aes(x=RAM, y=SSD))
colour = “blue”), axis.line = element_ the histogram will be on top of the density > q + geom_point() + geom_smooth()
line(size = 3, colour = “red”, linetype plot and therefore the density plot will not be > q + geom_point() + geom_
= “dotted”)) completely visible. smooth(method=‘lm’)
12 Box
plots
Monitor CPU
temperature with Dizmo
Turn your Raspberry Pi into an Internet of Things with
this CPU temperature gauge tutorial Full code
FileSilo.c
o.uk
02 Install dizmoSpace
If you haven’t already, head to www.dizmo.com, grab “A Dizmo widget is a HTML file,
dizmoSpace and install it to the system you plan for it to work
with. All you need to do is download the zip and unpack it, then packaging resources together to
click the Dizmo icon or run it from the terminal.
create an interface or graphic.
Our HTML file uses jQuery”
03 Launch issues?
If Dizmo is complaining about libraries when you try
05 Add framework
Use node -v to check if it’s installed correctly – it should
spit out a version number for you. Once that’s done, install
to run it, you’ll need to install some extra software. Open the express.js, which will be our web application framework:
terminal on the PC you’re working from and install the extra
software with the following: $ sudo npm install -g express
$ sudo npm install -g express-generator
$ sudo apt-get install libavahi-compat-libdnssd-dev
$ sudo apt-get install libavahi-client-dev
06 Install framework
We’ll create the folder www in var and create a symlink
04 Download node.js
Now, we need to grab the latest version of node.js for the
Raspberry Pi. Back in the SSH connection to your Raspberry Pi,
for everything to run. Do this by moving to var, creating www and
making the symlink with:
09
Above As it’s
multi-touch, Dizmo
Start node.js
is perfect for You can now start the node server by typing in:
interactive table
displays in meetings $ node app.js
Internet It will say it’s listening on *.3000. Start up a new terminal, ssh in,
of Things and create the folder /public with mkdir /public to save all of the
It’s not a very
descriptive term,
but the Internet
07 Package file
First, create the file package.json with sudo
package.json, then enter:
nano
CPU data in.
of Things can be
almost anything.
Any item that is or {
can be connected
to the internet “name”: “ServeSysinfo”,
or networks, “version”: “0.0.1”,
such as modern “dependencies”: {“express”: “4.x”}
automated lights,
can be connected }
up to Dizmo and
the Raspberry Pi.
Dizmo space walk
Enjoy some pre-
installed projects
to see exactly
what Dizmo
can do
PiGauge Create
a custom app
10 CPU information
We are going to use the vcgencmd command to get the
CPU information from the Raspberry Pi. We will write a script that
to monitor the will do this and then write the info to sysinfo.json. Download the
08
temperature of
your Raspberry Pi, App node file grabsysinfo.sh from FileSilo and put it in /usr/local/bin.
and then go even Now, create a file called app.js and enter the following:
11
further Make a cronjob
Browser Create var express = require(‘express’); We will make it so that the temperature is updated every
an entire custom var app = express(); ten minutes. You can make it update much faster if you want, but
display using
a variety of
app.use(express.static(__dirname + ‘/public’)); have a play around with that. Open up cron with sudo crontab
information that app.listen(3000, function(){ -e and add this at the end:
can connect to console.log(‘listening on *.3000’);
and through the Pi
}); */10 * * * * /usr/local/bin/grabsysinfo.sh
15 Final application
The final step is to create the application.js file, which will
call the temperature from the Raspberry Pi using Ajax. You can
download it using:
wget x/application.js
13 Index file
A Dizmo widget is basically a HTML file, packaging
resources together to create an interface or graphic. Here, we 16 Get coding
With these building blocks, you can now start doing more
have the main HTML file that uses jQuery, which helps display interesting IoT things – controlling the GPIO ports, getting more
the temperature. Still in the Gauge folder, download it with: information, having it connect to other objects to control them
as well. Check out the Dizmo website for more details on projects
$ wget x/index.html that you can do.
Execute the
latexmk Perl script
in silent mode;
Latexmk is a
handy automatic
LaTeX document
Create your own generation routine
table of contents, that saves you time
list of figures or list
of tables easily