Chit chat

———–

Been goofing off so there is not much to report.

———————————————————-

No matter what system you use or even if you do everything by hand, you will need a typewriter (editor), Filing cabinet (database), and an financial worksheet (spreadsheet). Everyone knows about vim, nano, and  for using as editor or word processor. If you have ever wanted to set up a filing cabinet or database, you probably have heard of Mysql (or one of the variants), Postgresql, or even Nosql.

What many people have not heard of is a spreadsheet for the command line.One interesting spreadsheet is called simply enough called sc. Some people may lead you to believe it will only support just numbers that is not true.

You can even get a help file with:

$ scqref > sc_commands



A:   This overview
B:   Toggle Options
C:   Set Options
D:   Cursor movement commands
E:   Cell entry and editing commands
F:   Line Editing
G:   File commands
H:   Row and column commands
I:   Range commands
J:   Miscellaneous commands
K:   Variable names/Expressions
L:   Range functions
M:   Numeric functions
N:   String functions
O:   Financial functions
P:   Time and date functions

There is even a tutorial you can use:

$ sc /usr/share/doc/sc/tutorial.sc

Though we like to use out own home grown spreadsheet called lizzyclc. Lizzyclc was created with Freebasic, so it is easy to update for adding new features.

Also the command structure is easier to follow for a new user.

Thats all..

———————————————————-

Server upgrades.

Upgrading the operating system on your home machine is a piece of cake compared to doing it in the server environment, Generally when you care changing a server os, you use a new systems so that if there are issues you can go back to the old system as a failsafe. There are always issues setup up new operating systems especially with hardware drivers, so dealing with that can be fun.

When you set up a new system the storage formats are completely different.   Some applications will balk at that, In some cases it could be just a permissions problem. Also network printers and input devices have to be set up. Remembering once when we went from Novell to NT printing out student invoices did not work or barely worked. The consulting company said it worked when they tested it, but never really did a mass testing. We ended up pooling printers to make things work well enough till a better fix was done.

To add to that scenario, you have to make sure the general permissions of files are correctly setup. For instance, years ago everything was locked down on Novell, Microsoft there was no real security, so you had to go directory, and file by file and change as needed.

There were always server applications that did not want to work with the newer systems OS applications could and will fail, This is especially true with specific permissions access.  You will need to make adjustments to allow your applications work in the new environment. . This was even true between versions of Microsoft servers. You would have to contact vendors for fixes and updates which on many cases the vendors were reluctant to do. In many cases you had to perform miracles on your own to make things work,  That led to issues, because vendors would threaten to sue you if you changed their software for copyright and or other violations.

Once you had that done, you had to go application by application to make sure the clients interacted with the server properly. This meant you had to completely revise your control (batch, shell, etc) files because the same scripts would no longer work anymore. Then you had to go to the clients and correct shortcuts to connect to the new control files. We usually just built a new image to work with.  Then there was the testing and retesting to make sure everything worked, That was just the tip of the iceberg.. Moving on, Of course, all this had to be done without the user ever knowing a change was made.  Being a software administrator is so much fun,

———————————————————-

Not so many years ago when I was a tech, needed to use the internet to solve a vital problem. The internet was allegedly down. Contacted the administrator (who had umpteen MSce certifications) who in charge of that area confirmed that the net was inaccessible because they were having problems. So I asked what I could do and the reply was nothing could be done.

Being independent as I am and not willing to give up so easily, I decided to tinker a bit.  Decided to go into the student CS lab and use one of the desktops as a test machine. Having set up a lot of the cabling and routers, was pretty knowledgeable of the systems, Fortunately also had systems admin rights also in those systems. Now for the tinkering,.

Logged into a system and immediately went to the ip settings. Dns server was down so, I used a public dns server in its place of the local dns server.  Could not get a ip address from that server, so I used a static ip address that would not interfere with the network if the local dhcp came back up. Saved the settings and restarted the system.

When the system came back up, I logged in and fired up the web browser. Guess what  There was now internet. Was able to get my research done that I needed. Then I reset the settings back on the system for normal use. More than one way to skin a cat. Never took the systems administrator very seriously after that. Actually I was a member of that same IT team.

———————————————————-

One of the simplest graphs I have seen can be done in bash. You will need a data file and a one line executable to extract the data from the file and then display it.

data:
Irene     10
Karen     37
Andreas   41
Beatrice  23

Code:
SCALE=1; WIDTHL=10; WIDTHR=60; BAR=”12345678″; BAR=”${BAR//?/==========}”; while read LEFT RIGHT rest ; do RIGHT=$((RIGHT/SCALE)); printf “%${WIDTHL}s: %-${WIDTHR}s\n” “${LEFT:0:$WIDTHL}” “|${BAR:0:$RIGHT}*”; done < data

Result:
Irene: |==========*
Karen: |=====================================*                       Andreas: |=========================================*
Beatrice: |=======================*

Another script:

 bar="=================================================="
  barlength=${#bar}
  i=0
  while ((i < 100)); do
    n=$((i*barlength / 100))       # Number of bar segments to draw $((i/2))
    printf "\r[%-${barlength}s]" "${bar:0:n}"
    ((i += RANDOM%5+2))            # i = percentage done
    sleep 1
  done
  echo

The you could get a bit more fancy with a bit of animation.

&nbsp;# !/bin/sh
#
# Bargraph_Generator.sh
#
# A DEMO 6 bit coloured bargraph animation for a default Bash and Terminal window on OSX 10.7.5...
# A simple Shell script to display an _AT_A_GLANCE_ real time analogue bargraph generator. It
# starts off with GREEN for OK, then YELLOW for warning and finally ending with RED for danger
# with a critical beep for values 61 to 63 inclusive.
# It assumes an 8 bit value being injected into the script which is then divided by 4 to give
# a 6 bit value which is 64 spaces width inside the Terminal. The DEMO uses a random number
# generator to give a representation of an 8 bit value so you can see it working...
#
# A shell derivative of my Python code:-
# http://code.activestate.com/recipes/577612-seven-bit-colored-analogue-bar-graph-generator-dem/?in=user-4177147
#
# To run, ensure the script is executable and change if required, then type from a Terminal:-
#
# xxxxx$ /full/path/to/Bargrapth_Generator.sh&lt;CR&gt;
#
# And away you go...
#
# Written in such a way that kids and newbies can understand what is going on.
#
# Originally written for a Macbook Pro 13 inch, OSX 10.7.5 using the default Terminal.
# It MIGHT work on some Linux variants but WAS intended for MacOS OSX 10.7.x and above only.
#
# The Terminal colours WILL be changed to Black background and Various foreground colours.
# It will NOT be returned back to its original state although it can be easily. If you
# need to rerturn back to default state then there are a couple of easy methods the
# simplest being type:-
#
# xxxxx$ reset&lt;CR&gt;
#
# And all will be corrected...
#
# Issued entirely as Public Domain and you may do with it as you please
#
# $VER Bargraph_Generator.sh_Version_0.00.10_(C)2012_B.Walker_G0LCU.
#
# Enjoy finding simple solutions to often very difficult problems...

# The required _varibales_ for ease of coding, these are the colours...
# White On Black.
WOB="\x1B[1;37;40m"
# Black On Green.
BOG="\x1B[1;30;42m"
# Black On Yellow.
BOY="\x1B[1;30;43m"
# Black On red.
BOR="\x1B[1;30;41m"
# Green On Black.
GOB="\x1B[1;32;40m"
# Yellow On Black.
YOB="\x1B[1;33;40m"
# Red On Black.
ROB="\x1B[1;31;40m"

# Set the pseudo 6 bit value to zero.
SIX_BIT_DEPTH=0

# Do a clear screen to White On Black.
printf $WOB
clear

while true
do
&nbsp;&nbsp; &nbsp;# Set up the screen per scan and prepare for the bargraph.
&nbsp;&nbsp; &nbsp;clear
&nbsp;&nbsp; &nbsp;printf $WOB"\n \$VER: Bargraph_Generator.sh_Version_0.00.10_(C)2012_B.Walker_G0LCU.\n\n"
&nbsp;&nbsp; &nbsp;printf " A horizontal, at a glance, coloured, analogue bargraph display for\n"
&nbsp;&nbsp; &nbsp;printf " a default Terminal inside OSX 10.7.5..\n\n\n\n\n"
&nbsp;&nbsp; &nbsp;printf "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 30&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 40&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 50&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 60"
&nbsp;&nbsp; &nbsp;printf $GOB"\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +----+----+----+----+----+----+----+----+----+"$YOB"----+----+"$ROB"----+--\n"
&nbsp;&nbsp; &nbsp;printf $GOB"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "$ROB")\n"
&nbsp;&nbsp; &nbsp;printf $GOB"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +----+----+----+----+----+----+----+----+----+"$YOB"----+----+"$ROB"----+--\n\n\n\n"
&nbsp;&nbsp; &nbsp;# If the 6 bit value is 0, zero, do no more until printing the 6 bit value and generating another 6 bit value...
&nbsp;&nbsp; &nbsp;# Anything greater than or equal to 1 enters this conditional branch.
&nbsp;&nbsp; &nbsp;if [ "$SIX_BIT_DEPTH" -ge "1" ]
&nbsp;&nbsp; &nbsp;then
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# If the 6 bit value is less than or equal to 46 then _plot_ the green section only.
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# The '\x1B[12;8f' is the ANSI 'Esc' code that forces the print position to 12 lines by 8 columns.
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if [ "$SIX_BIT_DEPTH" -le "46" ]
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;then
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BARGRAPH=$GOB"\x1B[12;8f("$BOG
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for green in $(seq 1 "$SIX_BIT_DEPTH")
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;do
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BARGRAPH=$BARGRAPH" "
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;done
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fi
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# If the 6 bit value is greater than or equal to 47 then print the green section and _plot_ the yellow section.
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if [ "$SIX_BIT_DEPTH" -ge "47" ]
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;then
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BARGRAPH=$GOB"\x1B[12;8f("$BOG"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "$BOY
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for yellow in $(seq 47 "$SIX_BIT_DEPTH")
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;do
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BARGRAPH=$BARGRAPH" "
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;done
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fi
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;# If the 6 bit value is greater than or equal to 57 then print the green and yellow section and _plot_ the red section.
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if [ "$SIX_BIT_DEPTH" -ge "57" ]
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;then
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BARGRAPH=$GOB"\x1B[12;8f("$BOG"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "$BOY"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "$BOR
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for red in $(seq 57 "$SIX_BIT_DEPTH")
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;do
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BARGRAPH=$BARGRAPH" "
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;done
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fi
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;printf "$BARGRAPH"$GOB"\n\n\n\n\n"
&nbsp;&nbsp; &nbsp;fi
&nbsp;&nbsp; &nbsp;# When the 6 bit value is greater than or equal to 61 sound a system error beep.
&nbsp;&nbsp; &nbsp;if [ "$SIX_BIT_DEPTH" -ge "61" ]
&nbsp;&nbsp; &nbsp;then
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;printf "\a"
&nbsp;&nbsp; &nbsp;fi
&nbsp;&nbsp; &nbsp;# Print the 6 bit value in White On Black...
&nbsp;&nbsp; &nbsp;printf $WOB" Random number generated "$SIX_BIT_DEPTH"...\n\n"
&nbsp;&nbsp; &nbsp;printf " Press Ctrl-C to stop the program...\n\n"
&nbsp;&nbsp; &nbsp;# Generate another 6 bit value as though from an 8 bit value...
&nbsp;&nbsp; &nbsp;SIX_BIT_DEPTH=$[($RANDOM % (256/4))]
&nbsp;&nbsp; &nbsp;# A practical lower limit for the sleep command is 'sleep 0.05'...
&nbsp;&nbsp; &nbsp;sleep 1
done

# End of Bargraph_Generator.sh DEMO.
# Enjoy finding simple solutions to often very difficult problems... ;o)

One step farther:

Or then you could use a built in program such as gnuplot. It is well documented and there are a zillion examples on the web.

Here is a simple data file:

# sample 2-column data file
# ————————-
1     1
2     4
3     9
4    16
5    25
6    36
7    49
8    64
9    81
10  100

The you want to fire up gnuplot

$ gnuplot

G N U P L O T
Version 4.6 patchlevel 0    last modified 2012-03-04
Build System: Linux i686

Copyright (C) 1986-1993, 1998, 2004, 2007-2012
Thomas Williams, Colin Kelley and many others

gnuplot home:     http://www.gnuplot.info
faq, bugs, etc:   type “help FAQ”
immediate help:   type “help”  (plot window: hit ‘h’)

Terminal type set to ‘unknown’
gnuplot>

Set a simple terminal for now

gnuplot> set term dumb

Now let’s use that data file

gnuplot> plot ‘2col.dat’

Or if you have Imagemagick installed you can get a bit fancier.

gnuplot> set term png
Terminal type set to ‘png’
Options are ‘nocrop font “/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf,12” fontscale 1.0 size 640,480 ‘

gnuplot>               set output ‘| display png:-‘

Then run your plot again

gnuplot> plot ‘2col.dat’ with linespoints

Try a different data file

1,    1,   2,   5
2,    4,   4,  10
3,    9,   6,  15
4,   16,   8,  20
5,   25,  10,  25
6,   36,  12,  30
7,   49,  14,  35
8,   64,  16,  40
9,   81,  18,  45
10, 100,  20,  50

gnuplot> plot '4col.csv' using 1:2 with lines, '4col.csv' using 1:3 with lines
gnuplot> plot '4col.csv' using 1:2 with lines, '4col.csv' using 1:3 with lines, '4col.csv' using 1:4 with lines


gnuplot>               set term png
Terminal type set to ‘png’
Options are ‘nocrop font “/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf,12” fontscale 1.0 size 640,480 ‘
gnuplot>               set output ‘| display png:-‘
gnuplot> set style line 1 lc rgb “red”
gnuplot> set style line 2 lc rgb “blue”
gnuplot>
gnuplot> set style fill solid
gnuplot> set boxwidth 0.5
gnuplot>
gnuplot> plot “data.dat” every ::0::0 using 1:3:xtic(2) with boxes ls 1, \
>     “data.dat” every ::1::2 using 1:3:xtic(2) with boxes ls 2
gnuplot>

 

gnuplot>               set term png
Terminal type set to ‘png’
Options are ‘nocrop font “/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf,12” fontscale 1.0 size 640,480 ‘
gnuplot>               set output ‘| display png:-‘
gnuplot>
gnuplot> set xrange [-pi/2:pi/2]; set yrange [-pi/2:pi/2]
gnuplot> set contour
gnuplot> set isosamples 100,100; set samples 100,100
gnuplot> splot sin(x)*cos(y) with lines palette linewidth 4
smooth palette in png: using 160 of 160 available color positions
gnuplot> pause -1

The sky is the limit have fun.
——————————————
Update:

Each script takes in a csv file as input and “plots” the values as an ASCII graph in the terminal. It’s questionable how useful this actually is, but it’s a bit of fun at least. The SCALE variable controls the amount of characters used for the width of the plot area (not including the table containing labels and values).
Simple: Plot Values of each item
input file: sales

january,140
february,29
march,26
april,54
may,72
june,86

output: ./vgraph sales


 Relative Value Chart
Name      Value (Max is 140)
____________________0_________._________|_________._________|100% (140)
january      140    |========================================
february     29     |========
march        26     |=======
april        54     |===============
may          72     |====================
june         86     |========================

Percentage graph using value and max for each item

input file: stock-list

apples,20,100
pears,40,50
cherries,100,150
mangoes,45,85
tomatoes,30,30

output: ./pgraph stock-list


 Percentage Chart
____________________0_________._________|_________._________|100%
apples       ( 20%) |========
pears        ( 80%) |================================
cherries     ( 66%) |==========================
mangoes      ( 52%) |=====================
tomatoes     (100%) |========================================

And the scripts…. They are both very similar, just some minor tweaks to make them do what I wanted.

vgraph

Relative Value Chart

Name      Value (Max is 140)
____________________0_________._________|_________._________|100% (140)
january      140    |========================================
february     29     |========
march        26     |=======
april        54     |===============
may          72     |====================
june         86     |========================


#!/bin/bash
#
# Value Graph (vgraph)
# Basic ASCII Graphing Tool
#
# Plot values and scale to max
#
# CSV format: Name, Value
#
# Awk isn't perfect at rounding.. .5 rounds down
#
# v1.1 sol@subnetzero.org

if [ -z $1 ]; then
        printf "Usage: pgraph [datafile]\n"
        exit 1
fi

# Set Vars
# FILLER and ENDDELIM are used for drawing bars.
ENDDELIM="="
FILLER="="
SCALE=40
INPUTFILE=$1
NAME=(`awk -F"," '{print $1}' < "$INPUTFILE"`)
TOTAL=(`awk -F"," '{print $2}' < "$INPUTFILE"`)

# Get Max qty for scaling
MAXQTY=0
for VALUE in ${TOTAL[*]}
do
        if [ "$VALUE" -gt "$MAXQTY" ]; then
                MAXQTY=$VALUE
        fi
done

# Make graph header and markings
printf "\n Relative Value Chart\n"
printf "\nName      Value (Max is $MAXQTY)\n"
printf "____________________0"
QTRSCALE=`echo "$SCALE / 4" | bc -l | awk '{printf("%.0f",$0)}'`
HALFSCALE=`echo "$SCALE / 2" | bc -l | awk '{printf("%.0f",$0)}'`
THRSCALE=`echo "$SCALE * 0.75" | bc -l | awk '{printf("%.0f",$0)}'`
LCNT=1
while [ "$LCNT" -le "$SCALE" ];
do
        case $LCNT in
                $QTRSCALE)      printf ".";;
                $HALFSCALE)     printf "|";;
                $THRSCALE)      printf ".";;
                $SCALE)         printf "|100%% ($MAXQTY)\n";;
                *)              printf "_";;
        esac
        LCNT=$(( $LCNT + 1 ))
done

# Draw graph bars
i=0
for ITEM in ${NAME[*]}
do
        # Print Category name in format along with info and bars
        LENGTH=`echo "scale=2;(( ${TOTAL[$i]} / $MAXQTY ) * $SCALE )" |\
                bc |\
                awk '{printf("%.0f",$0)}'`
        printf "%-12.12s %-6.6s |" "$ITEM" "${TOTAL[$i]}"
        BLOCKS=""
        while [ "$LENGTH" -gt "0" ]; do
                if [ "$LENGTH" -eq "1" ]; then
                        BLOCKS="$BLOCKS$ENDDELIM"
                else
                        BLOCKS="$BLOCKS$FILLER"
                fi
                LENGTH=$(( $LENGTH - 1 ))
        done
        printf "$BLOCKS\n"
        i=$(( $i + 1 ))
done
printf "\n\n"

pgraph



 ./pgraph.sh stock-list
max is 150

 Percentage Chart
____________________0_________._________|_________._________|100%
apples       ( 20%) |========
pears        ( 80%) |================================
cherries     ( 66%) |==========================
mangoes      ( 52%) |=====================
tomatoes     (100%) |========================================

#!/bin/bash
#
# PercentageGraph (pgraph)
# Basic ASCII Graphing Tool
#
# CSV format: Name,Used,Total (or Maximum)
#
# Awk isn't perfect at rounding.. .5 rounds down
#
# v1.1 sol@subnetzero.org

if [ -z $1 ]; then
        printf "Usage: pgraph [datafile]\n"
        exit 1
fi

# Set Vars
# FILLER and ENDDELIM are used for drawing bars.
ENDDELIM="="
FILLER="="
SCALE=40
INPUTFILE=$1
NAME=(`awk -F"," '{print $1}' < "$INPUTFILE"`)
USED=(`awk -F"," '{print $2}' < "$INPUTFILE"`)
TOTAL=(`awk -F"," '{print $3}' < "$INPUTFILE"`)

# Get Max qty for scaling
MAXQTY=0
for VALUE in ${TOTAL[*]}
do
        if [ "$VALUE" -gt "$MAXQTY" ]; then
                MAXQTY=$VALUE
        fi
done

echo "max is $MAXQTY"

# Make graph header and markings
printf "\n Percentage Chart\n"
printf "____________________0"
QTRSCALE=`echo "$SCALE / 4" | bc -l | awk '{printf("%.0f",$0)}'`
HALFSCALE=`echo "$SCALE / 2" | bc -l | awk '{printf("%.0f",$0)}'`
THRSCALE=`echo "$SCALE * 0.75" | bc -l | awk '{printf("%.0f",$0)}'`
LCNT=1
while [ "$LCNT" -le "$SCALE" ];
do
        case $LCNT in
                $QTRSCALE)      printf ".";;
                $HALFSCALE)     printf "|";;
                $THRSCALE)      printf ".";;
                $SCALE)         printf "|100%%\n";;
                *)              printf "_";;
        esac
        LCNT=$(( $LCNT + 1 ))
done

# Draw graph bars
i=0
for ITEM in ${NAME[*]}
do
        # Print Category name in format along with info and bars
        LENGTH=`echo "scale=2;(( ${USED[$i]} / ${TOTAL[$i]} ) * $SCALE )" |\
                bc | \
                awk '{printf("%.0f",$0)}'`
        PCT=`echo "scale=2;(( ${USED[$i]} / ${TOTAL[$i]} ) * 100)" |\
             bc |\
             awk '{printf("%.0f",$0)}'`
        printf "%-12.12s (%3.3s%%) |" "$ITEM" "$PCT"
        BLOCKS=""
        while [ "$LENGTH" -gt "0" ]; do
                if [ "$LENGTH" -eq "1" ]; then
                        BLOCKS="$BLOCKS$ENDDELIM"
                else
                        BLOCKS="$BLOCKS$FILLER"
                fi
                LENGTH=$(( $LENGTH - 1 ))
        done
        printf "$BLOCKS\n"
        i=$(( $i + 1 ))
done
printf "\n\n"

———————————————————-

Your web cams and CCTV may not be  secure.

Use a search engine with the ipaddress of the unit and one of these search terms one at a time to see if the unit is accessible. These are only a few of many.

inurl:/view.shtml
intitle:”Live View / – AXIS” | inurl:view/view.shtml^
inurl:ViewerFrame?Mode=
inurl:ViewerFrame?Mode=Refresh
inurl:axis-cgi/jpg
inurl:view/index.shtml inurl:view/view.shtml
liveapplet
intitle:liveapplet
allintitle:”Network Camera NetworkCamera”
intitle:axis intitle:”video server”
intitle:liveapplet inurl:LvAppl
intitle:”EvoCam” inurl:”webcam.html”
intitle:”Live NetSnap Cam-Server feed”
intitle:”Live View / – AXIS 206M”
intitle:”Live View / – AXIS 206W”
intitle:”Live View / – AXIS 210″

———————————————————-

Picture of Exacto knife to an existing page.
screenshotledresistorca1.png

One nice thing is that if you find a page with an educational tool that you need, under certain circumstances, you can save the page for later use. In some cases, if it is going into an educational environment, the advertisements have to go away. That is what was done with this web page. See pictures. You will also need to save the images and then edit the code to look for them locally.

for example we have a web page that has the script we want to use and the dots represent code that is not needed, we can just remote those unneeded lines lined.

before:

&lt;html&gt;
&lt;body&gt;

&lt;h1&gt;My First Web Page&lt;/h1&gt;
...
...
...
...
....
....
<span class="marked">&lt;script type="text/javascript"&gt;
document.write("&lt;p&gt;" + Date() + "&lt;/p&gt;");
&lt;/script&gt;</span>
...
...
...
...
&lt;/body&gt;
&lt;/html&gt;

after;

&lt;html&gt;
&lt;body&gt;

&lt;h1&gt;My First Web Page&lt;/h1&gt;

<span class="marked">&lt;script type="text/javascript"&gt;
document.write("&lt;p&gt;" + Date() + "&lt;/p&gt;");
&lt;/script&gt;</span>

&lt;/body&gt;
&lt;/html&gt;

———————————————————-

Love Tuxpaint, but it lacks some cut and paste features. Used the
Gimp to get around these short comings. Kind of had to plan out what I wanted to do. First was to use the picture of the video card in the Gimp.

So now I can see the picture, but the canvas is not big enough to hold what else I want. So let us make a new canvas four times bigger. Original picture was 480 x 281.

Import the picture of the card and the picture of the RPi. Actually I cut and pasted the RPi out of one of my other pictures.

Now to do a screen capture of the canvas. Then we will do a tuxpaint-import of that capture into tuxpaint.

Then we need to do a magic shift to put the pictures where we can have more room for pictures and text. Now  the pictures are centered better.

Now all that is left to do is erase some lines that were wires in the original picture and add all the new art work by hand.

Now all we have to do is take a screen shot of the canvas for the blog like we did with this one.

That’s all for now.

———————————————————-

Writing code.

Traditional:

Systems analyst:
What is problem per users.
Develop criteria and test data needed to solve a problem.
Use criteria logically using test data.

Programmer
Develop code based on data defined by criteria.
Test and rewrite code until it works.
Rewrite code for best form.

Users
Test code to see if it solves problem.
Else start over.

Another view.

———————————————————-

if you wanted to convert a decimal number to a hexadecimal number, you can do it several ways. first you could do it the old fashion way by hand.

or you could use a C language program such as:

&nbsp; #include&lt;stdio.h&gt;
int main(){
&nbsp;&nbsp;&nbsp; long int decimalNumber,remainder,quotient;
&nbsp;&nbsp;&nbsp; int i=1,j,temp;
&nbsp;&nbsp;&nbsp; char hexadecimalNumber[100];

&nbsp;&nbsp;&nbsp; printf("Enter any decimal number: ");
&nbsp;&nbsp;&nbsp; scanf("%ld",&amp;decimalNumber);

&nbsp;&nbsp;&nbsp; quotient = decimalNumber;

&nbsp;&nbsp;&nbsp; while(quotient!=0){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp = quotient % 16;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //To convert integer into character
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( temp &lt; 10)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp =temp + 48;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp = temp + 55;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hexadecimalNumber[i++]= temp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; quotient = quotient / 16;
&nbsp; }

&nbsp;&nbsp;&nbsp; printf("Equivalent hexadecimal value of decimal number %d: ",decimalNumber);
&nbsp;&nbsp;&nbsp; for(j = i -1 ;j&gt; 0;j--)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%c",hexadecimalNumber[j]);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("\n");
&nbsp;&nbsp;&nbsp; return 0;
}

Compile it  and then run it:

$ ./d2h
Enter any decimal number: 708
Equivalent hexadecimal value of decimal number 708: 2C4

or actually you could use either of two command line commands.

$ echo ‘obase=16;ibase=10;708’| bc
2C4

or

$ printf ‘%x\n’ 708
2c4

As you learn bash, you can see you can do things without getting real complicated.

———————————————————-

Try at your own risk!!!! It could brick your arduino!!

1. Minimal Arduino

I recently got really interested in Arduino hardware. For those who don’t know what it is,

 Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

 

So I looked for ways to make my own board but as I am not into electronics, I needed something really simple, where I just needed to put in components, abracadabra and it should start working. So after much research (Googling actually) I have now learned how to make a minimal Arduino clone.

PARTS LIST

ATmega168 (or similar e.g. ATmega8) (Rs. 300)
A Breadboard (Rs. 150)
7805 Voltage regulator (Rs.10)
2 LEDs (Rs. 5)
2 10 uF capacitors (Rs.5)
16 MHz clock crystal
2 22 pF capacitors
2 220 Ohm resistors
1 10k Ohm resistor
small momentary normally open (“off”) button, i.e. Omron type B3F

Note: replaced a resonator for the capacitors and the crystal.

BUILD IT

Before building the main circuit, you need to prepare a 5v supply.
Use 7805 voltage regulator, have a look at this picture:


5v voltage regulator

You need to provide 9v-12v to the INPUT and connect ground wire to GROUND. Then use OUTPUT pin for 5v output and do not forget to ground your circuit with the same GROUND pin.

Next step is to add an LED. An LED attached to power like this is a great troubleshooting trick. You’ll always know when your board is being powered as well as quickly know if your board is being shorted.

We will be using Atmega168(or similar) for our Arduino:


ATmega168

Before moving on, this image is a great resource for learning what each of the pins on your Atmega chip do in relation to the Arduino’s functions. This will clarify a lot of confusion behind why we hook up certain pins the way we do.

Start by adding a 10k ohm resistor “up” (to power) on the RESET pin in order to prevent the chip from resetting itself during normal operation. The RESET pin reboots the chip when pulled down to ground. In later steps I will show you how to add a reset switch that takes advantage of this.

  • Pin 7 – Vcc – Digital Supply Voltage
  • Pin 8 – GND
  • Pin 22 – GND
  • Pin 20 – AVcc – Suppply voltage for the ADC converter. Needs to be connected to power if ADC isn’t being used and to power via a low-pass filter if it is (a low pass filter is a circuit that cleans out noise from the power source, we aren’t using one)

After that, add a 16 MHz external clock between pin 9 and 10, and add two 22 pF capacitors running to ground on each of those pins.

This is where we add the small tactile switch so that we can reset the Arduino whenever we’d like and prepare the chip for uploading a new program. A quick momentary press of this switch will reset the chip when needed. Add the switch just above the top of the Atmega chip. Connect one leg to the RESET on the chip. Then, connect the other leg of the button to the ground.

small tactile switch

Success!
Congratulations, You just made an Arduino clone for yourself.
As of now, this arduino is of no use to you. As it is not functional.
We need a Programmer to “program” our Atmega chip.
I opted for Parallel Programmer, which is the cheapest and simplest one.

You need a male DB25 parallel port connector and some wires.


DB25 male connector

Now you need to solder some pins of this connector to your chip.

 Pin of DB25  Pin of ATmega168
 Pin 11  Pin 18
 Pin 1  Pin 19
 Pin 16  Pin 1
 Pin 2  Pin 17
 Pin 18  GROUND

Please be sure to keep the wire between the parallel port and Atmega chip short as possible.

Now we are done with the hardware part.

Connect you Arduino to your PC through Parallel Programmer and execute these commands through avrdude (Download)

Unzip avrdude into a folder and use CMD(MS-DOS) to first navigate to that new folder you just unzipped and execute the following:

avrdude.exe -p m168 -v -U hfuse:w:0xdf:m -U lfuse:w:0xc7:m -U efuse:w:0x08:m

This command will set the Fuse settings of your chip to use the external 16Mhz crystal we connected earlier (by default, the chip will use 1Mhz internal clock which is slow)

Getting started with programming with Arduino:
Download Arduino software from www.arduino.cc
Before you start programming with Arduino software, configure it to use Parallel Programmer.

  • Go to C:\Documents and Settings\YOUR USER NAME\Application Data\Arduino\
  • Open the preferences.txt file in Notepad.
  • Find the line upload.using=bootloader and change it to upload.using=parallel
Now you should be able to program and upload your code through Parallel Programmer.

———————————————————-

Soduku is an interesting game of numbers and logic. You can not lose of you play it right. The board with preset numbers already sporadically spaced on the  board can be divided into nine sections  with each section of nine squares.The numbers one through nine must be strategically placed so that no number is duplicated in any column or row. Here is your typical sections.

Section:

The whole board:

or you could mentally separate it into three columns or rows.

 

You can have a maximum of one number shown three times in any column or row. For example we already have the number eight three times but the number nine is only shown twice. so we need another nine.

In the upper right hand corner we have three possibilities where another number nine can go.  So we look at the whole board to eliminate the possibilities in our mind.

In this case, it was easy to figure out the where the third nine should go. It will not be that easy with every number. It is a process of elimination with all numbers one through nine both in columns and rows.

 

Since only one number of each can be in each square, you can also eliminate boxes where a number exists. If most of a row is done, you can also fill in numbers.

 

Lastly if you have a mini-square almost filled in you can obviously choose the last number to be filled in.

There are other hints you can pick on your own, but just wanted to share a few starter hints. Good luck.

———————————————————-

Screenshot from 2015-08-30 19:13:00

Good day.

 

 

 

 

Advertisements