Friday, March 13, 2015

Adventure in R

What's up?

I am taking a class on Coursera.org called - "The Data Scientist's Toolbox" teaches online by Jeef Leek, Brian Caffo, and Roger D. Peng.  Part of the class is to teach you how to use git, github, R, and R's packages

Rcurl package requires "curl-config".
This means that we need to do:
  • sudo apt-get install curl
  • sudo apt-get install libcurl4-gnutls-dev

"mermaid" - OMG!!!!!

Ok, so I am really excited to have found mermaid- the software. LOL.
I was looking for a tool that I can generate a chart. It started off with markdown and I ended up running into mermaid.

mermaid is written in JavaScript, so you will need to have node.js installed on your lappy. Come to think of it, I haven't write an article about node.js, yet. I will do it later. *giggle*

NOTE: I found out later that mermaid requires Phantom.js and not node.js. I need to rewrite this section. One thing for sure, all of these require npm. Yeah, more stuffs to write about...

Installing mermaid

Installing mermaid is pretty simple, but only if you have node installed. So if you don't have node go ahead and install it on your puter.
The following is a script of me installing mermaid on my beloved Macbook Pro.

[reia-mbp15:~] reia% sudo npm install -g mermaid
Password:

> contextify@0.1.13 install /usr/local/lib/node_modules/mermaid/node_modules/d3/node_modules/jsdom/node_modules/contextify
> node-gyp rebuild

gyp WARN EACCES user "root" does not have permission to access the dev dir "/Users/reia/.node-gyp/0.10.33"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/mermaid/node_modules/d3/node_modules/jsdom/node_modules/contextify/.node-gyp"
  CXX(target) Release/obj.target/contextify/src/contextify.o
  SOLINK_MODULE(target) Release/contextify.node
  SOLINK_MODULE(target) Release/contextify.node: Finished
/usr/local/bin/mermaid -> /usr/local/lib/node_modules/mermaid/bin/mermaid.js
mermaid@0.4.0 /usr/local/lib/node_modules/mermaid
├── which@1.0.9
├── minimist@1.1.1
├── he@0.5.0
├── semver@4.3.1
├── mkdirp@0.5.0 (minimist@0.0.8)
├── moment@2.9.0
├── chalk@0.5.1 (ansi-styles@1.1.0, escape-string-regexp@1.0.3, supports-color@0.2.0, has-ansi@0.1.0, strip-ansi@0.3.0)
├── dagre-d3@0.3.3 (graphlib@1.0.1, dagre@0.6.4, lodash@2.4.1)
└── d3@3.4.13 (jsdom@1.0.0)
[reia-mbp15:~] reia% 

How do I run "mermaid"?

After the installation, I tried to run it but it failed.... *sad face*.

[reia-mbp15:~] reia% mermaid
mermaid: Command not found.
It turns out that I didn't have "/usr/local/bin" in my PATH, silly me. LOL.
Using absolute path fix that issue, for now.
Note to self, add /usr/local/bin/ into the .cshrc
[reia-mbp15:~] reia% /usr/local/bin/mermaid

You had errors in your syntax. Use --help for further information.
You must specify at least one source file.
Cannot find phantomjs in your PATH. If phantomjs is installed
you may need to specify its path manually with the '-e' option.
Run this executable with '--help' or view the README for more
details.
[reia-mbp15:~] reia% /usr/local/bin/mermaid --help

Usage: mermaid [options] ...

file    The mermaid description file to be rendered

Options:
  -s --svg             Output SVG instead of PNG (experimental)
  -p --png             If SVG was selected, and you also want PNG, set this flag
  -o --outputDir       Directory to save files, will be created automatically, defaults to `cwd`
  -e --phantomPath     Specify the path to the phantomjs executable
  -t --css             Specify the path to a CSS file to be included when processing output
  -c --sequenceConfig  Specify the path to the file with the configuration to be applied in the sequence diagram
  -h --help            Show this message
  -v --verbose         Show logging
  --version            Print version and quit
[reia-mbp15:~] reia%

Example

you can find a lot of example of mermaid at http://knsv.github.io/mermaid/. Here's just a short one:

sequenceDiagram
Customer ->> HelpDesk: Case Open
Note right of HelpDesk: SR open via CRM
if there is no known PR
Then HelpDesk open a new PR HelpDesk->> ACE: Create a new PR Note right of ACE: Update the PR
and change PR status to
"info"

Tuesday, November 4, 2014

Running AppleScript from CLI

It is actually pretty simple to run AppleScript from CLI.
% osascript scriptname.scpt

Thursday, May 29, 2014

TCL and Expect Library

Source: http://www.tcl.tk/man/tcl8.5/tutorial/Tcl31.html

WORK IN PROGRESS

Preamble 

Well, today I have to write an "expect" script to automate some of the lab work that I need to do.  I already have basic library like the login procedure and etc done on a previous project.  Currently, I have that in a file and usually just "source ..." them in.  But why get stuck using just "source ...".  Its easy, but I don't think it is cool. LOL.  Let's try to look at some of the alternatives.

The following is a direct quote from Tcl31.html's tutorial.  The exact URL locates on the top of the page.

Using packages

The package command provides the ability to use a package, compare package versions, and to register your own packages with an interpreter. A package is loaded by using the package require command and providing the package name and optionally a version number. The first time a script requires a package Tcl builds up a database of available packages and versions. It does this by searching for package index files in all of the directories listed in the tcl_pkgPath and auto_path global variables, as well as any subdirectories of those directories. Each package provides a file called pkgIndex.tcl that tells Tcl the names and versions of any packages in that directory, and how to load them if they are needed.

It is good style to start every script you create with a set of package require statements to load any packages required. This serves two purposes: making sure that any missing requirements are identified as soon as possible; and, clearly documenting the dependencies that your code has. Tcl and Tk are both made available as packages and it is a good idea to explicitly require them in your scripts even if they are already loaded as this makes your scripts more portable and documents the version requirements of your script.


Friday, May 2, 2014

Running 32-bit software on Ubuntu 14.04LTS 64-bit

May 2nd, 2014 - Writing Android App

I am trying to play with Android SDK. The machine that I'm using is virtual 64-bit Ubuntu 14.04LTS running on top of VBox. The host OS is Apple MacBook Pro 15" 20011 vintage. May be I will get a MacBook Air later on.

I follow the instruction from http://developer.android.com to install 64-bit SDK for my ubuntu. The problem is that when I try to start "Eclipse", it complains that it cant find "adb". Which is confusing to me. When looking at "adb" itself, it shows that it is a 32-bit software instead of 64-bit software as the Android SDK is indicated.

To run 32bit executable file in a 64 bit multi-arch Ubuntu system, you have to add i386 architecture and install libc6:i386,libncurses5:i386,libstdc++6:i386 these three library packages.

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
sudo ./adb

Tuesday, January 28, 2014

Playing with my Juniper's router... PyEz

JUNOS PyEz is easy as pie...

Ok, may be not that easy.  But it is doable.

I was randomly browsing the net while waiting to upgrade my MX480 to the latest and greatest JUNOS 12.3R5.whatever....  I remember that I still try to learn my rope around Python and one thing leads to another... "PyEZ" on Juniper's techwiki...

I was hoping to just download the module and run off from techwiki, but unfortunately, I need to go to git to get it. Fortunately, the instruction is easy enough to do.  Only two commands to install the required modules on my Ubuntu system:
sudo pip install git+https://github.com/Juniper/ncclient.git
sudo pip install junos-eznc
My first try was unsuccessful and I got the following messages:
  Running setup.py egg_info for package lxml
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    Building lxml version 3.3.0.
    Building without Cython.
    ERROR: /bin/sh: 1: xslt-config: not found
    
    ** make sure the development packages of libxml2 and libxslt are installed **

Not included in the instruction is that I also need to install two additional packages:
  • python-dev
  • libxslt1-dev
Which on my Ubuntu system, it is easy enough to do:
% sudo apt-get install python-dev
% sudo apt-get install libxslt1-dev
After I install the two packages, the installation of the pyez was very smooth.
Jeremy's example in the installation page was pretty easy enough for testing. I highly recommend you to just try it in interactive mode like I did...
reia@ubuntu:~$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pprint import pprint
>>> from jnpr.junos import Device
>>> dev = Device(host='mysun.example.net', user='me', password='more0fme')
>>> dev.open()
Device(mysun.example.net)
>>> pprint( dev.facts )
{'2RE': True,
 'HOME': '/var/home/lab',
 'RE0': {'last_reboot_reason': 'Router rebooted after a normal shutdown.',
         'mastership_state': 'master',
         'model': 'RE-S-1800x4',
         'status': 'OK',
         'up_time': '17 hours, 51 minutes, 36 seconds'},
 'RE1': {'last_reboot_reason': 'Router rebooted after a normal shutdown.',
         'mastership_state': 'backup',
         'model': 'RE-S-1800x4',
         'status': 'OK',
         'up_time': '16 hours, 22 minutes, 55 seconds'},
 'domain': None,
 'fqdn': 'Sun-re0',
 'hostname': 'Sun-re0',
 'ifd_style': 'CLASSIC',
 'master': 'RE0',
 'model': 'MX480',
 'personality': 'MX',
 'serialnumber': 'JN1XXXXXXXXXX',
 'switch_style': 'BRIDGE_DOMAIN',
 'version': '12.3R5.7',
 'version_RE0': '12.3R5.7',
 'version_RE1': '12.3R5.7',
 'version_info': junos.version_info(major=(12, 3), type=R, minor=5, build=7)}
>>>
And I notice that my router has been upgraded. That's it for now.
Tata my friend.