Wednesday, November 30, 2016

Howto Install Laravel Using Composer

Following are instructions to install Laravel Framework 5.3.16 on a Centos Linux 7. The PHP Composer 1.2.2 is used to install all the dependency packages. Detailed instructions on MS Windows environment were initially prepared in previous blog Howto Install Laravel Framework using Composer.

The system on a x86 64-bit computer consist of
CentOS Linux 7.2
HTTPD 2.4.6-40.el7.centos.4
PHP 7.0.13
MySQL 5.7.16-1.el7

Step 1. Install Laravel

Login to a command line terminal (CLI) as a normal user (with sudo rights) and type

 $ sudo yum install composer  
 $ composer -V  

This installs Composer 1.2.2. Minimum requirement is PHP 5.3.2 as mentioned as Composer website.

Install Laravel

 $ sudo yum install composer  
 $ composer -V  

Create your first application called hello.

 $> composer create-project --prefer-dist laravel/laravel hello   

This install Laravel 5.3.16 as shown in the image below. The folder tests and vendor is not shown.

Listing in hello folder.



Step 2. Run Artisan Serve

Start local artisan server

 $ cd hello  
 $ php artisan serve  

Open a web browser and point to the provided URL http://localhost:8000

To allow access to this instance with a domain name such as tboxmy.blogspot.com, start the server with following command

 $ php artisan serve --host= tboxmy.blogspot.com --port=8000  

Step 3. View the Results in HelloWorld

Test Laravel with a helloworld file

Open a terminal and go to the project folder ->hello ->resources ->views
Create a file helloworld.blade.php with following text

1:   <!DOCTYPE html>   
2:   <html>   
3:    <head>   
4:     <title>Laravel</title>   
5:    </head>   
6:    <body>   
7:   Hello World!   
8:    </body>   
9:   </html>   

Display this "VIEW" when the URL is /hello by editing the file web.php in the project folder ->hello ->routes

1:   Route::get('/hello', function () {    
2:     return view('helloworld');   
3:   });   

Save the file and start the artisan serve.

Open a web browser and type the URL mentioned above in Step 2. E.g.
http://localhost:8000/hello

This displays the Hello World! page with HTML formatting from the file resources/views/helloworld.blade.php

Done

Tuesday, November 22, 2016

Raspbian Command Line Basics 102

This is continuation from Raspbian Command Line Basics 101


Here are 18 commands on configurations of Raspbian Jessie or Release 8.0 on a Raspberry Pi 2. This might work for other versions of Raspbian, as they are common Linux commands in most cases.

At the Raspbian terminal, users can access a whole load of information. These can be useful for troubleshooting graphics, program conflicts and networking issues.

GENERAL

Display your device name and operating system information
$ uname -a

Change directory
$ cd directoryname

List files n a directory
$ ls
or
$ ls directoryname

Restart background services
$ sudo systemctl daemon-reload

Display disk usage or free space
$ free
$ free -h

Display disk usage by partitions
$ df -h

Display contents of a file
$ cat filename
e.g. to display CPU type
$ cat /proc/cpuinfo

Display the system date and time
$ date

Edit a file with Vim or Nano
$ vi filename
or
$ nano filename

Schedule shutdown at specific time
$ shutdown -h 21:00
or reboot
$ shutdown -r now

Configure Raspbian
$ sudo raspi-config

PACKAGE MANAGEMENT

List installed packages
$ dpkg-query -l

To clear up disk space before updating
$ sudo apt-get clean

Update Raspbian system packages
$ sudo apt-get update

Upgrade installed packages
$ sudo apt-get dist-upgrade

Install a package
$ sudo apt-get install mypackagename
or
$ sudo apt-get install mypackagename -y

Remove an installed package
$ sudo apt-get remove mypackagename
or complete removal with its configuration files
$ sudo apt-get purge mypackagename

Search for a package online
$ apt-cache search mypackagename

Display information of a package
$ apt-cache show mypackagename


NETWORKING

Default networking file is configured at
/etc/dhcpcd.conf

And the dhcpcd controls the networking interfaces

Display existing network interface settings
$ ifconfig


Display network routing table
$ route 
or display all numericals
$ route -n

Changes to the static ip in configuration file requires restart of the dhcpcd
$ sudo dhcpcd -k
$ sudo dhcpcd

Display status of running network interfaces
$ sudo service networking status

Restart network interfaces. Required after changes to network configuration.
$ sudo service networking restart

When there is network but web browser display "Unable to resolve name". Edit the domain name server at /etc/resolv.conf

nameserver x.x.x.x


Saturday, November 19, 2016

Oppo F1s How To Change Looks - Part 1

Oppo F1s is a decent phone running Android 5.1. Very responsive to the touch and with a nice big screen.

It's got a few things that new users just must do to personalize to look cute. Since there are so many things for customisation,  I will list few must know things to default theme.

Add screens

Default it comes with 2 screen where you can swipe left or right to go to each screen. Screens are a great way to organise contents. As you can see below,  there are 3 circles above the camera icon which means there are 3 screen.

Select an icon on the screen for the new screen. In this example,  I choose Theme Store icon and as drag it, the screen editor appears at bottom of screen.


Drag the icon to a new screen and release. If the icons are still wobbly or jello like,  tab on an empty space of the screen and it should end the editing mode. 



Create folder on a screen

Folders allow you to group several icons together on one screen.  With option to name the folder,  everything get more organised. Folders are shown as an icon with a little downwards arrow by it's side.

In order to create a folder,  identify the 2 icons for a folder.  Press on one icon and drag it on the centre of the other icon.  The icons will then be displayed in editing mode with the name of the folder above.  Click on that name and change the folder name.  Click the check mark and tap an empty space on the screen.

Change theme

Themes provide a feel of icon shapes,  background and lock screen that consistent.
Press Theme store icon and select a theme or press the download theme button.




The download button is to choose installed icons themes on the system.  Next press on apply and watch your screen and icon change. Other changes may effect fonts and lock screen.



Done.



Friday, November 11, 2016

Yum error Cannot retrieve metalink for repository

Yum provides installation, upgrades and removal of packages on Linux such as Centos. It is used to install other package repositories too. Over time, some of the certificates for installation would have changed and thats where you get this error when running Yum.

In this example, the error indicate Epel repository cannot be retrieved.

"Cannot retrieve metalink for repository: epel"

Some sysadmins have decided not to use that repo totally as they do not use that repo. E.g. when updating a package, they use

# yum --disablerepo="epel" update httpd

Solution

  1. Clean yum cache
  2. update the ca-certificate packages while disabling that repository with error.

Clean yum cache
# yum clean all

Update ca-certificate packages



In my Centos 6.3, it required to updated these related packages.


Monday, November 7, 2016

Howto Start Lavarel and MySQL


Lavarel provide the tools to quickly create an MVC application. In this guide, lets generate the required database table of a class and retrieve data while keeping to MVC.

Background

Models are used to represent objects and Laravel associates it with a database table of the same name. E.g. a model called Customer (singular) will have a table called Customers (plural). Using the --migration option will also produce a file to manage the database.
Our Customer class will consist of the fields id, cname, phone, last_update and a timestamp.



Controllers provide the glue to Views and Models. Laravel helps to create controllers that are empty or CRUD ready in the directory app/Http/Controllers. CRUD ready meaning that the standard functions or also known as Actions are generated for each HTTP action;

GET - create, show, edit and index.
POST - store
PUT/PATCH - update
DELETE - destroy

Each Controller file needs to be told which namespaces or Models to use.

Routing determines the URL mapping to actions that Controllers are to provide. Route can also be directly to a View or to deliver specific HTML contents without any Controllers.

The Laravel config directory contains a file, database.php with default settings to SQLite, Mysql and Postgresql database. You just need to fill in the appropriate values for the database in use. This Howto will use MySQL database.

Pre-Requisites

Installed the following and are in working order

  • Apache2
  • PHP v7.0.12
  • Composer 1.2.2
  • Lavarel 5.3


To install Laravel, refer to previous posting http://tboxmy.blogspot.my/2016/11/howto-install-laravel-framework-using.html

Step 1. Configure Lavarel to use MySQL

Create a database in MySQL called hellocustomer and assign the user permissions. Create 2 to 3 rows of dummy data as this howto will need to retrieve these data.

Edit the file hello/config/database.php and configure database

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'hellocustomer'),
            'username' => env('DB_USERNAME', 'mysql'),
            'password' => env('DB_PASSWORD', 'somepassword'),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

Edit hello/.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=hellocustomer
DB_USERNAME=mysql
DB_PASSWORD=somepassword

Step 2. Create the Customer Model

1. At the project workspace directory, open a terminal and type

php artisan make:model Customer --migration

This will create

  • hello/app/Customer.php
  • hello/database/migrations/YYYY_MMM_DD_###_create_customers_table.php


2. Edit the table file in migrations (above) with all the required fields for Customer model.
3. Activate the migration file to generate Customer table in the database. Just type;

php artisan migrate

If the schema needs to be changed and database deleted after the above was created, just refresh the database, with;

php artisan migrate:refresh


Step 3. Create the CustomerController class

In order for the CustomerController class to retrieve data from the database, Eloquent provides the all() function, such as;
 $customers = Customer::all();  

An array of data rows are extracted to the variable $customers. No additional SQL coding is required.

At the terminal, type the following to generate the controller class app/Http/Controllers/CustomerController.php

php artisan make:controller CustomerController --resource

Edit CustomerController to use the Customer model by adding the "use App\Customer;" above class declaration as below;


use App\Customer;
class CustomerController extends Controller
{
 public function index()  
 {  
       //              
       $customers = Customer::all();  
       return View('customers.index')->with('cust', $customers);  
 }  

 public function show($id)  
 {  
       //              
       $customer = Customer::find($id);  
       return view('customers.show', array('customer' => $customer));  
 }  


Step 4. Create View for the Implemented Actions in Controller

Create a directory customers in resources/views and create the following 2 files

 <!DOCTYPE html>  
 <?php  
 // index.blade.php   
 ?>  
 <html>  
 <head>  
   <title>Customer index page</title>  
   <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">  
 </head>  
 <body>  
 Customers  
 <br/>  
 @foreach($cust as $key => $value)  
 <table>  
     <tr>  
       <td>{{ $value->id }}</td>  
       <td>{{ $value->cname }}</td>  
       <td>{{ $value->phone }}</td>  
                   </tr>  
                   @endforeach  
 </table>  
 </body>  

 <!DOCTYPE html>  
 <?php  
 // show.blade.php   
 ?>  
 <html>  
  <head>  
   <title>Customer</title>  
  </head>  
  <body>  
  <?php  
       if ($customer == null)   
       {  
             print "No data";  
             return;  
       }  
       ?>  
   <h1>Customer {{ $customer->id }}</h1>  
   <ul>  
    <li>Name: {{ $customer->cname }}</li>  
    <li>Phone: {{ $customer->phone }}</li>  
    <li>Last update: {{ $customer->last_update }}</li>  
   </ul>  
  </body>  
 </html>  

Edit routes/web.php file to use this new controller.

Route::resource('customer', 'CustomerController');

Step 5. Try them out

The Actions from our Laravel framework implementation can be listed with the command

php artisan route:list







Since you now know the URL for each Action we know to do the following displays for all customers and for each customer.

To call  INDEX action use the URL
http://localhost:8000/customers/



To call  SHOW action use the URL followed by a valid customer id.
http://localhost:8000/customers/1


Exercise:

This should take less than 15 minutes to complete.

Demonstrate use of database with Laravel. Create following Customer class below and display formatted data (create your own dummy data in the database).










Friday, November 4, 2016

Howto Install Laravel Framework using Composer

Laravel framework provides rapid development of a model-view-controller (MVC) with PHP programming language. Currently is at version 5.3 and is open source using MIT license.

Composer is a tool to easily retrieve packages required for most PHP projects and frameworks. Laravel can be found available in Composer at packagist.org. Detailed documentation for Composer can be found at https://getcomposer.org

This is a quick guide on installing Laravel then creating a page to display hello world!.

Installation environment for this How-to;
MS Windows 10
Apache2
PHP v7.0.12
Composer 1.2.2
Laravel 5.3

By the end of this guide, the following directories should have been generated.


Step 1: Installing Composer

Ensure Apache2 and PHP7 is already installed and working before starting this guide.

Download and install Windows Composer installer https://getcomposer.org/Composer-Setup.exe

Open a terminal and change to the installed PHP folder. Type

 $> composer -V  

(Or with the file composer.phar in same directory, type)
 $> php composer.phar  
This should display the version number of composer.
Update composer and check the version.
 $> php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"  
 $> php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"  
 $> php composer-setup.php  
 $> php -r "unlink('composer-setup.php');"  
 $> composer -V  

Step 2: Create an empty composer project 

Create a project folder called myproject.
Open a terminal and enter folder for myproject
Type
 $> composer init  

Choose default values, except following;
Package type: project
dev dependencies: yes
Search for a package: laravel/laravel

Press "Enter" until exit the interactive menu.

This will create a default json file for the composer. This step is only an example of creating a json file. Feel free to ignore this step.

Step 3: Install Laravel Framework and dependencies

Create a project folder called myproject, if you haven't.
Open a terminal and enter folder for myproject, and type.

 $> composer create-project --prefer-dist laravel/laravel hello  


This will do pretty much that same as Step 2 above, except that it will create the workspace called hello and load all the required libraries and plugins.

Laravel is installed in the folder hello.

Step 4: Start local server

Open a terminal and enter folder for hello, and type.

 $> cd hello  
 $> php artisan serve  

Laravel development server started on http://localhost:8000/

Open a web browser and type the URL mentioned above.
http://localhost:8000/

It displays the default Laravel page.

Step 5: Display a Hello World page

Open a terminal and go to the project folder ->hello ->resources ->views
Create a file helloworld.blade.php with following text

 <!DOCTYPE html>  
 <html>  
   <head>  
     <title>Laravel</title>  
   </head>  
   <body>  
  Hello World!  
   </body>  
 </html>  

Tell Laravel that to display this "VIEW" when the URL is /hello.
Edit the file web.php in the project folder ->hello ->routes

 Route::get('/hello', function () {    
      return view('helloworld');  
 });  

Save the file.

Open a web browser and type the URL mentioned above.
http://localhost:8000/hello

This displays the Hello World! page with HTML formatting from the file resources/views/helloworld.blade.php

Step 6: Display a Hello World text (without Views)

Tell Laravel to display some HTML when the URL is /hello2
Edit the file web.php in the project folder ->hello ->routes

 Route::get('/hello2', function () {    
      return 'Hello World 2!';  
 });  

Save the file.

Open a web browser and type the URL mentioned above.
http://localhost:8000/hello2

This displays the Hello World 2! text.

Happy trying out Lavarel.



Tuesday, October 11, 2016

Open Source Hardware Today

The spirit of open source software means providing access to the source code, friendly licensing models and community support (documentations, forums and social gatherings). Computer and electronic hardware have always been proprietary as it involved large sum of money and required access to specialised machines and technology in order to design and build hardware.

In October 2016, it is announced by Open Source Hardware Association the rollout of Open Source Hardware Certification Program (read more). Hopefully it will help to address the long time conflict of patent law with OSS licenses in regards to hardware. That's right, OSS relates to copyright laws in almost all cases I know, but when it comes to hardware, most of it refer to patent law.

The most well known license for open source hardware is the European Organization for Nuclear Research (CERN). CERN list their licenses, hardware repository and projects that use their license at http://www.ohwr.org


More projects on hardware can be found at
Makezine
Olimex
Raspberry Pi
Adruino

With the certification coming out, a growing list of open source hardware vendors and project, looks like the stars are shinning for open source hardware enthusiast and business.



Thursday, October 6, 2016

Learning to code for kids

Here are 5 websites to start the young minds with coding. In no particular order;

Scratch 

Use of the famous programming blocks of different shape and colours to do coding. Adobe Flash is required for the web interface.

CodinGame

Use web interface to complete snippet of codes. This is not for the uninitiated. You have a choice of using the text editor Emacs, Vim or the standard IDE that supports several popular programming languages. This includes C, C++, Java, Go, Paskal, PHP, Python and Ruby. If you are looking to learn logics and algorithms, this is it.




Code Academy

Provides programming courses for free. Personal learning plan and quizzes with advisor are included in the paid subscription. Its starts off with learn to HTML and CSS.


Code.org

Place to learn coding with contribution from many difference sources. Some element of Scratch with specialised themes and gamification to learn coding. Lots of resources for lesson plans.
A sweet start would be Coding with Anna and Elsa.


Alice

Create 3D animations and learn programming for those familiar with the use of computers. This product of Carnegie Mellon University teaches C++, Java and C#.



Any of these made it to your your favourite sites?

Thursday, August 11, 2016

Pokemon Go the Start of The Unity

Recently Pokemon Go, a location based game have taken the game industry by storm. Literally more people are getting up and going around in search of Pokemons, Poke stops, Gyms and other parts of the games. This is a little off open source topic, but its a rather attractive game using location base and augment reality.

Niantic Labs was founded by Google before it separate to a separate company known as Niantic. Pokemon Go is a successful product of Niantic as indicated by the number of installations.

Looking at the permission that must be allowed for the game to run, its literally having a access to a wide range of information. Millions of users are allowing access to Niantics.

Could this be used for big data? possibly the first signs of Unity, as in the Matrix?


Graphics on the different type of Pokemon in case you need to take on Unity in the future. How many of each type do you have? and whats the strongest?
  • Bug
  • Dark
  • Dragon
  • Electric
  • Fairy
  • Fighting
  • Flying
  • Normal
  • Poison
  • Psychic 
  • Water

Wednesday, July 6, 2016

NMap, SSH and Matrix the Movie

Matrix the movie is one of the coolest movie with concepts that provoke thoughts of technology and politics.

Ever thought that open source was involved? Surprise, surprise, trinity was referring to the use of Nmap and SSH exploits.

See http://www.theregister.co.uk/2003/05/16/matrix_sequel_has_hacker_cred


Monday, June 20, 2016

Backup Thunderbird 45 on MS Windows 10

Just after installing the Kubuntu Jaunty 9.04 Linux, its time to restore some of my stuff. Firstly, I need communications and this is via my Thunderbird.

Thunderbird email client allow access of emails from online email providers and a local storage of email. It may be necessary to move these local emails and local Thunderbird profile to another PC or to be saved as a backup.



Here is the manual method. Save the local configurations by copying the files as listed in these locations to the backup location.

  • Thunderbird 45.1.1
  • MS Windows 10

Backup

Step 1. Identify location of the files for backup.

There are a few ways to do this, one of which is to open Thunderbird menu (3 horizontal lines), click Options-> Account settings. Then follow the steps below.
1. Signature. Right click the email account-> Account settings. In the right window, look for
Attach signature from a file instead



2. Email configuration profile. Right click the email account-> Account setting ->Server Settings ->Local directory





3. Local folders for offline access. Right click the Local folders ->Server Settings ->Local directory



4. Digital certificates. Right click the email account-> Account setting ->Manage Identities...
Then choose the email profile(s) and click Edit and choose the tab for Security.


Step 2. Stop Thunderbird and compact all large folders.

Example,
Inbox
Sent

Empty all Deleted folders

Step 3. Copy files in Step 1 to the new location.


Restore:

Step 1:
Copy the directory profile back to the new system

Step 2:
In the terminal create an email profile that uses the old directory, type

thunderbird -profilemanager

(WIP)

Friday, May 20, 2016

Howto convert photos to line drawing with GIMP

GIMP provides a large tool set to edit photos. This software is provided with GNU License and is available to use on Linux and MS Windows computers.

Artistic look from photos can be created with a few steps in GIMP 2.8.8.

Start GIMP and open the photo (which is in colour).

Step 1: Select the photo.
From the main menubar, click Select ->All or press "Ctrl+A"

Moving dots/dashes should be around the photo.

Step 2: Remove colour from the photo.

Click the menu Colors ->Desaturate... and choose a shade of gray based on Lightness or Luminosity or Average. Click "OK"

Alternative method:
Click the menu Colors ->Hue-Saturation... and slide Saturation value all the way to left or -100.

Step 3: Strip gray tones

Click the menu Filters ->Edge-Detect ->Difference of Gaussians...
Default checks the boxes Normalize and Invert. Radius 1 value is 3.0 and Radius 2 is 1.0.

Note: At this point if it results in a blank image, remove the Alpha channel

Step 4: Raise the lines

Click the menu Colors ->Brightness-Contrast...

Increase brightness value and reduce contrast value until image appears. Click "OK"

Step 5: Enhance the light lines

Click the menu Colors ->Levels... and click "Auto".
In the graph like "Input Levels", slide the triangle till to left until the desired tone. Click "OK"

Done.


Thursday, March 17, 2016

Centos 6 Checklist on Systems Security

Linux Security Checklist

A reliable server is only as good as it is maintained and due processes applied. A systems security checklist template for Centos 6 mentioned below serves to meet the basic security requirements. A more stringent and targeted checklist can be developed further.

This mainly records existing system details and follow common practices. Some stuff like SELinux is mentioned as permissive as this is what I have at the moment. Details should be updated to specific server needs. Another useful checklist is for web application deployment and can be found at http://tboxmy.blogspot.my/2011/06/linux-security-checklist_14.html.

Centos 6 Checklist on Systems Security (link)

Contents of the checklist includes;

Section A. Details of the system
Section B. Services
Section C. Essential files
Section D. Examples.




Monday, March 14, 2016

NFS Commands 101


Refer to previous article Setup File Sharing with NFS on Centos Linux.

I find NFS version 3 is the most commonly used and uses remote procedure call (RPC) to manage connection between client and server. The service called rpcbind in Centos 6 has replaced portmap to handle RPC (see nfs4). Version 3 onward support files larger than 2 Gb size.

Whenever an NFS server is restarted not gracefully, the service rpc.statd notifies NFS clients. When quota is applied to the NFS, the service rpc.rquotad handles quota information.

The file /etc/exports define which directories are available to NFS clients. Each share is placed on a separate line and it indicates which client can access along with the options. Default users access a share as the user nobody, where this can be overridden in the /etc/exports option.

E.g. The following /etc/exports shares the directory /data with the client 192.168.1.45. The client may read and write and mounts synchronously.

/data 192.168.1.45(rw,sync)

Or user connect as its own user

/data 192.168.1.45(rw,no_root_squash,sync)

Default ports used by NFS are 2049 for the NFS service and 111 for RPC service.

Here are a list of NFS version 3 commands. Most are at the client side unless specified.

General NFS Commands

Start and stop NFS service
# service nfs start
Or
# /etc/init.d/nfs start
Or
# service nfs stop

Enable NFS service at boot
#chkconfig nfs on

Refresh NFS server shares from /etc/exports
# exportfs -r

Unload and reload NFS shares from /etc/exports
# export -a

Check support for NFS on the kernel. Did you forget to compile kernel with NFS support?
# lsmod |grep nfs
or
# grep -i nfs /boot/config

Check if list of commands are running
# rpcinfo -p

Display NFS statistics as client
# nfsstat -c

Display use of io
# vmstat -s

Mounting NFS

Display available NFS mounts
# showmount -e servername

Mount an NFS share
# mount -t nfs servername:/the/sharename

Display if the NFS mount is full or its free space
# df -k


Troubleshoot reference


Howto check Linux memory usage

Ever found a Linux suddenly having low free memory or none at all? This is something to check when the server suddenly starts slowing down or not able to complete processes.

Here are several method to diagnose and maybe identify a fix. Check the memory usage then identify the process causing the extreme usage. Next, work on that process configuration.


Check memory usage

Display available and used memory with 'free' command
# free
Or
# free  -m

The top live monitor
# top

Press m to display memory
Press Shift + m to sort by memory percentage
Press R to reverse the sort


List processes and amount of memory being used
# ps -e -o pid,vsz,comm=
Or
# ps -e -o pid,vsz,comm= | sort -n -k 2

Or
# ps aux  | awk '{print $6/1024 " MB\t\t" $11}'  | sort -n


View meminfo
# cat  /proc/meminfo
or
# vmstat -s

View the RAM device installed
# dmidecode -t 17


Check the process

List processes that open files
# lsof


Several TYPE of files are monitored

REG – Regular File
DIR – Directory
FIFO – First In First Out
CHR – Character special file

A description of the file is shown by FD
cwd – Current Working Directory
txt – Text file
mem – Memory mapped file
mmap – Memory mapped device
NUMBER – Represent the actual file descriptor. The character after the number i.e ‘1u’, represents the mode in which the file is opened. r for read, w for write, u for read and write.

List processes base on process names
# lsof -c ssh

List processes base on process id
# lsof -p 1234

Where 1234 is an example of the process id (pid).

Done

Tuesday, March 8, 2016

Boot Centos Linux to Windows

Centos 6 and 7 provide different approach for booting to a graphical windows interface known as X. Firstly, ensure the relevant packages to support display of windows where most of it are bundled as one of the popular Linux desktop environments.

Among the popular current desktops environments available are;

  • Gnome
  • KDE
  • Unity
  • Xfce
  • LXDe
  • Cinnamon
Here are the steps.

Centos 6 Approach


Edit the file /etc/inittab and change the number 3 to 5 as shown in the line below

id:5:initdefault:

Then reboot.

To start graphical windows without reboot, at the command prompt type

init 5
or
startx

Centos 7 Approach


Login as root and the prompt type

sudo systemctl set-default graphical.target

Then reboot.

To start graphical windows without reboot, at the command prompt type

sudo systemctl start graphical.target

Done

Install GIMP on Centos 6

Centos 6.6 provides the popular graphic editing software GIMP at version 2.6.9. The current stable release is GIMP 2.8 for those who seek the additional editing features (link). Existing Centos 6.6 does not have the required newer libraries to support GIMP 2.8.

The details of GIMP is described as below.

Name        : gimp                         Relocations: (not relocatable)
Version     : 2.6.9                             Vendor: CentOS
Release     : 8.el6_6                       Build Date: Thu 20 Nov 2014 02:06:25 PM EST
Install Date: Tue 08 Mar 2016 03:09:46 PM EST      Build Host: c6b9.bsys.dev.centos.org
Group       : Applications/Multimedia       Source RPM: gimp-2.6.9-8.el6_6.src.rpm
Size        : 48118103                         License: GPLv2+
Signature   : RSA/SHA1, Thu 20 Nov 2014 04:10:42 PM EST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem
URL         : http://www.gimp.org/
Summary     : GNU Image Manipulation Program
Description :
GIMP (GNU Image Manipulation Program) is a powerful image composition and
editing program, which can be extremely useful for creating logos and other
graphics for webpages. GIMP has many of the tools and filters you would expect
to find in similar commercial offerings, and some interesting extras as well.
GIMP provides a large image manipulation toolbox, including channel operations
and layers, effects, sub-pixel imaging and anti-aliasing, and conversions, all
with multi-level undo.


Flexibility on editing include availability of many brushes and patterns.




 Here are steps to install the standard GIMP version 2.6.9
 

Step 1: Install GIMP



# yum install gimp





Step 2: Install additional brushes and patterns

Install additional brushes and patterns. Brushes include swirls and text to enhance strokes. Patterns such as clouds and funnymess.

yum install gimp-data-extras

Start GIMP from the desktop menu. Click Applications ->Graphics ->GNU Image Manipulation Program




Done

Saturday, February 20, 2016

Install OSMC on Raspberry Pi2

Raspberry Pi 2 (RPI2) provides a flexible multimedia centre for movie streaming, watching youtube, using a web browser and options to addon many Linux applications. OSMC is one of the images that can be downloaded unto an RPI2 from osmc.tv (download page or FTP). This Debian Jessie based system is great at running the RPI2 and allow developers space to enhance to their needs.

The media player system KODI, provides an interface to multimedia contents such as movies, online TV, videos, photos and musics. KODI itself does not have any media contents, but due to its extensible nature, many developers have created plugins to access external contents and addons to extend its functionalities. Media contents could reside in the same device as KODI, in a local area network, stream from the internet or cached contents from internet. KODI 15 comes with the current OSMC.

* Consider OSMC as an upgrade of Raspbmc.

This is an update to previous post "Raspberry Pi: Getting Started with OSMC" and I do not expect it to go into too much details. When I mention OSMC, it might also refer to KODI as its typically the only screen seen when running this RPI2.

Step 1: Starting OSMC

Download OSMC image from raspberry.org and image copy the .img file to the blank SD card. Tools such as Win32 Disk Imager can be used for this purpose.

Plug SD card into RPI2 and start RPI2 (already have internet connection).

Automatically start installation process.


It will reboot once installed successfully.

Step 2: Basic configuration

The default layout uses OSMC skin. Below is the OSMC main menu screen. Default appearance is handled by the skin called OSMC.


 It shows the following options;
  1. Videos
  2. Music
  3. Pictures
  4. My OSMC
  5. Favourites
  6. Programs
  7. Settings
  8. Power

Configure Screen size

The screen display may appear outside of the screen area. Change the zoom size until everything meets your satisfaction. From OSMC home page, click Settings ->Appearance ->Skin. Choose your zoom level and press Esc key until back to OSMC main menu.


Configure Timezone

Configure the timezone for correct time display. Click Settings ->Appearance ->International. Choose your region and the OSMC time should be update instantly.

Configure Skin

Default skin OSMC can be changed to KODI's default skin called Confluence. From OSMC home page, click Settings ->Appearance ->Skin. Choose skin as confluence and press Esc key until back to OSMC main menu.

More notes from KODI website: Quick start guide, Home screen controls,

Step 3: Add Youtube addon

In Videos menu there is an option to link your Youtube account with OSMC. This allows viewing of all your Youtube channels. From the OSMC main menu, click Videos ->Video add-ons ->Get more... ->Youtube

Click Install

Click launch. (From the OSMC main menu, you can click Videos ->Video add-ons to watch Youtube).

Follow the instructions on screen.
One of this includes accessing youtube.com/activate on a PC to enter the code given by the add-on in OSMC.

Troubleshooting:

1. Mode Not Supported

If after installation process, RPI2 boots and screen displays a message "Mode Not Supported", it means the display resolution was not automatically detected correctly. This happens on one Samsung TV.

Solution:
SSH into the OSMC and edit  /boot/config.txt
See command line tips at Raspbian Command Line Basics 101

Updated file for mode CEA
gpu_mem_1024=256
hdmi_ignore_cec_init=1disable_overscan=1
start_x=1
hdmi_group=1
hdmi_mode=20
disable_splash=1
dtoverlay=lirc-rpi:gpio_out_pin=17,gpio_in_pin=18

ALTERNATIVE Updated file for mode DMT
overscan_top=16
hdmi_mode=4
gpu_mem_1024=256
overscan_right=24
force_turbo=0
over_voltage_sdram=0
config_hdmi_boost=4
disable_overscan=1
initial_turbo=0
start_x=1
hdmi_group=2
sdtv_aspect=0
overscan_bottom=16
overscan_left=24
disable_overscan=0
hdmi_force_hotplug=1
arm_freq=900
sdram_freq=450
core_freq=450
hdmi_ignore_cec_init=1
over_voltage=0

2. Youtube add-on errors/issue.

Successfully login after the 2 google app authorisation, but displays empty list and
Display error exceeded quota (of some sort)

Solution:
Step 1: Activate the Google API v3
All Google App requires API v3, as derived from forum posting #2904.

Login to your google developer account and enable the above API.

Step 2: Use your own browser key, Oauth id and secret.
Looks like the default developers combination of above does not allow too many to use it. In posting #2847.

Login to your google developer account and create the above. A new project is created if none is created yet.

The newly created info from above should be updated in the file login_client.py that is found in /home/osmc/.kodi/addons/plugin.video.youtube/resources/lib​/youtube/client/

Find the line as below and edit the key, id and secret values.

'youtube-for-kodi-15': {
            'system': 'Isengard',
            'key': 'The_browser_key',
            'id': 'The_oauth_id_.apps.googleusercontent.com',
            'secret': 'The_oauth_secret_word'
        },

Done

Wednesday, January 20, 2016

RPI2 - Dashing Dashboard Installation Tutorial


Dashboard provide a quick view of information on the system. This can be a desktop application or web based. One such example on Raspberry Pi 2 is Dashing which is based on the Sinatra Framework and Ruby.

The Sinatra Framework from http://sinatrarb.com provides web application development quickly on Ruby. Example of installation on Ruby;

$ sudo gem install sinatra


Pre Installation checklist


  1. Raspbian Jessie
  2. Ruby


Installation of Dashboard on Dashing.

Step 1: Install Dashing.

$ sudo apt-get update
$ sudo apt-get install ruby-dev
$ sudo apt-get install ruby2.1-dev
$ sudo gem install bundler


Install Dashing 1.3.4 and create a new project called my_dashboard_project.

$ sudo gem install dashing



Step 2: Create a new project space

$ dashing new my_dashboard_project
$ cd my_dashboard_project
$ ls -l
total 36
drwxr-xr-x  6 pi pi 4096 Jan 20 12:34 assets
-rw-r--r--  1 pi pi  339 Jan 20 12:34 config.ru
drwxr-xr-x  2 pi pi 4096 Jan 20 12:34 dashboards
-rw-r--r--  1 pi pi  122 Jan 20 12:34 Gemfile
drwxr-xr-x  2 pi pi 4096 Jan 20 12:34 jobs
drwxr-xr-x  2 pi pi 4096 Jan 20 12:34 lib
drwxr-xr-x  2 pi pi 4096 Jan 20 12:34 public
-rw-r--r--  1 pi pi   65 Jan 20 12:34 README.md
drwxr-xr-x 11 pi pi 4096 Jan 20 12:34 widgets


Change your directory to my_dashboard_project and bundle gems

$ bundle

Display installed gems

$ bundle show

Step 3: Start the dashing server


$ dashing start

Point web browser location at http://localhost:3030/sample


Whats next?

There are additional widgets that can be installed and new dashboards can be created. Here is an example of adding a widget from dashing.

Installing Server Status Squares widget with GIST_ID = 9588819

$ dashing stop
$ dashing install 9588819

From server status squares widget, copy the file server_status_squares.erb to the dashing dashboard directory in the project created above.

$ cp server_status_squares.erb dashboards

Point web browser location at http://localhost:3030/server_status_squares






WIP

Reference:
Dashboard on PI
Tutorial on Sinatra: Sinatra docsJust do it, Singing with Sinatra.
Dashing: Shopify,

Monday, January 18, 2016

Android Studio - Proguard Error Shows Unable to compute hash

In Android development, the standard development kit includes a tool to shrink, optimise and obfuscate the APK. This tool is known as Proguard.

Android Studio will provide the options to use Proguard if it is enabled. However, some classes or files do NOT like to be optimised and obfuscated. In particular Javascript files and reference to classes that do not exist in the path. Here is an example of how the error message may appear when building the signed APK on Linux & MS Windows.

Linux

Error:Execution failed for task ':app:packageMinirelease'.
> Unable to compute hash of /usr/development/BakersPercentage/app/build/intermediates/classes-proguard/minirelease/classes.jar

MS Windows

Error from proguard during build
Since the problem is a warning on GMS packages, I resolved on Android Studio 1.4 as follows;

Step 1: Verify project works

Open the project and make sure it can build without errors. 

Step 2: Edit build.gradle (Module: app)
Copy the existing release build type and paste as a new build release named minirelease (or any name you fancy).

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
        minirelease {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
    }


Step 3: Edit proguard-rules.pro

Add the following lines

 -keep class com.google.android.gms.** { *; }
 -dontwarn com.google.android.gms.**


Step 4: Build Signed APK

In Android Studio menu, choose Build-> Clean Project

Build-> Generate Signed APK...
Enter Key details and click Next.
In Build Type: choose minirelease.
Click Finish.


Done.

Friday, January 15, 2016

Android http audio streaming and MediaPlayer

MediaPlayer class provides a player for local files and online streaming. Its a pretty flexible class and allows syn and asyn calls to suit almost every type of needs.

Formats supported by Android is at http://developer.android.com/guide/appendix/media-formats.html

There are cases where online streams can be played on an Android emulator but not on actual Android device. This happened for Samsung Galaxy S5 with Android 5 OS.

This is what I found;


  1. There are two type of AAC streams in my list of sites. Streams using AAC-LTP AAC with SBR+PS doesnt work but AAC-LC is played satisfactorily.
  2. Audio in MP3 plays fine on emulator and actual Android device.


There are other APK that managed to play the same audio streams on That S5. Probably there is another type of mediaplayer-like class to stream audio with support of the AAC-LTP.

Conclusion if MediaPlayer stream doesnt play over HTTP
  1. Try to play the stream on VLC player and see if it works. Verification process.
  2. Seek alternative stream format if one doesnt work. Remember, only MP3 and AAC-LC works.
  3. Incorporate a decoder to manage the unsupported format. 
  4. Consider to use AudioTrack instead of MediaPlayer. This will require manual assignment of the codec and audio format.

Raspberry Pi 2 and a VGA monitor

The Raspberry Pi 2 (RPI2) model B (more details) comes with many input/output connectors and of which its display output is using HDMI type A. This HDMI is also known as Full HDMI.

Model B is the big brother of Model A+ that is much more cheaper for specific implementation in an embedded project where the most minimal use of electrical power is needed.

The RPI2 can be hooked up to a decent monitor or projector using VGA connectors. All that is needed is a HDMI to VGA adapter. This adapter may comes with additional functions like audio output, additional power source or USB. Price differences are huge but here is an example that I got from online and it works just fine with the NEC AccuSync LCD52v monitor.

HDMI to VGA cable plugged to RPI2 and female VGA.


Done.


Blog Archive