Chit chat

———-

Went through the old closet and found a few legacy parts or two.

Was able to use a couple of posts from chat sites as the basis for an article or two.

—————————————————
Play the lottery? Here is a simple random number generator to pontificate the numbers. Run it as many times as there are picks.

lg.sh:

echo Lottery generator
echo
echo -n "Enter number of balls: "
read nodf
echo -n "Enter number of choices: "
read b
declare -i X=$b
for i in $(seq 1 1 $nodf)
do
NUM=$[ ( $RANDOM % $X ) + 1 ];
echo "The winner is for ball number $i:" $NUM
done

Enter number of balls: 5
Enter number of choices: 50
The winner is for ball number 1: 32
The winner is for ball number 2: 43
The winner is for ball number 3: 23
The winner is for ball number 4: 18
The winner is for ball number 5: 38

Don’t forget to “chmod +x” it. Great for choosing winners randomly in a contest. Write the number down after each toss. I will let you mod the code to save the numbers.

Note: it does not check for duplicates.

Another way to do it.

usage ./rndom choicesperball numberofballs

$ ./rndom.sh 50 5

Choices per ball are 50 and the number of balls is 5

Ball number 1 is 35
Ball number 2 is 31
Ball number 3 is 6
Ball number 4 is 42
Ball number 5 is 3

$ cat rndom.sh

#!/bin/bash
clear
echo “Choices per ball are $1 and the number of balls is $2”
echo
for (( c=1; c<=$2; c++ ))
do
echo “Ball number $c is $[($RANDOM % $1)]”
done

Note: this is a good way to give out prizes at a meeting. Just make sure everyone has their own number.

One last variation:

$ shuf -i 1-49 -n18 | xargs -n6
41 34 28 4 36 45
7 2 31 25 38 14
44 32 6 17 11 46
$ shuf -i 1-49 -n24 | xargs -n6
41 13 10 45 29 30
47 43 33 9 32 34
18 36 14 44 48 8
38 31 26 6 35 39

$ shuf -i 1-49 -n28 | xargs -n7
34 10 5 45 43 35 2
42 18 7 22 30 47 23
13 6 19 49 48 4 11
24 8 20 29 31 17 27

—————————————————

Not really what I had in mind…

Had to stay at my brother’s house during a recent summer while the AC was being replaced. While there, he was kind enough to let me access his wifi. It was real easy. You just log in and your on-line. The neat part of it was you are blocked out of using the local area network. He uses a wireless router from that company in Cupertino, California. I wanted to have the same thing but did not want to spend one hundred plus dollars on a new router like he did.

Recently I purchased a used Cisco Linksys wrt-54g from the local Goodwill store specializing in computer stuff real cheap. Knew that you could upgrade the firmware with dd-wrt, openwrt, and a host of others. In fact, I think I had installed dd-wrt. Wanted more like what my brother has. After doing some research, I found some firmware. Known as CoovaAP, it is known is what is called a Wisp (wifi inTERnet service provider. Well I wanted it for our intranet (local area full service network without internet access).

We have sort of our own mini cloud (web, media and etc.) servers. So it still is a Wisp (Wireless inTRAnet service provider. You can also set this software for a stand alone machine acting as a wireless access point.

Installed CoovaAP on the router and now it can be accessed within the range of the router. This is a great set up say for a school, church, or in a small town. More information at: http://www.coova.org/CoovaAP
and http://www.howtoforge.com/wireless_hotspot_howto
http://www.howtoforge.com/wireless_hotspot_howto 

—————————————————
When considering getting an old computer, one of the biggest telltale features to consider before acquiring the system (unless you get it for free) are the capacitors. Avoid the system if it has bad capacitors.

Learning how to de-solder and solder can be helpful. Why throw away a good motherboard if you can fix it without too much trouble.Hopefully that is what I can do with this motherboard.

A while back lots of brand name computers had bad capacitors.  People were getting the monitors and computers for scrap. Once the caps were replaced, the equipment was sold for full resale price.

 

—————————————————

If you are into arduino type stuff, this may interest you.
Avrian Jump

===========

A very simple ladder language for programming ATMega168s from a web browser.

This started out as a desire to be able to program an [Arduino][] from an iOS device.  Since it doesn’t seem like compiler tools of any sort would get into the app store, I figured something would need to be done in HTML5.  And if a [PC emulator][pcemu] could be written in javascript, so could something like this.

However, recreating the Arduino IDE in HTML seemed like too much work, at least for a first try.  So I reduced the project into something much simpler, while still putting real machine code into the AVR’s flash.  A simple ladder language that compiled into AVR assembly, which would be assembled into machine code, seemed like like a resonable reduction.  With that I could take advantage of the [Audioino][] bootloader, to load right from the web page.

This is still unfinished, go see the TODO file.

Also go read issue #2, playing sounds encoded in data URIs in iOS 5.1 is broken. *sigh*

Try it out! [Avrian Jump](http://tadpol.github.com/Avrian-Jump/avrianjump.html)

Some other ways (likely better) of putting Arduino IDEs into web browsers:
– [wifino](http://www.wifino.com/)

[codebender](http://codebender.cc/)

The Ladder
———-

Each rung on the ladder has a single test and multiple actions.  Tests can check the digital pins, analog pins, and a couple of variables.  Each action can set a digital pin, a PWM output, or a variable.  Analog, PWM, and variables are 16bit values.

There is no ‘setup()’.  Analog pins are always analog inputs.  When specified in a test, a digital pin is set to an input then read.  When specified in an action, it is set to an output then set.

PWM code is still non-existant, so how this will actually work is up in the air.  How I want it to work is:  Specifying a pin in an action as a PWM output makes it a PWM output.  Specifying a pin in a test stops it from doing PWM output.  Specifying a digital state for the pin in an action also stops it from doing PWM output.

There is an ascii format of the ladders.  This was done because it seemed like it could be neat to be able to tweet ladders.  You can view the ascii format, and also load ladders from it.  The ascii parser skips anything it doesn’t recognise; it is a bit too forgiving at times.

An example program:

#Fast Blink LED
:T;A+=1
:A=16383;D13=1
:A=32767;D13=0,A=0

Mostly though, a ladder is converted into AVR assembly.

The Assembler
————-

The assembler is pretty basic. Lots of features commonly found in other assemblers are currently missing.  It does assemble the mneonics from [Atmel’s pdf][avrasm] into machine code.  It supports labels, but not local labels.  It has simple parameter replacement, so common names can be defined for IO registers and memory regions and things.  It can also specify where in memory to put the machine code, and can specify immeadiate words to save in the machine code.

This assembler doesn’t know about the various AVR devices, and so will happily assemble any of the known mnemonics into the output.  Even if your target device has no idea what to do with them.  It has assembled blink tests for the ATmega168 and the ATTiny13, so it seems pretty flexable. (Avrian Jump currently only supports the ATmega168 though.  Maybe add others in the future, but would have to figure the bootloader thing out first.)

Outputs
——-

A ladder can be compiled into a few different formats:

– ASCII
– This the only form can can be converted back into a ladder.
– This is for sharing your ladder with others, or saving a ladder for later.
– S19
– If you don’t have an [Audioino][] bootloader, but still want to use a ladder.  A S19 can be ded with [avrdude][].
– WAV
– A [Audioino][] compatible wav file for loading the ladder onto an ATmega168 with the [Audioino][] bootloader installed.
– Assembler
– This is mostly around for debugging the ladder compiler.  It can be interesting to look at  too.

License
——-

Copyright (c) 2012 Michael Conrad Tadpol Tilstra

Licensed under the MIT License.

[Arduino]:http://www.arduino.cc/
[pcemu]:http://bellard.org/jslinux/
[avrasm]:http://www.atmel.com/atmel/acrobat/doc0856.pdf
[avrdude]:http://ladyada.net/learn/avr/avrdude.html
[Audioino]:http://www.hobby-roboter.de/forum/viewtopic.php?f=4&t=128&p=531

————————————
Football time again. Here is a quick script to get some nfl scores. You will have to read the script to set the values for what part of the season and what week to show. I did not put a lot of time into formatting as it is easy for me to read as is.  The script might be use for other sports depending on the format.

------------------------------------------------
nfl data for phase = 1 week = 3 season = 2014
------------------------------------------------

       Home           Score              Away

Thursday, August 14 - (Preseason)
Jacksonville 19 - 20 Chicago Final
Friday, August 15 - (Preseason)
Philadelphia 35 - 42 New England Final
Tennessee 24 - 31 New Orleans Final
Detroit 26 - 27 Oakland Final
San Diego 14 - 41 Seattle Final
Saturday, August 16 - (Preseason)
Green Bay 21 - 7 St. Louis Final
NY Jets 25 - 17 Cincinnati Final
Baltimore 37 - 30 Dallas Final
NY Giants 27 - 26 Indianapolis Final
Buffalo 16 - 19 Pittsburgh Final
Miami 20 - 14 Tampa Bay Final
Atlanta 7 - 32 Houston Final
Arizona 28 - 30 Minnesota Final
Sunday, August 17 - (Preseason)
Denver 34 - 0 San Francisco Final
Kansas City 16 - 28 Carolina Final
Monday, August 18 - (Preseason)
Cleveland 23 - 24 Washington Final

Standings

* AFC
* NFC

East

East
Team W L T Pct
NY Jets 2 0 0 1.000
Miami 1 1 0 .500
New England 1 1 0 .500
Buffalo 1 2 0 .333


North

North
Team W L T Pct
Baltimore 2 0 0 1.000
Pittsburgh 1 1 0 .500
Cincinnati 0 2 0 .000
Cleveland 0 2 0 .000


South

South
Team W L T Pct
Houston 1 1 0 .500
Jacksonville 1 1 0 .500
Tennessee 1 1 0 .500
Indianapolis 0 2 0 .000


West

West
Team W L T Pct
Denver 2 0 0 1.000
Kansas City 1 1 0 .500
Oakland 1 1 0 .500
San Diego 1 1 0 .500


East

East
Team W L T Pct
NY Giants 3 0 0 1.000
Washington 2 0 0 1.000
Dallas 0 2 0 .000
Philadelphia 0 2 0 .000


North

North
Team W L T Pct
Chicago 2 0 0 1.000
Minnesota 2 0 0 1.000
Detroit 1 1 0 .500
Green Bay 1 1 0 .500


South

South
Team W L T Pct
New Orleans 2 0 0 1.000
Atlanta 1 1 0 .500
Carolina 1 1 0 .500
Tampa Bay 0 2 0 .000


West

West
Team W L T Pct
Arizona 1 1 0 .500
Seattle 1 1 0 .500
San Francisco 0 2 0 .000
St. Louis 0 2 0 .000


Full Standings

---------------------------------------------



 ####################################
# Score  Grabber
#
#===============================
# Assignments
# --------------------------------
datafile="nflscorefile"
a=1
flag=0
week=3
# phase 1 is preseason phase 2 is regular season #phase 3 is
phase=1
season=2014
#finished week = 1 unfinished week = 0
weekfinished=1
league="nfl"
# end assignments
#=================================
#
# Get data file
#---------------------------------
case $weekfinished in
1)
elinks "http://sports.yahoo.com/$league/scoreboard/?week=$week&phase=$phase&season=$season"  > $datafile
;;
0)
elinks "http://sports.yahoo.com/$league/scoreboard/"  > $datafile
;;
*)
#
;;
esac
#=================================
#
# Extract and display data
#---------------------------------
while read line
do fdata[$a]=$line
echo $line | grep -q "Home Score Away"
if  [ $? -eq 0 ]; then
# header
clear
echo
echo ------------------------------------------------
echo  $league  data for phase = $phase  week = $week  season = $season
echo ------------------------------------------------
echo
echo "       Home           Score              Away"
echo ""
let "flag = 1"
fi
if [ $flag -eq 1 ]; then
echo $line | grep -q "Latest NFL Videos"
if [ $? -eq 0 ]; then
let "flag = 0"
else
echo $line | grep -q "Home Score Away"
if  [ $? -ne 0 ]; then
case $weekfinished in
1)
echo $line | sed 's/\[.*\]//'
;;
0)
echo $line
;;
*)
#
;;
esac
fi
fi
fi
let "a += 1"
done < $datafile
# footer
echo ---------------------------------------------
echo
#===============================
# End.
################################

---------------------------------------------------

You could always go to the brand name software, but it does not always fit especially on embedded devices. Linux and BSD are more diversified.

http://www.instructables.com/id/Give-your-Cisco-Linksys-NSLU2-some-muscle-part-1/

--------------------------------------------------

Graphic is nice but what is the date for a particular day. How about the day 214? Supposedly close to the hottest day of the year, then what actual day is that?

Useage: ./main dayofyear year

$ ./main 214 2014
Result: day 214 of year 2014 is '08/02/2014'.

To confirm it:

Screenshot - 08232014 - 08:11:48 PM

So it looks like August 2, is near the hotest day of the year.

$ gcc main.c -o main

main.c

 #define _XOPEN_SOURCE /* glibc2 needs this for strptime */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>  
#include <errno.h>

int to_date(
  char * date,
  const size_t size,
  const char * fmt,
  const short unsigned int day_of_year,
  const short unsigned int year)
{
  char buffer[16] = "";

  sprintf(buffer, "%hu %hu", day_of_year, year);

  {
    struct tm t = {0};
    char * presult = strptime(buffer, "%j %Y", &t);

    if ((NULL == presult) || ('\0' != *presult))
    {
      errno = EINVAL;
      return -1;
    }

    strftime(date, size, fmt, &t);
  }

  return 0;
}

int main(int argc, char ** argv)
{
  if (2 > argc)
  {
    fprintf(stderr, "Missing arguments. Usage: %s day-of-year year\n", argv[0]);
    return EXIT_FAILURE;
  }

  short unsigned int day_of_year = atoi(argv[1]);
  short unsigned int year = atoi(argv[2]);
  char date[16] = "";

  if (-1 == to_date(date, sizeof(date), "%m/%d/%Y", day_of_year, year))
  {
    perror("to_date() failed");
    return EXIT_FAILURE;
  }

  printf("Result: day %d of year %d is '%s'.\n", day_of_year, year, date);

  return EXIT_SUCCESS;
}

---------------------------------------------------

Arpanet

Ascii is usally eight binary characters of ones or zeroes. So you can take the first 8 ones and zeros for the first character.

Then to further split out the whole code sequence:

01000001 01010010 01010000 01000001 01001110 01000101 01010100

Then you can convert on character at a time.  You can just look at a table or write a program to do it.

 


</pre>
<pre><code class="language-js"><html>
<head>

<script type="text/javascript">
var input_id = "bin_text";
var answer_id = "answer";

function convertToASCII() {
 var bin_text = document.getElementById(input_id);
 var answer = document.getElementById(answer_id);

 if (!answer) {
  alert("Error: No element with id \""+answer_id+"\".");
  return;
 }
 if (bin_text)
  var text = bin_text.value;
 else {
  error("No element with id \""+input_id+"\".");
  return;
 }
 var divisible = text.length % 8;
 var nonBinary = /[^0|1]/.test(text);
 if (text.length > 0 && divisible == 0 && !nonBinary) {
  var regex = /[0|1]{8}/g;
  var str = text.match(regex);
  var code = 0;
  var placeVal, exp, digit;
  var ascii = '';
  while (str.length > 0) {
   code = 0;
   for (var i=0; i<str[0].length; i++) {
    placeVal = 7-i;
    exp = Math.pow(2, i);
    digit = str[0].charAt(placeVal);
    code += exp*digit;
   }
   str.shift();
   ascii += String.fromCharCode(code);
  }
  answer.innerHTML = "<p class=\"binary\">" + ascii + "</p>";
 }
 else {
  error("Malformed binary.");
  return;
 }

 function error(errText) {
  answer.innerHTML = "<span class=\"error\">Error: " + errText + "</span>";
 }
}
</script>

<style type="text/css">
.block {
 width: 45%;
 border: 1px solid #000000;
 padding: 10px;
}
.binary {
 background-color: #C6FFC7;
 padding: 3px;
}
.error {
 background-color: #FFC6C6;
 padding: 3px;
}
</style>

</head>
<body>

<div style="float:left;" class="block">
 <form onSubmit="convertToASCII(); return false;">
  <p>Enter some binary to decode:</p>

  <input type="text" id="bin_text"/>
 </form>
</div>

<div style="float:right;" class="block">
 <p id="answer"><br/></p>
</div>

</body>
</html></code></pre>
<pre>

---------------------------------------------------

Sometimes simple just works. Rice boiled in liquid from poaching chicken breasts,

green peas, and sauteed ground turkey.

SUNP0030

Good day,

Advertisements