Thursday, December 25, 2014

Here is some javascript for displaying random numbers:





<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>New Web Project</title>
    </head>
    <body>
        <h1>New Web Project Page</h1>

        Max Number:
        <input id="maxnum" type="number" />
        Seconds of delay:
        <input id="delay" type="number" />

        <br />
        <button type="button" onclick="go()">
            Go!
        </button>

        <button type="button" onclick="stop()">
            Stop!
        </button>

        <p id="message1">

        </p>
        <p id="message2" style="font-size: 200px">

        </p>

        <script>
var interval;

function go() {
var maxnum = document.getElementById("maxnum").value;
var delay = document.getElementById("delay").value;
document.getElementById("message1").innerHTML = "you typed in maxnum=" + maxnum + " and delay=" + delay + "";
clearInterval(interval);
update();
interval = setInterval(function() {
update();
}, delay * 1000);

}

function stop() {
   clearInterval(interval);
}

var prevnum = -1;
function update() {
var maxnum = document.getElementById("maxnum").value;
var number;
do {
number = Math.floor((Math.random() * maxnum) + 1);
} while (number == prevnum);
document.getElementById("message2").innerHTML = number;
// document.getElementById("message2").style.fontSize="xx-large";
prevnum = number;
}
        </script>

    </body>
</html>

Wednesday, December 24, 2014

systemd

After recently upgrading an ancient system, I realized that my custom init scripts don't quite start in the same (kludged) order now that my Fedora box is using systemd.  So, a quick update is in order.

Jumping into man systemd and systemctl isn't particularly enlightening.

Helpful sites are:
http://www.linux.com/learn/tutorials/788613-understanding-and-using-systemd
man systemd.service



Create /usr/lib/systemd/system/[thingy].service.  This is the master holding place for configs and init.

To get things to start automatically at boot, symlink:
ln -s /usr/lib/systemd/system/[thing].service /etc/systemd/system/[thing].service

Edit /usr/lib/systemd/system/[thingy].service:

[Unit]
Description=Network Stuff
After=syslog.target network.target

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/[thingy] start

[Install]
WantedBy=multi-user.target


For a more persistent service:

[Unit]
Description=Network Stuff
After=syslog.target network.target

[Service]
Type=forking   (could be simple if the process does not fork)
ExecStart=/usr/local/sbin/[thingy] start
PIDFile=/var/run/blah.pid

[Install]
WantedBy=multi-user.target




To activate:

systemctl daemon-reload
systemctl enable [thingy]

To see status:

systemctl list-unit-files --type=service
systemctl status [thingy]