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]


Friday, June 20, 2014

SD Maid cleans up WSJ

I've been reading the WSJ on my Nexus 7 from time to time.  A bit of a buggy app, but tolerable.

A little while ago I noticed that my 13G of free storage on the Nexus 7 had dropped down to about 3G.

At the time I didn't realize these two things were related...  I just figured I'd used up the measly space with various things (books, music, videos, apps, etc.), and my little tablet was just overwhelmed.

So, first up, figure out what's using the storage so I can do a bit of spring cleaning.

The Android Settings app has a nice panel for Storage, and it shows you what's using storage - free storage, and storage used by apps, pictures,videos, music, downloads, cache, and misc.

Apparently I was using about 10G of Misc.  Nice.

I've been using ES File Explorer, so time to use it to trawl the filesystem looking for what's using what.  OK, apparently there is a folder on the root of the "sdcard" called ".wsj-External-data-cache" and in there are a bunch of directories, each one holding a bazillion files.  Probably about 10G worth.

OK, fine, uninstall the WSJ app.  Data cache remained.

Use ES File Explorer to delete the folder.  No go, it craps out with java memory exception when deleting folders with 10 bazillion files.  I was able to delete some folders, but there was a pernicious folder with too many files that ES File Explorer just could not delete.

I googled around and found other file explorer apps, but they all seemed to crap out when trying to delete the folder.  Argh.

I happened to stumble across "SD Maid", which also lets you trawl through the filesystem doing stuff.  This actually worked and was able to delete the remaining data cache.  It took about 10 minutes to delete everything, but was successful, no java memory exception.  Nice.


(This post reminds me of the time my MacBook filled up with disk because of the backups.  Maybe I'll post about that next.  - Apparently Time Machine on MacBooks makes backups on the local disk, for times you wanted to restore a file accidentally deleted.  Is all fun and games until you use about 400G of your disk space on backups.)