mirror of https://github.com/tLDP/LDP
new
This commit is contained in:
parent
b52d5d3a90
commit
dfc2940d26
|
@ -0,0 +1,42 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Script author: Joseph Steinhauser
|
||||||
|
# Lightly edited by ABS Guide author, but not commented.
|
||||||
|
# Used in ABS Guide with permission.
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#-- File: ascii.sh Print ASCII chart, base 10/8/16 (JETS-2012)
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#-- Usage: ascii [oct|dec|hex|help|8|10|16]
|
||||||
|
#--
|
||||||
|
#-- This script prints out a summary of ASCII char codes from Zero to 127.
|
||||||
|
#-- Numeric values may be printed in Base10, Octal, or Hex.
|
||||||
|
#--
|
||||||
|
#-- Format Based on: /usr/share/lib/pub/ascii with base-10 as default.
|
||||||
|
#-- For more detail, man ascii . . .
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
[ -n "$BASH_VERSION" ] && shopt -s extglob
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
oct|[Oo]?([Cc][Tt])|8) Obase=Octal; Numy=3o;;
|
||||||
|
hex|[Hh]?([Ee][Xx])|16|[Xx]) Obase=Hex; Numy=2X;;
|
||||||
|
help|?(-)[h?]) sed -n '2,/^[ ]*$/p' $0;exit;;
|
||||||
|
code|[Cc][Oo][Dd][Ee])sed -n '/case/,$p' $0;exit;;
|
||||||
|
*) Obase=Decimal
|
||||||
|
esac # CODE is actually shorter than the chart!
|
||||||
|
|
||||||
|
printf "\t\t## $Obase ASCII Chart ##\n\n"; FM1="|%0${Numy:-3d}"; LD=-1
|
||||||
|
|
||||||
|
AB="nul soh stx etx eot enq ack bel bs tab nl vt np cr so si dle"
|
||||||
|
AD="dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us sp"
|
||||||
|
|
||||||
|
for TOK in $AB $AD; do ABR[$((LD+=1))]=$TOK; done;
|
||||||
|
ABR[127]=del
|
||||||
|
|
||||||
|
IDX=0
|
||||||
|
while [ $IDX -le 127 ] && CHR="${ABR[$IDX]}"
|
||||||
|
do ((${#CHR}))&& FM2='%-3s'|| FM2=`printf '\\\\%o ' $IDX`
|
||||||
|
printf "$FM1 $FM2" "$IDX" $CHR; (( (IDX+=1)%8))||echo '|'
|
||||||
|
done
|
||||||
|
|
||||||
|
exit $?
|
|
@ -0,0 +1,38 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# ASCII table script, using awk.
|
||||||
|
# Author: Joseph Steinhauser
|
||||||
|
# Used in ABS Guide with permission.
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#-- File: ascii Print ASCII chart, base 10/8/16 (JETS-2010)
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#-- Usage: ascii [oct|dec|hex|help|8|10|16]
|
||||||
|
#--
|
||||||
|
#-- This script prints a summary of ASCII char codes from Zero to 127.
|
||||||
|
#-- Numeric values may be printed in Base10, Octal, or Hex (Base16).
|
||||||
|
#--
|
||||||
|
#-- Format Based on: /usr/share/lib/pub/ascii with base-10 as default.
|
||||||
|
#-- For more detail, man ascii
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
[ -n "$BASH_VERSION" ] && shopt -s extglob
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
oct|[Oo]?([Cc][Tt])|8) Obase=Octal; Numy=3o;;
|
||||||
|
hex|[Hh]?([Ee][Xx])|16|[Xx]) Obase=Hex; Numy=2X;;
|
||||||
|
help|?(-)[h?]) sed -n '2,/^[ ]*$/p' $0;exit;;
|
||||||
|
code|[Cc][Oo][Dd][Ee])sed -n '/case/,$p' $0;exit;;
|
||||||
|
*) Obase=Decimal
|
||||||
|
esac
|
||||||
|
export Obase # CODE is actually shorter than the chart!
|
||||||
|
|
||||||
|
awk 'BEGIN{print "\n\t\t## "ENVIRON["Obase"]" ASCII Chart ##\n"
|
||||||
|
ab="soh,stx,etx,eot,enq,ack,bel,bs,tab,nl,vt,np,cr,so,si,dle,"
|
||||||
|
ad="dc1,dc2,dc3,dc4,nak,syn,etb,can,em,sub,esc,fs,gs,rs,us,sp"
|
||||||
|
split(ab ad,abr,",");abr[0]="nul";abr[127]="del";
|
||||||
|
fm1="|%0'"${Numy:- 4d}"' %-3s"
|
||||||
|
for(idx=0;idx<128;idx++){fmt=fm1 (++colz%8?"":"|\n")
|
||||||
|
printf(fmt,idx,(idx in abr)?abr[idx]:sprintf("%c",idx))} }'
|
||||||
|
|
||||||
|
exit $?
|
|
@ -0,0 +1,126 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# bingo.sh
|
||||||
|
# Bingo number generator
|
||||||
|
# Reldate 20Aug12, License: Public Domain
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
# This script generates bingo numbers.
|
||||||
|
# Hitting a key generates a new number.
|
||||||
|
# Hitting 'q' terminates the script.
|
||||||
|
# In a given run of the script, there will be no duplicate numbers.
|
||||||
|
# When the script terminates, it prints a log of the numbers generated.
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
MIN=1 # Lowest allowable bingo number.
|
||||||
|
MAX=75 # Highest allowable bingo number.
|
||||||
|
COLS=15 # Numbers in each column (B I N G O).
|
||||||
|
SINGLE_DIGIT_MAX=9
|
||||||
|
|
||||||
|
declare -a Numbers
|
||||||
|
Prefix=(B I N G O)
|
||||||
|
|
||||||
|
initialize_Numbers ()
|
||||||
|
{ # Zero them out to start.
|
||||||
|
# They'll be incremented if chosen.
|
||||||
|
local index=0
|
||||||
|
until [ "$index" -gt $MAX ]
|
||||||
|
do
|
||||||
|
Numbers[index]=0
|
||||||
|
((index++))
|
||||||
|
done
|
||||||
|
|
||||||
|
Numbers[0]=1 # Flag zero, so it won't be selected.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
generate_number ()
|
||||||
|
{
|
||||||
|
local number
|
||||||
|
|
||||||
|
while [ 1 ]
|
||||||
|
do
|
||||||
|
let "number = $(expr $RANDOM % $MAX)"
|
||||||
|
if [ ${Numbers[number]} -eq 0 ] # Number not yet called.
|
||||||
|
then
|
||||||
|
let "Numbers[number]+=1" # Flag it in the array.
|
||||||
|
break # And terminate loop.
|
||||||
|
fi # Else if already called, loop and generate another number.
|
||||||
|
done
|
||||||
|
# Exercise: Rewrite this more elegantly as an until-loop.
|
||||||
|
|
||||||
|
return $number
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print_numbers_called ()
|
||||||
|
{ # Print out the called number log in neat columns.
|
||||||
|
# echo ${Numbers[@]}
|
||||||
|
|
||||||
|
local pre2=0 # Prefix a zero, so columns will align
|
||||||
|
#+ on single-digit numbers.
|
||||||
|
|
||||||
|
echo "Number Stats"
|
||||||
|
|
||||||
|
for (( index=1; index<=MAX; index++))
|
||||||
|
do
|
||||||
|
count=${Numbers[index]}
|
||||||
|
let "t = $index - 1" # Normalize, since array begins with index 0.
|
||||||
|
let "column = $(expr $t / $COLS)"
|
||||||
|
pre=${Prefix[column]}
|
||||||
|
# echo -n "${Prefix[column]} "
|
||||||
|
|
||||||
|
if [ $(expr $t % $COLS) -eq 0 ]
|
||||||
|
then
|
||||||
|
echo # Newline at end of row.
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$index" -gt $SINGLE_DIGIT_MAX ] # Check for single-digit number.
|
||||||
|
then
|
||||||
|
echo -n "$pre$index#$count "
|
||||||
|
else # Prefix a zero.
|
||||||
|
echo -n "$pre$pre2$index#$count "
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# main () {
|
||||||
|
RANDOM=$$ # Seed random number generator.
|
||||||
|
|
||||||
|
initialize_Numbers # Zero out the number tracking array.
|
||||||
|
|
||||||
|
clear
|
||||||
|
echo "Bingo Number Caller"; echo
|
||||||
|
|
||||||
|
while [[ "$key" != "q" ]] # Main loop.
|
||||||
|
do
|
||||||
|
read -s -n1 -p "Hit a key for the next number [q to exit] " key
|
||||||
|
# Usually 'q' exits, but not always.
|
||||||
|
# Can always hit Ctl-C if q fails.
|
||||||
|
echo
|
||||||
|
|
||||||
|
generate_number; new_number=$?
|
||||||
|
|
||||||
|
let "column = $(expr $new_number / $COLS)"
|
||||||
|
echo -n "${Prefix[column]} " # B-I-N-G-O
|
||||||
|
|
||||||
|
echo $new_number
|
||||||
|
done
|
||||||
|
|
||||||
|
echo; echo
|
||||||
|
|
||||||
|
# Game over ...
|
||||||
|
print_numbers_called
|
||||||
|
echo; echo "[#0 = not called . . . #1 = called]"
|
||||||
|
|
||||||
|
echo
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
|
# Certainly, this script could stand some improvement.
|
||||||
|
#See also the author's Instructable:
|
||||||
|
#www.instructables.com/id/Binguino-An-Arduino-based-Bingo-Number-Generato/
|
Loading…
Reference in New Issue