Tuesday, September 29, 2015

Tutorial on Multiple Fragments in Activity

Here is an example to describe in codes how to create Fragment classes with Android Studio 1.4.

I wanted to be able to receive Button events and switch the Fragment depending on user selection. Need to be careful with rendering the layouts lower than API 23, as it did not generate the Design view properly.

Android Fragments in an Activity



Friday, September 25, 2015

Notes on the Sunshine app

Reviewed back lessons over last few months.

"Notes on Udacity Developing Android Apps"

Biggest problem was not passing the correct object to the ViewList. It kept giving a null error upon running the application.

The logging system was truly helpful for errors at runtime.


Upgrade to Android Studio 1.4 RC2

That was fast, RC1 was out in early September 2015 and shortly after that RC2 is released on 23 September. View the upgrade installation for Canary channel, RC1 at "Upgrade to Android Studio 1.4 RC1". Upgrade was smooth and without any problem recompiling target API 21 apk.

RC2 provide bug fixes and includes;

  • Update to the Theme Editor (using style.xml files)
  • In performance monitors it includes GPU and network profiler
  • The Vector Asset Wizard creates Android XML vector drawables, icons, from SVG files
  • Improved Android permission checks 
It is stable in terms of use and will surely provide a good experience for first time Android developers. With Android Studio 1.4, education institutions will surely be able to introduce Android Programming to a more advanced level, similar to how C++ was widely used.

Here are steps to upgrade RC2 from RC1;

Step 1: Check for updates

Start Android Studio and in the menu choose Help-> Check for Updates...
Click "Update and Restart". Ensure you have administrator rights to update the application or accept the request to update if such a request window appears.


Step 2: Restart Android Studio

This would be automatic if all went well. Verify RC2 is installed in the About.


Done.






Monday, September 21, 2015

Upgrade to Android Studio 1.4 RC1

Just saw there is an update to Android Studio to version 1.4RC1.

In existing Android Studio 1.1, update can be done easily with these steps;

(Tested on MS Windows 8.1)

Step 1: Update Android Studio

Open existing Android Studio (in this case its version 1.1) and click "Check", which is at the bottom of the Android Studio start page.


Step 2: Update configuration

After it searches for update on the Internet, click "Update and Restart"


After it has installed the update, choose to import my settings from a previous version (keep existing configuration).


Step 3: Update Plugin and other components

Platform and Plugin Updates, click "update". Click "Update now".



Click "Exit Studio and launch SDK Manager".
Choose "Install .. packages..." button. Choose ".


In Choose Packages to Install, choose "Accept License and click Install. My case above, it took 2.9GB of downloads.

Start Android Studio and complete rest of installation.

See an example of creating an Android Studio Project.

Troubleshooting:

Problem 1. After creating a new project, there is an Gradle sync error:

Warning:The project encoding (windows-1252) does not match the encoding specified in the Gradle build files (UTF-8). This can lead to serious bugs.

Solution: Upon new installation, the default IDE encoding uses Windows-1252 instead of UTF-8 as in project files. Change this from Android Studio menu File-> Settings-> Editor->File Encodings

Change the default encoding for project files to UTF-8. Click OK. Restart Android Studio and create a new project.


Problem 2: Rendering Problems.


Build the project.


Done.


Sunday, September 20, 2015

Samsung S5 Wifi not connecting automatically

Samsung S5 is a powerful Android mobile phone. In May 2015, the S5 received an update to Android 5.0 but has since had a problem with the wifi.


The smart network switch automatically switches from wifi when it gets weak, to mobile data. Usually, to save on mobile data its a good idea to turn it off. This way, even if wifi is weak it still stays on until signal is lost.

It can connect to wifi. However even after choosing smart wifi, it does not automatically reconnect when returning to the most wifi access point (AP) that it has saved the password. I say most because it can connect to open public wifi like Starbucks.

Previously, before the upgrade it was able to connect without problem.

Even resetting to factory did not help. Probably had something to do with me restoring my backup.

Here is how I got it working, clearing the S5 phone cache.

Step 1: Power off the S5

Step 2: At same time hold down following keys;
Volume up, power on/off, Home.

When it vibrates or see the galaxy start screen, release the power on/off.

Step 3: clear cache and restart
Use the volume key to select clear cache. Press the power button.

Once it says cache cleared, use volume button to select restart of phone and press power button.

Done.

Thursday, September 17, 2015

Howto Screenshot Desktop

The print screen key or "PrtSc" can be used to create a screenshot of the desktop and windows. This will activate gnome-screenshot from the gnome-utils package.

Gnome-utils contain;

  • dictionary
  • disk usage analyser
  • screenshot tool
  • search 


By default on a server setup of Centos Linux 6, the screenshot is not installed. This can be done easily.

Step 1: Install gnome-screenshot

As a admin role (root) at the terminal, type
# yum install gnome-utils

Step 2: Take screenshot of desktop or active windows

Screenshot of desktop
Press the print screen key or "PrtSc"



Screenshot of active window
Hold "Alt" key and press the print screen key or "PrtSc"

Edit the graphics name and press Save.

Delayed screenshot
This is useful if the screenshot can only be taken without user intervention.

  1. On desktop menu click Applications-> Accessories-> Take Screenshot
  2. Choose which area of desktop to take screenshot and enter the number of seconds for "Grab after a delay of ___ seconds.
  3. Click "Take Screenshot"



Done.





Paint program on Centos

Linux comes with open source software (OSS) for graphics editing, such as XPaint, GIMP and Tuxpaint. Vector editing can be done with Inkscape and xfig.

XPaint is a light weight program to do simple graphics editing and carries the GPL license.

Currently maintained by Jean-Pierre Demailly, but as stated in the "About" message, not to send bug reports.

Installation of XPaint (currently version 2.9.9.4) on Centos Linux 6.2 64 bits is quite straight forward.

Dependencies;

  • Xawd3d 1.5
  • gv 3.7.1
  • linXaw3dXft 1.6.2b
  • netpbm 10.47.05
  • psutils 1.17


Step 1: Install XPaint

Login with admin role (root) and type

# yum install xpaint
type y and press Enter

Step 2: Start XPaint

On the Centos Linux desktop, choose Applications-> Graphics ->XPaint


Click "Canvas" button and choose "New Canvas"




Tips on initial use of XPaint


Open an image to edit
File-> Open image...

Drawing lines, rectangle, circles, polygon
Click the Tool icon and choose the drawing tool.

Done.

Tuesday, September 15, 2015

Howto Install WordPress 4 on Centos Linux 6


WordPress in a PHP based content management system licensed under GPL v2. Since it has been around for a long time, there are many forums, blogs and video to help users and developers.

Functions:
  1. Create web pages without needing to know HTML
  2. Provide blog tools
  3. Themes to quickly create different look and feel
  4. Plugins to extend its functionalities
  5. Mobile ready site
  6. Provide multiple authors to manage their own contents.

WordPress 4.3 has just been released and here is a guide to install on Centos 6.4

Pre-installation recommendation
PHP 5.4 (works on 5.3.3)
MySQL 5.5 (works on 5.1)
mod_rewrite in Apache module
Bind-utils (works on 9.8.2)

Step 1: Obtain WordPress

Open a terminal and download the WordPress installation file.

$ wget --no-check-certificate https://wordpress.org/latest.tar.gz
$ tar xvzf latest.tar.gz
$ ls wordpress

Copy the whole folder to the web server directory. Example if the web server runs with permission for user apache.
$ mkdir /var/www/html/wp1
$ cp -r wordpress/* /var/www/html/wp1
$ chown -R apache.apache /var/www/html/wp1

Read the readme.html file with a web browser.


Step 2: Configure MySQL and create wp-config.php

Create the database wp1 in MySQL
$ mysql -u root -p
> create database wp1;
> /q

Open a web browser with URL to the installed page of WordPress.

http://servername/wp/
or
http://servername/wp/wp-admin/install

Fill the fields and click Submit.


Click Run the Install.

Fill the 5-minutes WordPress Install information
  • Site Title
  • Username
  • Password
  • Confirm password
  • Your E-mail
  • Privacy
Click Install WordPress.

Click Log In.

Enter the admin username and password.

View the admin user's dashboard.

Restart apache web server.
$ sudo service httpd restart

Step 3: View the site

Enter in the web browser URL
http://servername/wp1



The default left panel list;
  1. Site name
  2. Search tool
  3. Recent post
  4. Recent comments
  5. Archives
  6. Categories
  7. Meta (Site Admin, Logout, Entries RSS, Comments RSS, WordPress.org)

Troubleshoot

Problem 1: When choosing to add a new theme, the following error is displayed.
"unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums."

Solution: Ensure the server can connect to https://downloads.wordpress.org site. Restart Apache web server.

Problem 2: Pages are blank, and there are no error or warning messages.

Solution: Turn on the debug by changing the value false to true in /var/www/html/wp1/wp-config.php

define('WP_DEBUG', true);

Done.

Wednesday, September 9, 2015

Tutorial on Linux Shell Fundamentals

Most Linux admin and developers on Linux will benefit from knowing some shell scripting skills.

In most Linux, the shell is run on BASH. There are a few other shells out there but the default is BASH which I will introduce the basics here.

Gain access to a Linux terminal or also known as the command line terminal (CLI) and follow along these topics.

Fundamentals 1 (START)
  1. Getting started
  2. Creating a script
  3. Comments, printout and local strings
  4. Builtin variables
  5. Backup a folder
  6. Separate variable names and back slash
  7. Linux command in scripts
  8. Function basics
  9. Script arguments
  10. Accepting user input
  11. Simple if/else decision
Fundamentals 2 (START)
  1. The while loop
  2. Array variables
  3. Read from a file
  4. The for loop
  5. The until loop
  6. Find plain text files
  7. Quick menu input with select
  8. The case to create a menu
  9. Formatted printing with printf
  10. Print a line full length of screen


--

Monday, September 7, 2015

Display Dnsmasq status on Nagios

This article is an example of adding a custom process status in Nagios here the server (10.10.2.1) is separate from the host (10.10.2.2). In Nagios reference there are lots of option for configurations.

Dnsmasq as a light weight alternative to named, will appear in the linux process. E.g. when issuing the command ps -C dnsmasq

Pre-configuration checklist:

Ensure NRPE is installed and working on the host.

Step 1: Update nrpe.cfg with following;

# vi /etc/nagios/nrpe.cfg

Add the line
command[check_dnsmasq]=/usr/lib64/nagios/plugins/check_procs -C dnsmasq -w 5 -c 10

Save and test the new nrpe command;
# /usr/lib64/nagios/plugins/check_procs -C dnsmasq -w 5 -c 10
PROCS OK: 1 process with command name 'dnsmasq'


Restart nrpe
#service nrpe restart

Step 2: Add this service to the Nagios host

# vi /etc/nagios/servers/server1.cfg

define service{
use generic-service
host_name lbserver2
service_description Dnsmasq
check_command check_nrpe!check_dnsmasq
}

Save and restart Nagios


These 2 step works for any services that the linux ps command can detect.

Install Nagiosgraph on Centos 6

This article is on how to install Nagiosgraph on Centos.

Nagiosgraph is a plugin to Nagios and it provides graphical display of information captured by Nagios.

Installation environment:
Centos 6.5 x86_64
Nagios version 3.5.1-1
Pre-requisite perl modules: rrd tool 1.4+, Nagios::Config, GD, Object

Step 1: Prepare Nagiosgraph 1.5 for installation

# wget http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz
#  tar xvzf nagiosgraph-1.5.2.tar.gz
#  cd nagiosgraph-1.5.2
# less README

Install Perl module if havent installed.
# ./install.pl --check-prereq
# yum install perl-rrdtool perl-GD perl-Nagios-Plugin
# cpan Nagios::Config
If there are many modules not installed, just press Enter (Yes), unless you have other config.

Check all dependencies are met.
# ./install.pl --check-prereq


Step 2: Install Nagiosgraph source

# install.pl --prefix=/usr/share/nagiosgraph
Follow the instructions online. I choose the default values where nagios and httpd (apache) files were not updated automatically.

Step 3: Post configuration

If in step 2, it was chosen to not modify apache and nagios, then following must be configured. All instructions are printed at end of the installation of Step 3.

nagios.cfg
In the nagios configuration file (nagios.cfg),
    add/change these lines:
# vi /etc/nagios/nagios.cfg

Edit value for
process_performance_data=1

Add following lines
# process nagios performance data using nagiosgraph
service_perfdata_file=/tmp/perfdata.log
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=30
service_perfdata_file_processing_command=process-service-perfdata-for-nagiosgraph

template.cfg
# vi /etc/nagios/objects/templates.cfg
define service {
        name    graphed-service
        action_url      /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
        register 0
}

command.cfg
# vi /etc/nagios/objects/commands.cfg

# command to process nagios performance data for nagiosgraph
define command {
  command_name process-service-perfdata-for-nagiosgraph
  command_line /usr/share/nagiosgraph/bin/insert.pl
}

Host service files. E.g. for servername server1, append to show the graph service
vi  /etc/nagios/servers/server1.cfg
define service{
use generic-service,graphed-service
host_name applicationser1
service_description Current Load
check_command check_nrpe!check_load
}

* In the apache configuration file (httpd.conf),
    add this line:

include /usr/share/nagiosgraph/etc/nagiosgraph-apache.conf

Restart nagios to start data collection:
# service nagios restart

Restart apache to enable display of graphs:
# service httpd restart
Nagioschart: Chart icon in Nagios page

Nagioschart: Configuration page

Troubleshoot

Check graphs are displaying data, open a web browser and enter the URL
http://serversite/nagiosgraph/cgi-bin/show.cgi

Check RRD is collecting data with the command
# ls /usr/share/nagiosgraph/var/rrd

Check the nagios configuration files for errors
# /usr/sbin/nagios -v /etc/nagios/nagios.cfg

To enable graph links and mouseovers, see README sections:
       Displaying Per-Service and Per-Host Graph Icons and Links
       Displaying Graphs in Nagios Mouseovers

Thursday, September 3, 2015

Howto add Dropbox as Backup to Kodi - OSMC on Raspberry Pi 2

This is generally for backup purpose.

Step 1: Create API in dropbox

Login to dropbox.com or create an account if you haven't.
Go to the URL https://www.dropbox.com/developers/apps
Click "Create"
Choose "Dropbox API app"
In Can you app be limited to its own folder, choose "Yes"
App Name: "Kodi backup"
Click check box for "I agree to...conditions"
Click "Create app"

Write down the values for
App key and App secret.


Step 2: Configure Dropbox in Kodi

Open the Kodi screen and click Programs ->Get more...
Choose "Backup"-> "Install"
Click "Configure", in tab "General", change Remote path type to "Dropbox".
Enter values for Dropbox key
and Dropbox Secret
Click "ok"
Click "Launch"


Step 3: Start the backup

AT THE KODI SCREEN

A popup window "XBMC Backup - Mode" will appear, choose "Backup"
DO NOT CLICK "OK"

Step 4: Locate dropbox authorization
AT THE SSH TERMINAL
Using SSH tool like Putty, login to the OSMC Raspberry Pi and look for the dropbox authorization key in the file kodi.log.
Type
$ grep dropbox /home/osmc/.kodi/temp/kodi.log


AT THE PC WEB BROWSER
Copy that URL to a web browser and when the API request appears, click "Allow"

Step 4: Start backup

Return back to the screen in Step 3 and click "Ok"

Backup should begin.

Check dropbox for a new folder with the backup contents in
Apps/Kodi backup

Done.

Other stuff to do with Dropbox is to stream your home videos.
**To access files on dropbox**
Open the Kodi screen and click Programs ->Get more...
Choose Dbmc (Dropbox add-on)
Click "Install"

Once Dbmc has completed installation, click Dbmc (Dropbox add-on)
Click "Configure"

Tuesday, September 1, 2015

Setup Centos as Nagios clients

Centos Linux servers can be monitored by Nagios remotely. This typically provides information of ping response, services running and system information.

The setup is fairly straight forward assuming Nagios server IP is 10.10.2.1 and uses port 5666.

Step 1: Install Nagios plugins and NRPE.

Read the NRPE documentation.
Login to the nagios host, e.g. 10.10.2.2
# yum install -y nagios-plugins-all nrpe net-snmp

Edit /etc/nagios/nrpe.cfg with these 2 values

server_address=127.0.0.1
or the nagios IP

allowed_hosts=10.10.2.1
or the nagios IP

Example to enable monitoring of http is to have this line;
command[check_http]=/usr/lib64/nagios/plugins/check_http -I 10.10.2.2 -w 5 -c 10

Step 2: Start NRPE

# service nrpe start
# chkconfig nrpe on

Test with
 /usr/lib64/nagios/plugins/check_nrpe -H 10.10.2.2 -c check_load

Step 3: Allow monitoring through firewall

E.g. if using IPTABLES, make it as a rule at the top
# iptables -I INPUT 2 -p tcp -m tcp --dport 5666 -j ACCEPT
# iptables -L |grep 5666
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:5666

# service iptables save

Step 4: Configure Nagios server

Enable the services in the Nagios server, in this example 10.10.2.1
# vi /etc/nagios/servers/server1.cfg

define service{
use generic-service,graphed-service
host_name server1
service_description Http
check_command check_nrpe!check_http!-w 5 -c 10
}


Post installation

Check the service is running
# netstat -anlp |grep nrpe
tcp        0      0 10.240.1.14:5666            0.0.0.0:*                   LISTEN      12467/nrpe
unix  2      [ ]         DGRAM                    14250318 12467/nrpe

From the nagios server, test with 
/usr/lib64/nagios/plugins/check_nrpe -H 10.10.2.2

this should return the NRPE version.

/usr/lib64/nagios/plugins/check_nrpe -H 10.10.2.2 -c check_http

this should return the http check at the host.


Self reminder: TODO check_postgres source github

Blog Archive