RSS Feed

RSS

Comments RSS


Python – Accessing Oracle Databases

Still learning the Python programming language here. However, along the way, I have found a need to branch out with some add-on modules for specific tasks. One of these is a module for accessing Oracle Databases. The module is cx_Oracle. Performing a query to an Oracle database become this simple process:

import the cx_Oracle module

import cx_Oracle

make your connection to the Oracle database

connection = cx_Oracle.connect(“username”,”password”,”oracle_instance”)

create an instance of the cursor

cursor = connection.cursor()

Perform a query. This demonstrates a simple select query, how to pass some user input as an argument to it, and how to do something something with the result.

user_input = str.upper(str(input(“Please provide value to query>>”)))

cursor.execute(“select some_field from some_table where some_field like :arg_1″, arg_1 = user_input)

for some_field in cursor:

print(some_field)

Python – a learning exercise

In the process of learning Python, I have given myself a programming exercise to do.  This is a standard thing I do whenever learning a new programming language and I have used this same exercise several times before.  It is a simple text based game that simply lets a user explore a maze of rooms.   If fully fleshed out, it would be a Zork or D&D type game.  It demonstrates some basic programming tasks such as reading data into an array from a file, getting and responding to user input, looping, control structures, system calls and function definitions.  I share it here as example code for others also learning Python and I welcome comments.   The code is for Python 3.x, but the comments explain how to easily convert it for use in Python 2.x.  It is far from perfect and is for learning purposes only – something to tinker with.  It is based on concepts from Creating Adventure Games on Your Computer by Tim Hartnell, which used the BASIC programming language.   You are welcome to take this code and use and modify for any purpose you like.  The current version of this code will always be at this location: mazegame-current .  You can create an appropriate data file by making a text file with contents similar to the following, the current code requires a fixed number of columns (7 at the time of this writing and subject to change) and an unlimited number of rows.
0 0 0 0 0 0 0
0 0 4 2 0 0 0
0 0 0 1 3 6 0
0 0 5 0 2 0 0
0 1 0 5 0 0 0
0 3 0 0 4 0 7
0 0 0 0 0 0 2
0 0 0 0 0 5 0

My previous blog entry Learning Python provides resources for those wanting to learn Python, as does the Dev page from my main website.

Learning Python

I have picked up learning to program in Python again.   Looking to add it to my trophy case along with BASIC, x86 Assembler, IBM BAL, Pascal, Modula-2, Forth and C.   In the process I have found some great resources, aside from the official Python website to share. The first two sites are excellent on-line books about programming in Python. The last two sites teach programming skills generally using Python as the example programming language.

A Byte of Python
Dive Into Python
Learning to Program
How to Think Like a Computer Scientist

More resources can be found on my Web Development and Programming page.

Shave Secret – WOW!

Ok, do not usually do this and certainly am not being paid to do it, but it is very seldom that a product I try on a whim that works out so well. I have always HATED shaving. Even the very best lubricated shaving gels did not prevent me getting pretty bad razor rash. I would not shave very often because of it, usually just once a week for church or otherwise on special occasions (like my wife insisting!). I was in Wal-Mart about two months ago and noticed a product called Shave Secret shaving oil. It is a little bottle and the product is a blend of oils. I bought it on a whim out of desperation for something that would work better than shaving cream or shaving gel. It works fantastically well! With it, I can shave daily and not be one constant case of razor rash and it leaves the skin refreshed, moisturized, and well conditioned. It can be found on-line at http://www.shavesecret.com. Oh, and it is a TEXAS product made by USA King’s Crossing, LLC.. Cuero, Texas.

Useful Linux tips

This page has some very useful Linux tips.  Mainly for beginners, but some intermediate.   Good stuff!   Thanks to the author for sharing with the community.
Highly useful Linux commands & configurations

Barack HUSSEIN Obama – America’s Dictator


uppity

I am better than you.  I am smarter than you.  You will do what I say, BECAUSE I SAY SO!`


CSH PROGRAMMING CONSIDERED HARMFUL

Why script writing in the Unix shell csh is considered harmful.   A classic, but useful, Usenet rant.

http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

A Romantic Dinner

It is my wife’s birthday today.  We are out of town in Houston and vacationing, away from the kids who are vacationing separately.  It is wonderful to finally be at that point in life where that is possible!  It has allowed for a nice romantic dinner tonight at Perry’s Steakhouse, a great fine dining experience.   We had an excellent dinner and I did what I wish I had done twenty years ago, get down on one knee in public and make a proper proposal.  Of course, we are already married, but I did next best thing.  I asked her if she had it to do all over again, would she still marry me?  I also asked her if she would renew our wedding vows with me later this summer when our 2oth wedding anniversary comes around.  I received a joyful affirmative on both counts!  My advice to any married couple, take the time to do the simple, romantic things.  Go out to dinner.  Tell each other often you love them.  Do not forget how to go out on a date.  Take time for each other, because a limited amount of time is all you have together.

K5TSU Echolink Repeater

A new echolink repeater for Erath County, TX is on its way! The K5TSU/R.
After many years of faithful service of the KD5HNM repeater, the trustee Justin McClure has had to shut it down due to network infrastructure changes at his location. Many thanks to Justin, KD5HNM, for having made this available to us in Erath County, TX. Yesterday, some of us began discussing the possibility setting up a new Echolink repeater for our Ecom/WX use. It was amazing that within an hour we had what appears to be a very solid plan for bringing it online. A radio, computer an location have all been identified. Also, a call sign, K5TSU. This is the call sign of our local university ham club at Tarleton State University.

FOSS Encryption Software

I have been using EncryptionPlus Hard Disk encryption software at work now for encrypting laptops (per corporate security policies) for over six years now.   The product has work reasonably well.  Aside from personal file and email encryption products such as GPG, I was unaware of any FOSS (Free and Open-Source Software) full disk encryption systems similar to what I had been using at work, until a coworker brought TrueCrypt to my attention.   I have read the documentation and it seems perfectly capable for what I need so I am going to give it a try.  My laptop is unencrypting right now and EncryptionPlus will be uninstalled.   What makes me want to try this out is not just that TrueCrypt is FOSS, but also that I could not previously have a Wubi install of Ubuntu on this laptop while it was encrypted with the EPHD product – the Wubi Ubuntu would not boot.   Once this finishes unencrypting and EPHD is gone, I will once again do a Wubi install of Ubuntu and then try TrueCrypt and see if every thing works.   I will let the blogosphere know how this progresses!

Update — did the operation as described above. Wubi still did not work, but that now makes sense to me and I don’t think that could have worked. However, TrueCrypt itself is working wonderfully! I really like this product. I did a full disk encryption on a 75GB disk and it took much less than two hours. Also, the documentation for the software if very thorough. It is amazing that such a good system is FOSS!

Final Update — I could not be more pleased with TrueCrypt. I will highly recommend it to all my geek friends! :-)

From K5WLF – tech-note on battery run-time

K5WLF has written up a great tech-note on how to calculate battery run-time.  Very handy in any situation where running on battery power is critical.   A great overall blog post, the tech-note is found about half way down.   Check it out!

K5WLF post with tech-note:  http://www.rebelwolf.com/blog/?p=195

An update to K5WLF’s previous blog entry with information concerning the C/20 discharge rate of batteries, please see it for important additional information: http://www.rebelwolf.com/blog/?p=203

73,

Bill – WA5PB

HOWTO – Ububtu, a customizable Compose Key System

In my previous blog entry, I introduced both Unicode character entry and Compose Key entry of special characters.  One thing that becomes apparent is that there might be some characters or symbols missing from the default GTK+ code in Gnome.   Unfortunately, this is in compiled code and cannot be changed.  One option is to use Compose Key sequences for most special character entries and Unicode character entry for the occasional odd symbol.  However, if that “odd symbol” is one you intend to use often, you might wish you had a Compose Key sequence for it.   This can be accomplished, at a small price.

Situation, say you are an electronics enthusiast and have a need to type the Ohms symbol, Ω, quite often.  This symbol is not in the default GTK+ Compose Key sequences, and there is no way to add them easily into that source.   An option is to use the <Shft><Ctrl><u>03A9 Unicode method entry to get the Ohms symbol.  Sure, this works fine, but could be tedious if done on a regular basis.  What we need is a way to get this into a nice, intuitive, Compose Key sequence.  The solution is to take advantage of the fact that there is an alternate source for the Compose Key definition table and that this can be modified to add in missing symbols that you may need to use often.   This is the .XCompose file, which I will show here how to create and edit.

The method we will use is to override the default Gnome method with the orignal Xwindow method, which is also available on your system, but must be configured and activated.  It is called the Xwindow Input Method (XIM).  The system must be told to use this method instead by setting the GTK_IM_MODULE environment variable.   This is done with the following command from the shell prompt:

export GTK_IM_MODULE="xim"

For this environment variable setting to be automatically set every time you log into the system, add this line to the .gnomerc or .Xsession file in your home directory.  If these files do not exist, then create one (.gnomerc) by entering the following text in any text editor and saving the file as .gnomerc (do not neglect to include the leading dot!):

#!/bin/bash
export GTK_IM_MODULE=”xim”

Next, you want your own copy of the XIM Compose Key file to have and modify to your own liking.   We do this by copying a system copy of the file to our home directory and giving it the name .XCompose (this file name is CASE SENSITIVE!):

cp /usr/share/X11/locale/en_US.UTF-8/Compose ~/.XCompose

Finally, you will want to edit your .XCompose file to add in the symbols and keybindings  you are interested in.   For instance, here are the lines I added to bind the Unicode 03A9 for the Ohms symbol to <Multi_key> (AltGR in my case, whatever you have set as your Compose Key in your case) <o><m> (get it?) and <m><o>, also some other symbols I find handy.

<Multi_key> <o> <m>                   : “Ω”   U03A9 # OHM SYMBOL
<Multi_key> <p> <i>                    : “π”   U03C0 # PI SYMBOL
<Multi_key> <d> <t>                    : “Δ”   U0394 # DELTA SYMBOL

Is there a downside to overriding the default Gnome GTK+ Compose Key tables?  Yes, there is.  You loose the <Shft><Ctrl><u> keybinding to be able to do Unicode entry anywhere in the Gnome interface.  However, if your aim is to exclusively use Compose Key sequences and to update your data table to include any missing ones you might need, then it is not a bad trade off.

Finally, a tip on editing the .XCompose file.  Just how do you enter a represenation of the missing symbol into the file if you have already activated XIM which disables the <Shft><Ctrl><u> Unicode entry method?  Edit the file in an editor such as Vi that has its own Unicode entry method or use the Gnome “Character Map” utility to get a copy of the symbol into an editor that does not have a method of its own.   In Vi (or Vim), go into text insert mode and type <Ctrl><v><u>+unicode to enter Unicode symbols.

Once you have set the environment variable and created your file, log out and then back in to activate everything and you are all set to have a Compose Key system that you can customize to suit your own needs.

Much of this information was extracted from the following source and should be referred to for further information on the subject:
https://help.ubuntu.com/community/ComposeKey

HOWTO – Ubuntu special characters

In Ubuntu, if you want to type any Unicode character, do so my holding down Shift+Ctrl+U then the unicode for the needed character.  Shift+Ctrl+U gives you an underlined u and you type the code and hit <enter>.  Works in every application I have tried.

example:

Shift+Ctrl+U 00f4 results in ô
Shift+Ctrl+U 00e1 results in á

Of course, you have to know the Unicodes.  This chart will help  http://www.alanwood.net/demos/ansi.html

Also, you can use the COMPOSE KEY!

Addition information on configuring a compose key sequence and its use can be found here:  https://help.ubuntu.com/community/ComposeKey

I defined my compose key to be the Right-Alt key on Ubuntu 10.04 like this:

System>Preferences>Keyboard>Layouts>Options>Compose key position>Right Alt

Good list of compose key combinations to get all the weird, odd and desperately needed characters you want:  http://www.seedwiki.com/wiki/takomapark/compose2

Wikipedia entry on Compose key:  http://en.wikipedia.org/wiki/Compose_key

Another blogger’s nice short write up on using compose keys:  http://sivers.org/compose-key

Finally, for Windows users who would like to have Unix/Linux style compose key functionality this program works well and is free:  AllChars

Ubuntu, when things go badly – Synaptic HOWTO

This is good information for anyone who is going to be managing an Ubuntu system.

https://help.ubuntu.com/community/SynapticHowto

also good documentation on using the shell interface for Apt

https://help.ubuntu.com/community/AptGet/Howto

I had a 9.10 to 10.04 upgrade break due to an internet failure during the process.   The following is from the SynapticHowto.  The upgrade was so broken that it was leaving me at a shell prompt to login, the Gnome desktop was not loading automatically and the Update Manager would not finish the upgrade.  I did the following and it saved my upgrade and got everything working properly.

Broken Upgrade or Installation

  • What to do if an installation process fails and you find it is no longer possible to install or remove packages:
  • Open a Terminal and type the following commands, pressing the Return or Enter key after each (you may have to type in your password):
     sudo dpkg --configure -a
     sudo apt-get install -f

a neat trick via Ghostscript

I have found a neat trick.  Not original, found it here:  http://www.sls.psi.ch/controls/help/howto/tips_n_tricks.html#PostScript

PostScript and PDF

  • To concatenate PostScript or PDF files into a single PDF file:

    gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
    -sOutputFile=<outfile> <infile> <infile> …

  • To concatenate PostScript or PDF files into a single PostScript file:

    gs -q -dNOPAUSE -dBATCH -sDEVICE=pswrite \
    -sOutputFile=<outfile> <infile> <infile> …

  • This trick used in combination with the fact that in Ubuntu you can print not only to a printer, but also to either a postscript or PDF file directly, means that if a book is presented in html on the web, say with each chapter being an individual HTML page, you can easily print each of these to a file and then use the trick to concatenate the ps or pdf files together to reassemble the entire book.  For instance, I am doing that with this book that is online:  http://www.gigamonkeys.com/book/

    I do not know how many other books that I have run across on the web that were HTML like this and I wanted to reassemble them for a good print out.  This is a way to do it.

    By the way, “gs” is the command line program for Ghostscript, which should be already installed on your Ubuntu system by default.  If you install Ghostscript on a Window system, the same trick should work there too so long as you print the HTML to a PDF printer driver.  Ghostscript can be downloaded from here:  http://pages.cs.wisc.edu/~ghost/

    Oh, yes, this is also cool…:  http://pages.cs.wisc.edu/~ghost/redmon/index.htm

    Why Desktop Linux (still) Sucks…

    AND WHAT WE CAN DO TO FIX IT!

    This is not a slam against Linux.  It is all about making our favourite OS more viable and available to more people.

    Ubuntu 10.04 LTS is released

    The new Unbuntu, 10.04 LTS, has been released. It is great!
    Go get Ubuntu 10.04.
    A good review from another blogger: Ubuntu 10.04 – Perfect

    The Magic SysRq key

    The Magic SysRq key!   If you use a GNU/Linux OS, discover what the SysRq key on your keyboard can do for you.  http://en.wikipedia.org/wiki/Magic_SysRq_key

    A beautiful day!

    What a beautiful day!   My wife and I went on a date today to Clark Gardens Botanical Park.   The gardens are located outside of Mineral Wells, TX which is about an hour from where we live.   We packed some fixings for sandwiches and a nice Muscat Canelli wine from Sister Creek Vineyards, one of our favorite wines.   The flowers were gorgeous and very fragrant.  The gardens exhibit a large variety of plant life, particularly flowers such as roses, iris, poppies, etc.  There is also a local contingent geese, guinea flow, swans, ducks, and peacocks.   As a bonus, if you are a fan of model trains, there is a brilliant set of G-scale model trains running in a section of the garden.  I highly recommend anyone take some time to visit this wonderful place.  Pack a lunch, take a loved one, and enjoy a great day out in the outdoors and the beauty of nature!

    A great quote!

    “In my many years I have come to a conclusion that one useless man is a shame, two is a law firm, and three or more is a congress.” – John Adams