How to copy videos and live video streams from the internet

How to copy videos, live video streams, or live news reports
(like from CNN) to your Windows computer

by Bob Day

September 15, 2018

1. What you will need:
   a) The VideoCacheView app from NirSoft.  Here's a link:
        http://www.nirsoft.net/utils/video_cache_view.html
        Near the bottom of the page, there's a link to
        download the app.

   b) Another useful app is MediaInfo, which is able to
        determine the format of a video file.
        A link to it is:
        https://mediaarea.net/en/MediaInfo/Download/Windows

   c) Another app is the VideoSolo Free Video Converter, which
        can convert FLV format video files to MP4 format video files.  
        Here's a link:
        https://www.videosolo.com/free-video-converter/

2. Copying a video using the Firefox browser:
   a) Play the entire video or live video stream until the end.  
        Then close the browser.

   b) Run VideoCacheView.exe, and locate your video.  You can  
        recognize it by the browser you used (in this case Firefox),
        the very recent date and time, and probably its large file
        size.  Also, note the format under "Content Type".  

   c) Make a copy of the file on your computer desktop and change
        its file name to an appropriate name.  (If you want to post
        it on YouTube, give it a very unique name so you will be
        able to find it easily.  (Note: YouTube allows you to slow
        down the speaking rate of speaker without changing the pitch
        of his or her voice — a very nice feature.))

   d) If the file's Content Type is MP4, add the extension ".mp4"
        to the filename and you're done.  If the Content Type is
        MP2T, the file is an flv format file.  In that case, add the
        extension ".flv" to the filename and run the VideoSolo app
        to convert the file to the MP4 format.  (Also see Appendix 2,
        below.)

   e) Post the video on YouTube if you'd like.

Appendix 1
   The default size of Firefox's cache buffer for temporary files
   is 50 MB (megabytes) The cache is where Firefox stores all of
   its temporary files, including video files.  If you want to
   copy videos that are longer than, say, 10 minutes, you'll
   need to increase the size of the cache (so the cache will have
   plenty of room for all the files it needs to temporarily store).  
   Here's how to do it with the Firefox browser:
   a) Enter "about:config" (without the quotes) into the address
        bar (where "http://" URLs go).  

   b) After you "accept the risk", Firefox's internal settings will
        be displayed, and starting at the top left will be a search
        window.  Enter "browser.cache.disk" (without the quotes) into
        the search window and press Enter.

   c) Then right click on "browser.cache.disk.capacity" and click on
        "Modify" and enter the value you wish.  The units are in
         kilobytes (KB).  So, for example, 50000 is fifty megabytes (MB).

   d) On the next line, if necessary, modify the value of
        "browser.cache.disk.enable" to "true".  Exit the window and
        you're done.  

Appendix 2
Often a video will be composed of a sequence of several MP2T (flv)
files, and to get the complete video, this sequence of MP2T fles must
be strung together, from earliest to latest.  To do this, first
download and install the Avidemux app.  Here's a link to the download:

http://fixounet.free.fr/avidemux/download.html

Then, do the following steps:
   a) Use Video Cache View to find the video you want.  Then copy the
        MP2T files in the sequence to a folder you've created (They'll be
        very close together in time, spaced just a few seconds apart.).  
        Rename the files with names that indicate their order in time,
        and tack onto each the extension ".flv".

   b) Bring up the Avidemux app, and drag the files in the folder, in
        time sequence, into the area next to the column of option
        selections on the left. (Note: the first file will create an
        image in this area — just copy the succeeding files onto the
        top of the image.)  Make sure that a little window saying
        "Checking if timestamp…" pops up when you drag an MP2T file
        onto the area.  If it doesn't, the file hasn't actually been
        copied.  In that case, drag the file again.

   c) Under "Output Format", select the option "MP4 Muxer".  Then click
        on the save icon (looks like a floppy disk) in the toolbar at the
        top of the window.  Give the file a name and click on "Save".  
        The output MP4 file will be saved in the folder you created for
        the MP2T files.  Exit Avidemux and you're done.

 

App to convert Ancestry.com raw data to 23andMe format

        App to convert Ancestry.com raw data to 23andMe format

On the internet I found other apps that claim to convert Ancestry raw data to
23andMe format, but the ones I found have flaws.  Among others, none of them
handled the PAR1 and PAR2 regions of the X and Y chromosomes correctly. 
Depending on what SNPs one counts as being in PAR1 and PAR2, most of them
are heterozygotic or homozygotic.   In the app I wrote, I used the limits that

23andMe uses to define the heterozygotic or homozygotic ranges.

Here's how to use the app:

1. Down load the Ancestry to 23andMe.zip file. 
    Heres a link to it:
     https://www.keepandshare.com/doc6/25655/ancestry-to-23andme-zip-6k

2. Unpack the Zip file into a folder.  

3. Copy your AncestryDNA.txt file into the same folder.  
   Make sure it is called AncestryDNA.txt.  

4. Double click on the Ancestry to 23andMe.exe file to run
   the program.  The program creates a file named
   "23andMe format file.txt" in the same folder.

5. Done!
 

Landline phone conversation recorder for Windows 10

Phone Recorder is an application for Windows 10
that allows you to join and record an ongoing telephone
conversation.  It runs under either 64-bit or 32-bit Windows.  
Phone Recorder doesn't have much of a user interface — just
two buttons: "Start recording/Stop recording" and "Exit".  
When you click on "Start recording", Phone Recorder will join
an ongoing phone conversation on the same line as that of the
modem, and the button label will change to "Stop recording".  
The conversation is stored as a .wav file in the same folder
as the Phone Recorder executable (.exe) file.  To run Phone
Recorder, you need to have a dial-up modem that has voice
capability installed on your computer.  Phone Recorder uses
only the voice feature of the modem — there's no need to
"dial-up" anywhere.  Be sure to tell the other party or
parties on the line that you are recording the conversation
if it is legally required to do so.

Here's a link to the Phone Recorder app kit:
https://dl.dropboxusercontent.com/u/97098121/Phone%20Recorder%20Kit.zip
 

Easy to Build 40 Hz Gamma Wave Flashing LED Lamp

According to an artcle in the December 8, 2016 issue of the journal Nature, an
LED light that fashes at 40 Hz, which is the frequency of Gamma wave in the
brain, may alleviate the symptoms of Alzheimer's disease. Also, a 40 Hz
fashing LED light is said to be an aid to meditaton.

In this artcle, I will describe an easy way to build a 40 Hz fashing LED foor
lamp. About all you need to know is a litle bit about electricity that you probably
learned as a kid, and a litle bit about household wiring, such as how to replace
an electrical outlet in the wall of your home.

The parts you will need
1. A DROK LCD Display Square Wave Generator,
https://www.amazon.com/DROK-Frequency-1Hz-150kHz-Adjustable-Rectangular/dp/B07F8R89YL/ref=sr_1_1?ie=UTF8&qid=1533386964&sr=8-1&keywords=DROK+LCD+Display+Square+Wave+Generator

Price on Amazon: $11.20.

2. A DC solid state relay,
Digi-Key part number CC1126-ND. Price on Digi-Key: $20.20.

3. A 12 volt DC power supply, such as this one on Amazon:
https://www.amazon.com/Selectec-12-Volt-Power-Supply/dp/B009ZZNHYC/ref=sr_1_3?ie=UTF8&qid=1533387536&sr=8-3&keywords=12+volt+laptop+power+supply

Price on Amazon: $13.99.

4. Two 12 volt LED light bulbs, such as this one on Amazon:
https://www.amazon.com/gp/product/B01M28CQ32/ref=oh_aui_search_detailpage?ie=UTF8&psc=1
Price on Amazon: $15.98.

5. Dual light bulb socket, such as this on Amazon:
https://www.amazon.com/Onite-Edison-Splitter-Adapter-Standard/dp/B01N1V4W9X/ref=sr_1_5?ie=UTF8&qid=1533388733&sr=8-5&keywords=dual+light+bulb+socket%5C
Price on Amazon: 6.99.

6. Two to six foot extension cord. Available at a local hardware store.

7. Twist-on wire connectors, such as these on Amazon:
https://www.amazon.com/Gardner-Bender-25-AWC-Assortment-Electrical/dp/B000F5TTE8/ref=sr_1_4?s=hi&ie=UTF8&qid=1533389567&sr=1-4&keywords=twist+on+wire+connectors
Price on Amazon: $2.07.

8. A standard foor lamp.

9. #22 gauge hook-up wire, such as this on Amazon:
https://www.amazon.com/Electronix-Express-Hook-Wire-Solid/dp/B00B4ZRPEY/ref=sr_1_3?s=hi&ie=UTF8&qid=1533390498&sr=1-3&keywords=hook+up+wire+22+gauge+solid
Price on Amazon: $18.95.

10. Soldering iron and solder. Soldering the connectons to the DROK Square Wave Generator is preferable but not absolutely nessesary. If you don’t solder the connectons, strip about V/8ths of an inch of insulaton of the ends of hook-up wires and loop them through the connectng holes in the DROK in twist-tie fashion, and twist tghtly.

Putting it together
1. Connect the negatve wire from the power supply to “VIN –” (the negatve input) on the DROK square wave generator.
NOTE: “
VIN -” is internally connected to GND on the output terminal screw #1 (the positve output) on the solid state relay.

2. Cut the extension cord at a convenient length, measured from its socket end.

3. Connect terminal screw #4 (the negatve input) on the solid state relay both to the Neutral (wide slot) side of the extension cord socket AND to GND on the output side of the output side of the DROK square wave generator.

4. Connect the positve wire from the power supply both to “VIN +” (the positve input) on the DROK square wave generator AND to terminal screw #1 (the positve output) on the solid state relay.

5. Connect terminal screw #2 (the positve input) on the solid state relay to PWM on the output side of the DROK square wave generator.

6. Connect terminal screw #2 (the negatve output) on the solid state relay to the HOT (narrow slot) side of the extension cord socket.

7. Turn the foor lamp of, unplug it, and screw the dual light bulb socket into its socket. Screw in the two 12 volt LED light bulbs.

8. Read the instructons that came with the DROK square wave generator.

9. Plug the power supply into the wall and set the DROK to 40Hz and the duty cycle to V0%.

10. Plug the lamp into the socket of the extension cord.

11. Turn the foor lamp on and it should now be fashing at 40 Hz! If you like, you can experiment with other frequencies and duty cycles.
 

Linear Regression: Least Squares Fit of a Straight Line to a Set of Points. Includes a Proof that the Total Variance can be Divided into Component Parts, and also Includes a Derivation of the Correlation Coefficient, Explaining its Meaning

We want to fit a straight line of the form:

(Eq. 1) or, alternatively,

(Eq. 2) to a set of data points.
 

Using the least squares method, we want to minimize the function:

(Eq. 3).

Taking partial derivatives and setting them to zero, we get:

(Eq. 4).

(Eq. 5).

Solving these equations, we get:

(Eq. 6), and

(Eq. 7),

or, (Eq. 8). 

In the following, we will assume that the number of points, n, in our data set is
quite large, say, >= 100. 
So to calculate variances we will simply divide sums
by n (rather than n-1 or n-2 to take into account degrees of freedom). 
Consequently, the variances we will calculate are only close approximations.

Using the values of a and b that we calculated above to minimize the F function,
we have:

So,
(Eq. 9),

where is the part of the total variance, that is left unexplained by the regression. 

The other part of the total variance is variance explained by the regression,
The explained and unexplained variances should add up to the total variance, i.e., that

(Eq. 10), and we will now prove that. 

Equation 10 can also be written as:

                                                           

We start the proof with:

  (identity). 

Squaring both sides and summing, we get:

. 

So the theorem is true if: 
.

Or equivalently if:

(Eq. 11).

            (A)                       (B)

From Equation 4, since we are using the optimum values for a and b, we know that:

, and, substituting for , that means that

is zero. So (B) above is true. 
From equation 5, we know that . Substituting , we get:

Simplifying, we get: ,

 

and:

. Since (B) , above, is zero, that means that (D) is zero,

           (C)                            (D)

 

which in turn means that (C) is zero. And (C) is the same as (A), so (A) is zero. 
Then, because (A) and (B) are both zero, equation 11 is zero. This proves
equation 10, that:

, i.e., that the total variance can be separated into two
non-overlapping components, the variance explained and the variance
unexplained by the regression, that added together are equal to the total variance.

Now we will look at the relationship between the total variance and the unexplained variance and define a correlation coefficient, r.

Squaring equation 1, , we get: .

Summing over n yields: , which means that

. 

Substituting for in Equation 10, we have

, or


A standard equation for the variance of a sample is:
.

And since, from equation 6,
, then

 

, or

The rightmost term on the right hand side of this equation is the square of the correlation coefficient, r.

So, (Eq. 12). 

From equation 10, we know that , or .

Substituting into equation 12, . 

So,

In words, is the ratio of the variance explained by the regression of Y on X to the total variance. This, in my opinion provides a better definition of the correlation coefficient than its usual definition as .

 

 

Cow Grazing in a Circular Pasture Problem: Solution by Calculus

"A cow is attached by a rope to a point on the perimeter 
of a circular field. How long should the rope be in terms 
of the radius of the field so that the cow can graze in 
exactly half of the field?"

This problem has been around in one form or another 
for a long time.  You can find many solutions to it 
on on the internet.  But all of the solutions I've seen 
are geometric solutions, using plane geometry.  They 
all chop up the pasture into various shapes and add up 
the area of each one.

I have found a solution using calculus that I think is 
a lot simpler and more elegant.  This solution defines 
a differential of area that is centered around the point 
on the perimeter of the pasture where one end of the 
rope is tied.  Then it integrates from the origin (zero) 
until the rope is long enough to allow the cow to graze 
on half the area of the circular pasture.  
Here's the derivation:

Let R be the radius of the cow pasture.
Let r be the length of the rope.
Let Θ be the angle between a line from the point where 
the rope is tied on the perimeter of the pasture to the 
center of the pasture, and a line of length r from where
the rope is tied on the perimeter to the edge of the 
pasture.  See diagram: 

                

1. BC is a circular arc of radius r centered at point A.  
   The length L of BC is 2Θr.
2. Cos(Θ) = AB/AD = r/(2R), so Θ = cos-1(r/(2R)).
   (Note: Angle ABD is a right angle because it intercepts
   a 180 degree arc.)
3. So L = 2Θr = 2r * cos-1(r/(2R)).
4. Consequently, one form of a differential of area of
   the pasture is dArea = 2r * cos-1(r/(2R))dr.

We want to integrate this differential along AD starting 
at point A until r is long enough so that half the area
of the pasture is enclosed, so we need to solve for x:

Wolfram’s online integrator, integrals.wolfram.com, easily solves 
the integral portion of this equation if you substitute K for R 
in the integral.  Then you can let R = 1 and use WolframAlpha to 
solve for the ratio of r to R that will result in half of the 
area of the pasture.  The answer, to 4 decimal places is 
r = R * 1.1587

About Butterscotch and How to Make Butterscotch Flavor Powder

About Butterscotch
      My sources for this are many Google searches about butterscotch on the internet. 
First, there is no such thing as "true butterscotch".  The many recipes I found have various
ratios of sugar to butter, and there is a variation in the ingredients.  So there is only
"version A" of butterscotch, "version B", "version C" and so on.  The commonality
among most of them is that they contain sugar, butter, salt, and molasses.  The sugar
can be light brown sugar, dark brown sugar, or just plain sugar.  If it's just plain sugar,
molasses is added to the recipe; otherwise, molasses is optional.  If molasses is added
it can be plain molasses or, occasionally, blackstrap molasses.  The sugar to butter
ratio varies greatly — anywhere from 4:3 to 16:1 by weight, I've read.

The sugar, butter, salt, and molasses are mixed together and cooked until the temperature
is raised to anywhere between 245 degrees F to 310 degrees F. 

One question I asked myself is why, if molasses is just mostly caramelized sugar (as many
sources on the internet say), why, if it's added separately, is it always cooked along with the
other ingredients and not added later?  After further research on the internet, I found the
answer: Molasses is NOT caramelized sugar!  Why?  To refine sugar, sugar cane is boiled in
a vacuum at 160 degrees F.  160 degrees F is well below the caramelization temperature of
sugar, which begins at about 320 degrees F.  Also at 160 degrees F the Maillard reaction
(which I'll get to shortly) is very slow, so molasses has undergone very little Maillard reaction.

Caramelization is not important for butterscotch because butterscotch is not caramelized, but
the Maillard reaction is very important since it is what develops the butterscotch flavor.  The
Maillard reaction takes place at an optimal rate between 270 and 310 degrees F.  To avoid

caramelization from occurring, among all but one of the recipes  I've seen for butterscotch,
the maximum cooking temperature is 300 degees F.

How to Make Butterscotch Flavor Powder
      I like the flavor of butterscotch a lot, and after some experimenting I figured out how to
make a butterscotch flavor powder that I could add to other things, such as yogurt.  The
following recipe is based on recipes for butterscotch I've found on the internet, plus a
couple of my own ideas, which seem to be original.

Ingredients
60 grams      dark brown sugar

30 grams      unsalted butter
1/8 tsp          salt (not sea salt)

1 1/2 Tbsp    blackstrap molasses (optional, to make the flavor "extra butterscotchy")
2 tsp             water (approximarely)

Cooking 
      Mix the ingredients together in a pan, adding just enough water to wet down the
other ingredients, set a stovetop burner in the medium heat range, and, stirring 
constantly, cook slowly until the temperature of the mixture is a carefully measured
310 to 315 degrees F.  Cooking slowly is important for giving the Maillard reaction time
to take place. (The Maillard reaction is what develops the butterscotch flavor.)  For
measuring the temperature, I use an infrared surface temperature thermometer. 
There are many brands of these infrared thermometers on Amazon.

When the mixture is cooked, pour it immediately (not letting it harden) onto a flat
surface that has been covered with a sheet of parchment paper, and let the mixture
cool for, say, 20 minutes, until it is rock solid.  Then crack it up with your food-gloved
hands, transfer it to a blade type coffee grinder, and grind it into a fine powder.  This
may require several "transfer-grind" operations.  Store the powder in a refrigerator,
and use it as desired.  When using the powder, also add some vanilla flavor or extract.

Serving size 1 Tbsp.  Makes about 7 servings.
 

“Knock Knock Unlock” Puzzle Box

This is my version of a "knock knock unlock" puzzle box.  A knock knock unlock puzzle box is a locked box that is opened by knocking on it with a particular sequence of knocks, for example "knock-pause-knock-knock-pause-knock-knock-knock" There are several versions of these boxes on the internet.  For my version, I wanted to make a box that has nothing mounted on the outside — no lights, no switches, no wires going through the box, and no outside latch.  Just a blank box on the outside.  Here are photos of and links to photos the inside and the outside of the box:

              
https://www.keepandshare.com/doc6/18671/knock-knock-unlock-box-open-jpg-65k?da=y
 

              
https://www.keepandshare.com/doc6/18668/knock-knock-unlock-box-closed-jpg-50k?da=y


PARTS
    1. Mini Pushbutton Power Switch, LV (Pololu #2808) – 3.95
    2. Mercury Tilt Switch, 1A @ 250V (Amazon) – $2.37
    3. Pololu 5V Step-Up/Step-Down voltage regulator (Pololu #2123) – $5.95
    4. Pololu A-Star 32U4 Micro microcontroller (Pololu #3101) – $12.75
    5. Anycubic Microphone Sound Detection Sensor Module (Amazon) – 6.99
    6. Hitec 35485S HS-5485HB Digital Servo (Amazon) – 24.84
    7. Micro Vibration Motor With Cable, 1.5V to 6V (Amazon) – $8.69
    8. 470 uF, 35VDC Capacitor (RadioShack #272-1030) – $1.49
    9. 1000 uF, 35VDC Capacitor (RadioShack #272-1032) – $1.99
    10. Safety 1st Spring-Loaded Cabinet & Drawer Latch (Walmart) – $3.59
    11. Pololu 3-AA Battery Holder (Pololu #142) – $0.99
    12. Breadboard (Sparkfun #PRT-12625) – $5.95
    13. Three Alkaline or Lithium size AA Batteries
    14. ArtMinds Wooden Box, 8 1/2" L, 5 5/16" W, 3 9/16" H (Michaels crafts) – $5.49

CONNECTIONS
    Mini Pushbutton Power Switch
        VIN to 4.5V battery pack
        VOUT to voltage regulator, VIN
        A to mercury switch
        B to mercury switch
        OFF to 32U4, pin 12
        GND to common ground

    Mercury switch
        To A and B on the pushbutton power switch
        (Note: The mercury switch is mounted vertically, with the
         tip down and the connection wires above.)

    Voltage regulator
        VIN to power switch, VOUT
        VOUT to 5V common positive
        GND to common ground

    32U4 Micro microcontroller
        5V to 5V common positive
        GND to common ground
        Pin 3 to microphone DO pin
        Pin 5 to servo signal wire
        Pin 9 to vibration motor red (+) wire
        Pin 12 power switch OFF

    Microphone
        + to 5V common positive
        G to common ground
        DO to 32U4 pin 3

    Servo
        Black to common ground
        Red to 5V common positive
        Signal wire to 32U4 pin 5

    Vibration Motor
        Red to 32U4 pin 9
        Black to common ground

    470 uF Capacitor
        Positive to 5V common positive
        Negative to common ground

    1000 uF Capacitor
        Positive to voltage regulator VIN
        Negative to common ground

    Cabinet & Drawer Latch
        1. Trim the top of the latch off so it will fit in the box.
        2. Drill a couple of 1/16" holes into the arm of the latch.
        3. Loop heavy sewing thread through the 1/16" holes and
            the servo arm and tie the servo to the latch.

ARDUINO CODE
    The following is just a very basic program to receive knocks and open and close
the box.  You start the program by turning the box upside down, closing the mercury
switch, and then turning the box upright.  The sequence of knocks required to open
the box is just four knocks within 30 seconds.  Add your own code to make the
required sequence of knocks more complex.

/*
This software was written by Bob Day.
It was written in May, 2016.

This software is licensed under the terms of the Creative
Commons "Attribution Non-Commercial Share Alike" license, version
3.0, which grants the limited right to use or modify it NON-
COMMERCIALLY, so long as appropriate credit is given and
derivative works are licensed under the IDENTICAL TERMS.  For
license details see

  http://creativecommons.org/licenses/by-nc-sa/3.0/
 
This source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

#include <avr/sleep.h>
#include <avr/power.h>
#include <Servo.h>
// #include <SoftwareSerial.h>
// #include <serial.h>

        // Pin assignments
static const int servo_control = 5;
static const int knock_interrupt_pin = 3;
static const int off_pin = 12;
static const int buzz_pin = 9;

        // These values should be adjusted according to your needs
static const int OPEN_ANGLE = 120;  // degrees
static const int CLOSED_ANGLE = 60; // degrees
int knocksToOpen = 4;

        // The basic objects needed
Servo servo;
volatile long knock_heard = 0;
volatile long knockOkFlag = 0;
int knock_count = 0;
int delay_count = 0;
int idx; // Index variable.
int len;
int blinkLed = 13;

// The Arduino setup() function
void setup()
{
pinMode(servo_control, OUTPUT);
pinMode(3, INPUT);
pinMode(off_pin, OUTPUT);
pinMode(buzz_pin, OUTPUT);

attachInterrupt(0, knock_detected, RISING);
servo.attach(servo_control);
delay(1000);

servo.write(CLOSED_ANGLE);
delay(1000);

knock_count = 0;
knock_heard = 0;
knockOkFlag = 0;
delay_count = 0;
} // End of setup().

void loop()
{
if (knock_count >= knocksToOpen)
  {
  knock_count = 0;
  knock_heard = 0;
  knockOkFlag = 0;
  servo.write(OPEN_ANGLE);
  delay(7000);
  servo.write(CLOSED_ANGLE);
  delay(1000);
  digitalWrite(off_pin, HIGH);     // Turn off the power.
  }
else
  {
  if (knock_count < knocksToOpen)
       {
       servo.write(CLOSED_ANGLE);
       delay(1000);
       }
  }

while(1)
  {
  knockOkFlag = 1;                 // Allow reception of knocks.
  delay(250);
  ++delay_count;
  if (delay_count >= 120)          // If 30 seconds have passed since starting,
    {
    digitalWrite(buzz_pin, HIGH);  // send a long buzz and
    delay(600);
    digitalWrite(buzz_pin, LOW);
    digitalWrite(off_pin, HIGH);   // turn off the power.
    }

  knockOkFlag = 0;                 // Knocks not allowed.
  digitalWrite(blinkLed, LOW);     // Turn off the blink LED.
  if (knock_heard == 1)
    {
    digitalWrite(buzz_pin, HIGH);  // Acknowledge the knock.
    delay(250);                    //         "
    digitalWrite(buzz_pin, LOW);   //         "
    knock_heard = 0;
    ++knock_count;
    }

  if (knock_count >= knocksToOpen)
    {
    break;
    }
  } // End of while(1).
} // End of loop().

//
// Functions
//

// Knock detected interrupt
void knock_detected()
  {
  if (knockOkFlag == 1)           // If knocks are OK,
    {
    knock_heard = 1;              // A knock was heard.
    digitalWrite(blinkLed, HIGH); // Turn on the blink LED.
    }

  knockOkFlag = 0;                // Knocks are not OK for a while.
  }

Runs Up and Down Test for Randomness — Source Code

I recently searched long and hard on the internet for source code in C language to do a runs up and down test on a sequence of numbers to test whether it was a sequence of random numbers.  I found very little.  The couple of programs had, to me, very opaque and incomprehensible code.  So I wrote my own code.  Here is a link to my C language source code:
https://www.keepandshare.com/doc6/18670/runs-test-for-randomness-zip-3k?da=y

I hope it is comprehensible to others — I've included quite a few comments in  the code to try to make it so.  The download consists of a C++ program (actually it's just C) for doing the test and an error function.  Both are intended for Windows Visual Studio, but the test program should be very easily adaptable to other platforms.  The error function might take more doing and it might be best to replace it with your own.