Author:

Journal Entry – 07092016

Journal Entry – 07092016

I have now replace dokuwiki with wordpress, and so far I am happier with wordpress than with dokuwiki. I feel that it makes it easier for me to focus on what matters more than spending time trying to fiddle with a bunch of stuff and not really accomplishing alot. Ansible is coming along slowly and I will update my progress on the Ansible post. I have already started thinking about moving my mail system from postfix/devcot -> postfix/dbmail.

On the cello front, I found a new youtube channel Sarah Joy Music Tutorials/Music Videos some of the tutorials she posts very helpful to me. For example, the stretching exercise she has posted on her site or Five practicing mistakes. On Suzuki Book #2 Minuet #3 I have been practicing that for two months now, and I feels like I am getting better with it. It definitely a challenging piece along with the pieces that my teacher, Mr. Ma, has me working on as well. But, I feel good about. Although, I am thinking of posting some of my playing on youtube and sharing with my friends!

I met with my Jessica this week for our session. Most of the time during our session we talk about my journal and what does it mean to me, what is the goal of it, and what do I expect to get out of it. The goal is to understand why do I overreact to curtain issues, to help me understand about it and how to deal with it, and what I want to get out of it to be a better person. We have mention that we may need to change the focus from Relationship coach to psychotherapy. I felt that at first I did not need it, that I am ok without it. But, now thinking about, I guess maybe I should venture into it deeper to see if I can have a healthier relationship with my self. In addition, try to deal or come to terms with the unstructured parts of my life or events in my life. I guess time will only tell to see how this will work out for me.

So, Cassie and I decided to expand our family and now where adopting a cat. Her name is potato.

Female Siamese Brown 2 years old
Female, Siamese, Brown, 2 years old

I am still a little apprehensive about potato, but excited to adapt! I have talk to my friends about adopting a cat they give me a few advice here and there. More news to come!

I got play Magic night with Ian, Adrian, and Jim! It was a great time playing with them, although I have to admit, I was getting murdered in the game as I could not keep a creature in play for more than two turns. But, in the end, it really did not matter if I win or lose, spending time with my friends or my girlfriend Cassie means a lot more! I also, schedule a romantic evening with Cassie on the 15th of this month at the McCormick and Schmicks restaurant in San Jose. I’m excited about it and it’s been a long time since we have one.

Working with sqlite in Python

Working with sqlite in Python

#!/bin/python

import datetime
import timedelta
import os.path
import sqlite3
import sys

#Global Variables
DBPath='test.db'

#from datetime import datetime, timedelta
#then = datetime.now() - timedelta(hours = 2)
#now = datetime.now()
#(now - then) > timedelta(days = 1)
#False
#>>> (now - then) > timedelta(hours = 1)
#True

StuffToLoad = [
	(0 , 'example.domain.com'  , 'Maintenance' ,'2014-08-10 15:07:15.067766'),
	(1 , 'example2.doman.com'  , 'Maintenance' ,'2014-08-10 15:07:15.067766'),
	(2 , 'exmaple3.domain.com' , 'Maintenance' ,'2014-08-10 15:07:15.067766'),
]

def CreateDB():
	print "Creating Database....."
	conn = sqlite3.connect(DBPath)
	conn.execute('''CREATE TABLE MInMant (ID INT PRIMARY KEY NOT NULL, Machine TEXT NOT NULL, HostState INT NOT NULL, date CHAR(50))''')
	conn.commit()
	conn.close()

def InsertDB(x):
	conn = sqlite3.connect(DBPath)
	c = conn.cursor()
	t = ('Maintenance',)
	c.execute('SELECT * FROM MInMant WHERE HostState=?', t)
	c.executemany('INSERT INTO MInMant VALUES (?,?,?,?)', StuffToLoad)
	conn.commit()
	conn.close()

def PrintDBContents():
	print "DEBUG PrintDB Contents"
	conn = sqlite3.connect(DBPath)
	c = conn.cursor()
	for row in c.execute('SELECT * FROM MInMant'):
	        print(row)

#We start out program
#if os.path.isfile(DBPath) == 'True':
CreateDB()

#Load data into our DB
InsertDB(StuffToLoad)

#Print data from our DB
PrintDBContents()
Linux tib bits…

Linux tib bits…

[toc]

Linux Networking Devices

Udev naming

There a few network gotchas when adding a new network card or copying VMs. The issue starts when an existing the name of the network adapter changes (e.g., from eth0 to eth1) network adapter’s MAC address changes because a configuration script in linux associates the name of the network adapter with its MAC address. It can be disabled:

Disable udev persistent net generation

echo -n > /etc/udev/rules.d/70-persistent-net.rules
echo -n > /lib/udev/rules.d/75-persistent-net-generator.rules

# disable udev persistent net generation

echo -n > /etc/udev/rules.d/70-persistent-net.rules
echo -n > /etc/udev/rules.d/75-persistent-net-generator.rules

Systemd naming

With systemd, network devices are named differently(ie. enp0s0 or wlp2s0). Although this provides a more consistence naming convention with network adapters in linux, in some cases, The old style naming is sometimes needed for environments or scripts. To fix that, In grub:

Change:

title Gentoo Linux 4.4.1
root (hd0,0)
kernel /kernel-genkernel-x86_64-4.4.9-gentoo root=ZFS dozfs init=/usr/lib/systemd/systemd
initrd /initramfs-genkernel-x86_64-4.4.9-gentoo

To:

title Gentoo Linux 4.4.1
root (hd0,0)
kernel /kernel-genkernel-x86_64-4.4.9-gentoo root=ZFS dozfs init=/usr/lib/systemd/systemd net.ifnames=0
initrd /initramfs-genkernel-x86_64-4.4.9-gentoo

Magic SysReq

I have gotten into situations where the subsystems or subproccesses on a running system maybe not be performing as expected. If you ever need to reboot the host and its not connected to an pdu magic SysReq is the next best options.

You can activate it by:


echo 1 > /proc/sys/kernel/sysrq

If you need to reboot the host:

echo b > /proc/sysrq-trigger

Note: This will cause the kernel to send an instruction to the cpu to reset and it will not show down any processes cleanly and the same goes to the filesystem. USE WITH CAUTION!

To make it permanently turn on:

echo “kernel.sysrq = 1” » /etc/sysctl.conf

More infromation can be found: If you would like to learn more about magic SysRq you can read the sysrq.txt file in the kernel documentation. http://www.mjmwired.net/kernel/Documentation/sysrq.txt

Simple useful Python Function

Simple useful Python Function

These are functions that I have been useful and flexible to me.

import sys
import subprocess
import string
import socket
import re
import syslog
import smtplib
import os
import sys, getopt
from optparse import OptionParser

# Function that does basic standard output
def message(message):
    sys.stdout.write(message)
    sys.stdout.flush()

#Get command line options then return the variables to be used in other parts of the script.
def CliOptions():
    """
    Setup command-line parsing options
    """
    parser = OptionParser()
    parser.add_option('-o', '--output', default = '',    dest = 'output', help = 'Where to output the file to.')
    parser.add_option('-i', '--input',  default = '',    dest = 'input',  help = 'The Input file.')
    parser.add_option('--TrueOrFalse',	default = False, dest = 'TOF', help = 'True or false value.')
    return parser.parse_args()

#Take the contents of data and write it in a file.
def WriteFile(outputFile, outputInformation): 
    fileHandle = open(outputFile + ".out", "w")
    fileHandle.write(outputInformation)
    fileHandle.close()
 
#Read a file and remove newline and return charaters. Then return the data back.
def readFileFunction(inputFile):
    InputFromFile = []
    with open(inputFile, "r") as ins:
        for inputFileLineItem in ins:
            InputFromFile.append(line.rstrip('\r\n'))
    ins.close()
    return InputFromFile

#Have it output to syslog
def MsgLogging(msg):
	syslog.syslog(syslog.LOG_INFO, msg)

#This function calls shell commands. Clean the output but removing the any newline and return charaters using lambda.
def ExternalCommands(command):
    p1 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    results = p1.stdout.readlines()

    resultsFromPopen = map(lambda s: s.rstrip('\r\n'), results)
    return resultsFromPopen

How to use the above functions:


#The messaging function:
message ("Hello World\n")

#For the CliOptions function, The function gets called, it getting the commandline arguments. The function will return data into an array.
(options,args) = CliOptions()

#For the msgLogging
MsgLogging("Hello World")

#For ExternalCommands
results = ExternalCommands("ls /")

#For readFileFunction
results = readFileFunction(pathToFile)

#For WriteFile
WriteFile("/tmp/test.txt", "Hello World")
Journal Entry – 07022016

Journal Entry – 07022016

This week quite busy and it even bleed into the weekend. A couple of weeks ago, I installed a Velcro script with a rubber band underneath and strips of paper to help me with my bow hold and finger positioning on my cello. I have gotten used to having those things. I think for the Velcro I will keep it on the bow, but the strips of paper, I am thinking of removing it in the next few weeks to make me depend on my ears as I have been noticing that I have being depend on touch. I have happy that my playing has improved and reading sheet music with out the numbers has been becoming easier for me. Although, since next week is the start of my vacation and really practice playing my cello!

Cassie and I have been busy though this week, but we are able to spend time at night together and even talk about work, me finding a new job, or events that are happening in our lives. This weekend, I was hopping that she would come with me to play Magic The Gathering with Jim and Adrian, but she was not able to as she had to work. Although it was great see Kert and Kristy again! Cassie and I went to a BBQ with my friends in San Jose. It seems like my friends and Cassie got along well and we had a lot of fun! We all talked, ate, and laugh together!

Roopa’s BBQ Party

My project for this site is really coming together now, expectantly with wordpress. Ansible automation for the base configuration is coming along, and services are moving to a much better place. The articles on wordpress are coming together as well, and I will replace dokuwiki with wordpress. I feel a lot better using wordpress than dokuwiki as it never really satisfied my needs as wordpress does. I guess to some extent I am abie to personize it and make it more of my own that what I did with dokuwiki.

connecting a virtual console with VirtualBox and SoCat

connecting a virtual console with VirtualBox and SoCat

There are times when being able to connect a console to a terminal application becomes useful. For example, Getting kernel panic messages and you need to get the entire message so that it can help you figure out what is going on. If using Virtualbox on linux, the serial console with need to be setup:

 

Once that is set, download and install the command screen and socat.

yum install screen socat

When the programs have finished installing. Run this command:

./socat-2.0.0-b9/socat UNIX-CONNECT:/tmp/NyLinuxVM-con PTY,link=/tmp/NyLinuxVM-con-pty &

This creates a socket to the virtual machines console and the & allows it run in the background.


screen /tmp/NyLinuxVM-con-pty

Now I can connect to the console using the command screen.

Slow Cooker Lemon And Garlic Chicken

Slow Cooker Lemon And Garlic Chicken

INGREDIENTS

  • 1 whole chicken (based on the size of your slow cooker – a 1.3kg chicken should just about fit into a 3.5L slow cooker – while a 6.5L would probably fit a 2kg chicken)
  • 4 lemons
  • 10 garlic cloves divided (8 whole and 2 halved)
  • 4 sprigs rosemary
  • Salt
  • Pepper

INSTRUCTIONS

  • Remove any giblets etc. from the cavity of the chicken, sometimes in a small bag.
  • Stuff chicken with 1 sprig of rosemary, 1 lemon (quartered) and 4 cloves garlic.
  • Season all sides of the chicken with salt and pepper.
  • Remove both ends of a lemon, cut in half to create very thick slices.
  • Line the bottom of the slow cooker with 4 lemon slices, 4 whole garlic cloves and a sprig of rosemary.
  • Put the chicken in the slow cooker.
  • Cut 2 garlic cloves in half and put all four pieces on top of the chicken along with the 2 remaining lemon slices.
  • Garnish with 1-2 more sprigs of rosemary. Put the lid on the slow cooker and set to high for 4 hours.
  • Place cooked chicken under the grill (broil) for 10 minutes to crisp the skin (optional).

Allow chicken to rest for 10 minutes before carving and serving. Leftover juices in the slow cooker are mostly lemon juice with a bit of chicken fat and can be used sparingly as a strongly flavoured sauce.
Enjoy!

Pineapple Upside-Down Cupcakes

Pineapple Upside-Down Cupcakes

Ingredients

  • 1 can (20 oz) sliced pineapple, drained, juice reserved
  • 1 box Betty Crocker™ SuperMoist™ yellow cake mix
  • 1/2 cup vegetable oil
  • 3 eggs
  • 1/3 cup butter, melted
  • 2/3 cup packed brown sugar
  • 12 maraschino cherries, cut in half

Directions

Heat oven to 350°F. Spray 24 regular-size muffin cups with cooking spray. Cut each pineapple slice into 4 pieces; set aside. In large bowl, beat cake mix, oil, eggs and reserved pineapple juice with electric mixer on low speed 30 seconds. Beat on medium speed 2 minutes, scraping bowl occasionally. In small bowl, stir together melted butter and brown sugar. Spoon 1 1/2 teaspoons butter mixture into each muffin cup. Top each with 2 pineapple pieces. Place cherry half, cut side up, in center of pineapple pieces. Spoon 1/4 cup batter into each cup. Bake 20 to 25 minutes or until toothpick inserted in center comes out clean. Cool 5 minutes. Run knife around edge of cupcakes to loosen; invert onto cookie sheet.
Serve warm!!

Source: Pineapple Upside-Down Cupcakes

Sample List (PHP)

Sample List (PHP)

Date: 08/21/2009
Program Name: Sample List (PHP)
Description: The purpose of this PHP program is get records of a database, and show only the last 30 items.

<?php
  session_start();
  include ('request_processor.php');
  include ('********.php');
  include ('menu.php');
  include ('head.php');
 
  //were going to check of the were able to connect to the database.  If we can not then print a message that we can not
  $result = con_test();
  if (!$result) 
  {
      echo ('Connection status: <b><span style="color:red">error</span></b> <br /> <p>Please check to see if the MySQL database service is on.');
      exit(0);
  }
  else
  {
    if ($_SESSION['login'] == '') //indicating that if the variable is not set than the 
    {  //print the login page
      print ("<table align=\"center\" border=\"0\"><form action=\"login.php\" method=\"post\"><table border=\"0\" align=\"center\">");
      print ("<tr><td>User Name:</td><td><input type=\"text\" size=\"30\" maxlength=\"28\" name=\"Name\" /></td>");
      print ("</tr><tr><td>Password:</td><td><input type=\"text\" size=\"30\" maxlength=\"28\" name=\"pass\" /></td>");
      print ("<tr><td align=\"center\" colspan=\"2\"><input type=\"submit\" value=\"Login\" />");
      print ("<input type=\"button\" value=\"Lost Password\" /></td></tr></table></form></body></html>");
      $_SESSION['login'] = 'check';
      exit(0);
    }
    elseif($_SESSION['login'] == 'check')
    {
      //Will start first by openning a connection to mysql
      $connection = con();
 
      //get the name and password from the login page
      $name = $_POST["Name"];
      $pass = $_POST["pass"];
 
      //Create the query command for MySQL
      $query = "select * from users where UserName = '$name' and password = '$pass'";
 
      $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
 
      if (!mysql_fetch_object($result))
      {
				$_SESSION['login'] = '';
				print ("I am sorry but the username or password does not match!<br /><a href=\"/portfilo/login.php\"><td>Go Back</a>");
				exit(0);
      }
      else
      {
				$_SESSION['login'] = 'ja';
				head();  //Create the html headers
				styles(); //Then the styles
				menu();   //Menu option
				print ("This is a sample programming Work.");
      }
 
      // close connection
      mysql_close($connection);
    }
    elseif ($_SESSION['login'] == 'ja')
    {
      head();  //Create the html headers
      styles(); //Then the styles
      menu();   //Menu option
 
      print ("This is a sample programming Work.");
    }
    // Session cleanup
    session_destroy();
  }
?>
Sample Login Program (PHP)

Sample Login Program (PHP)

Date: 08/18/2009
Program Name: Sample Login Program (PHP)
Description: The purpose of this PHP program is allow a user to login and view the content of a page. If the user does not supply the correct login information, then the program will print out a message stating that the information is incorrect. In addition, The program checks to see if it’s able to connect to the database. If it can not than it will display a message stating that it can not connect to the database.

<?php
  session_start();
  include ('request_processor.php');
  include ('********.php');
  include ('menu.php');
  include ('head.php');
 
  //were going to check of the were able to connect to the database.  If we can not then print a message that we can not
  $result = con_test();
  if (!$result) 
  {
      echo ('Connection status: <b><span style="color:red">error</span></b> <br /> <p>Please check to see if the MySQL database service is on.');
      exit(0);
  }
  else
  {
    if ($_SESSION['login'] == '') //indicating that if the variable is not set than the 
    {  //print the login page
      print ("<table align=\"center\" border=\"0\"><form action=\"login.php\" method=\"post\"><table border=\"0\" align=\"center\">");
      print ("<tr><td>User Name:</td><td><input type=\"text\" size=\"30\" maxlength=\"28\" name=\"Name\" /></td>");
      print ("</tr><tr><td>Password:</td><td><input type=\"text\" size=\"30\" maxlength=\"28\" name=\"pass\" /></td>");
      print ("<tr><td align=\"center\" colspan=\"2\"><input type=\"submit\" value=\"Login\" />");
      print ("<input type=\"button\" value=\"Lost Password\" /></td></tr></table></form></body></html>");
      $_SESSION['login'] = 'check';
      exit(0);
    }
    elseif($_SESSION['login'] == 'check')
    {
      //Will start first by openning a connection to mysql
      $connection = con();
 
      //get the name and password from the login page
      $name = $_POST["Name"];
      $pass = $_POST["pass"];
 
      //Create the query command for MySQL
      $query = "select * from users where UserName = '$name' and password = '$pass'";
 
      $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
 
      if (!mysql_fetch_object($result))
      {
				$_SESSION['login'] = '';
				print ("I am sorry but the username or password does not match!<br /><a href=\"/portfilo/login.php\"><td>Go Back</a>");
				exit(0);
      }
      else
      {
				$_SESSION['login'] = 'ja';
				head();  //Create the html headers
				styles(); //Then the styles
				menu();   //Menu option
				print ("This is a sample programming Work.");
      }
 
      // close connection
      mysql_close($connection);
    }
    elseif ($_SESSION['login'] == 'ja')
    {
      head();  //Create the html headers
      styles(); //Then the styles
      menu();   //Menu option
 
      print ("This is a sample programming Work.");
    }
    // Session cleanup
    session_destroy();
  }
?>
%d bloggers like this: