Monday, February 17, 2014

Java's java.util.Date Class

Teaching Java programming to novices forces me to sometimes revisit the basics in my own understanding, or the edges of what I understand.

java.util.Date has come up a couple times this semester, and I thought I would verify the behavior of Date for dates at and before 1970-01-01. Here's my simple test code:

//Time-stamp: <2014-02-17 11:14:34 jdm>

import java.util.Date;

public class TimeZero {

  public static void main(String[] args) {

    final int yearsAgo = Integer.parseInt(args[0]);
    final double msAgo = yearsAgo
      * 365.25 // days per year
      * 24     // hours per day
      * 60     // minutes per hour
      * 60     // seconds per minute
      * 1000;  // ms per second
    final Date d = new Date((long) -msAgo);
    System.out.println(d);

  } // main()

} // class TimeZero

I'm neglecting leap seconds in my calculation of ms before 1970-01-01 (called msAgo). Assuming a year averages 365.25 days is also not quite right, since most years divisible by 100 are not leap years. Providing zero as input acts as expected (once one takes the time zone difference between here and Greenwich into account):

> java TimeZero 0
Wed Dec 31 19:00:00 EST 1969

Three years earlier seems to be about right, given that 1968 was a leap year:

> java TimeZero 3
Sun Jan 01 01:00:00 EST 1967

1000 years before 1970 looks good:

> java TimeZero 1000
Sat Dec 18 19:00:00 EST 969

Let's look around near the beginning of CE and the end of BCE (boundary conditions):

> java TimeZero 1967
Tue Dec 19 01:00:00 EST 2
> java TimeZero 1968
Sun Dec 18 19:00:00 EST 1
> java TimeZero 1969
Sat Dec 18 13:00:00 EST 1

This seems odd, but the Gregorian calendar does not have a year zero (see https://en.wikipedia.org/wiki/Gregorian_calendar) and Date.toString() does not include CE/BCE indication. I played around with calendars in my locale to get the era, but cal.get(Calendar.ERA) returns an int, which makes no sense whatsoever, and the problem isn't interesting enough to spend more time on.

However, I am willing to say the Java Date and Calendar hierarchies are entirely too complicated for day-to-day uses. This is one of the few places where I endorse using non-standard class hierarchies.

Sunday, September 8, 2013

Common Fate of Android Tablets, or a Quick 2013 Nexus 7 Review

I'm on my third Android tablet. Or fourth, but who's counting?

My first tablet was a Samsung Galaxy 5 bought in September 2012. This was mis-marketed as an MP3 player, which it did fine, but 5" was a great size for a handheld GPS device walking through cities, and fit easily into most pockets. It included an FM receiver, rear and front facing cameras, etc. I liked it. The big drawbacks were that it was too small for most reading or surfing activities, and it didn't have enough RAM to upgrade past Android 2.3.5. In December I managed to find the one place on Charles Ave where there was a drop-off between the sidewalk and the adjacent turf, stepped wrong, and fell, landing on my shoulder and on the Galaxy that had slipped out of my chest pocket. No Gorilla glass on this one.

I replaced it with a Nexus 10, decided that was too big, and replaced that immediately with a 2012 Nexus 7.

The Nexus 7 was overall fine, but the sound quality of the built-in speakers was terrible and produced insufficient volume to listen to podcasts or streaming radio from just a few feet away or with any background noise. The UI was sluggish. Touch a search area, and wait a few seconds before the keyboard appears. Type a key, and wait a few seconds before the character appears on the screen. No built-in FM receiver, but with TuneIn, this is not usually a big deal. Other than the speakers, the largest deficiency was the lack of a rear-facing camera.  Got QR Droid? You won't be using it on this thing. I also found 16 GB to be slightly restrictive, but of course there is AndFTP's sftp feature, and my home desktop runs an sftp server, so moving stuff back-and-forth was a breeze--a great improvement over plugging in the USB cable and hoping Linux decides to recognize the device. Anyhow, I get around 20Mb/s between my Nexus and desktop via 802.11 (and an Ethernet hop). The one time I had two droids downloading from the server concurrently I got 30Mb/s measured at the server. Not bad.

I liked the size of the Nexus 7: fairly easy to hand-carry, and I picked up a small messenger bag that can carry that and a few other things while I wander about listening to podcasts.

Friday I dropped my Nexus 7. Even though it was in a decent M-Edge cover, the screen cracked, and much of the screen no longer behaves as a touch screen. No Gorilla glass on this one, either.

So I picked up a 2013 Nexus 7. I have not had it long, but my initial impression is that Asus did a great job. The sound quality is okay, but importantly it can kick out enough volume to be easily heard from several feet away. The UI is more responsive than the older Nexus 7. The rear-facing camera is a great addition. 32 GB of flash memory is a big improvement over my past 16 GB--I won't have to juggle among movies on the device.

I'll probably write more about the 2013 Nexus 7 later.

Aside: the guy from the Office Depot (la oficina de la marihuana) really, really wanted to sell me a protection plan for the Nexus. He went so far as to tell me I'd probably want to replace the battery in a year or so. Despite my tendency to break things, I never buy protection plans, as they are usually pure profit for the seller.

Sunday, August 25, 2013

Slightly Interesting Javascript Benchmark

I have an Asus CG5275 desktop, and decided to try out the Mandelbrot JavaScript benchmark at http://alexey.radul.name/ideas/2013/cleverness-of-compilers/ with the three browsers I use most, Chrome 29.0.1547.57, Firefox 23.0, and Opera 12.16. I expected Opera to be the slowest, and was not disappointed.

The mild surprise was that Firefox was almost four times as fast as Chrome. Here are my timings on the Asus with the above-mentioned URL and browsers:

Browser             Size    Time      Relative
Chrome 29.0.1547.57 500x500  9562 ms  3.86
Firefox 23.0        500x500  2478 ms  1
Opera 12.16         500x500 19464 ms  7.85

Opera took just about twice as long as Chrome, and Firefox was almost 4 times as fast as Chrome. This is on an Intel i5 at 3.2 GHz running Linux Mint 15, Mate, kernel 3.8.0-29-generic. It's a 4-core machine, which makes me curious about the almost 4x speedup of Firefox vs.. Chrome.

[ Note added about 15 minutes after original posting: Mate's System Monitor makes it appear that all three versions use just a single core. No real surprise--this is JavaScript, after all. ]


Tuesday, July 23, 2013

Scrollbars a page at a time, not a huge jump at a time

I've been really annoyed by Rhythmbox scrollbar behavior of late: when I click in the "trough" of the scrollbar, instead of moving the view by about a page up or down, it moves a distance corresponding to the point in the trough clicked. This is pretty bad for large text areas, such as a large music library. I complained to the Rhythmbox folks and Jonathan Matthew replied that this is default gtk behavior. This struck me as odd since I haven't noticed it in other applications, however Jonathan was right.

Google led me to a Gentoo site where ebichu was having the same issue, and posted the solution. I can't thank him there since I don't have a gentoo.org password, but he or she deserves thanks. The fix is to add a line to /etc/gtk-3.0/settings.ini:

[Settings] 
gtk-primary-button-warps-slider = false

So they apparently call this slider warping. Very user-hostile.

Sunday, July 21, 2013

Mindspring's 14 Deadly Sins

Worth keeping in mind and adapting for just about any business. From Wikipedia, http://en.wikipedia.org/wiki/MindSpring and credited to Mike McQuarry:

THE 14 DEADLY SINS OF MINDSPRING (or ways that we can be just like everybody else)
  1. Give lousy service--busy signals, disconnects, downtime, and ring no answers.
  2. Rely on outside vendors who let us down.
  3. Make internal procedures easy on us, even if it means negatively affecting or inconveniencing the customer.
  4. Joke about how dumb the customers are.
  5. Finger point at how other departments are not doing their jobs.
  6. Customers can't get immediate "live" help from sales or support.
  7. Poor coordination across departments.
  8. Show up at a demo, sales call, trade show, or meeting unprepared.
  9. Ignore the competition; they are far inferior to us.
  10. Miss deadlines that we commit to internally and externally.
  11. Make recruiting, hiring, and training a lower priority because we are too busy doing other tasks.
  12. Look for the next job assignment, instead of focusing on the current one.
  13. Office gossip, rumors, and politics.
  14. Rely on dissatisfied customers to be your service monitors.
I took the liberty of correcting the grammar in two places: 'jobs' in 5 was singular, and 9 contained a comma splice. Also, Wikipedia used a hyphen rather than a dash in 1; since it's unclear if this was Wikipedia's error or Mindspring's, I did not correct the Wikipedia page.

Thursday, July 18, 2013

Texas? New York?

Lewis Black nails it.


Sunday, June 23, 2013

Full-Disk Encryption, Linux Mint 15

Plaa's instructions for full-disk encryption at http://community.linuxmint.com/tutorial/view/1166 work fine for Linux Mint 15. This is for a new installation, or a new Mint partition. Do it.

For convenience, I have reproduced his instructions here:

(1) Boot your system using the Linux Mint 15 live CD or USB stick.
 
(2) Open a terminal and enter the following commands:

$ sudo apt-get remove ubiquity
$ sudo apt-get update
$ sudo apt-get install ubiquity
$ sudo ubiquity

Wednesday, June 12, 2013

We are Twitter's Twits, not their Customers

I've been disturbed by the invasive nature of many, many android apps. For example, here are the permissions requested by the Twitter app:


  • Why does Twitter need my location? They don't.
  • Why does Twitter need access to my accounts (note plural)? They don't. Why would I want to hand this over to them? That would be simply stupid.
  • Why would my contacts want me to hand their information over to Twitter? The naive ones may not to think to care, but most would likely prefer that I did not.
  • Why does Twitter need access to my Google service configuration? They don't. 
Clearly, we are not Twitter's customers, but rather Twitter's twits. Why use their app when you can simply log in to their service via browser?

Additionally, there are some ads that are simply blatant phishing attempts:


This is from the tunein app, which provides searches for radio stations and radio programs to stream. It's a nice service. It's ad-supported. The ad above, just above the highlighted Related tab, says I have one new message. So if I click that, where does it take me? Not to a message, or, rather, not to a message from anyone I could imagine listening to. It's a phishing ploy.

Tuesday, June 11, 2013

Monday, June 10, 2013

Classic CS1 Test Question Answer

Q:  What are the primary reasons for using procedures and functions?

A:  The primary reasons for using procedures and functions is for
instability.  A function is part of an expression and is used to
determine what the program must do.  A procedure is a statement in
itself and the great thing about it is that any variable declared
within a procedure can be referred to from anywhere in the program.

*************
The date on the file I re-stumbled across this in is December 1996, though it could be older. I suspect this is an answer I received on a test, but it may have been something going around the Internet at the time.

Monday, June 3, 2013

UMBC Frogs, Over a Stream Near a Pond, 2013-05-11 17:30

This plays well in Firefox, but on my Linux system neither Opera nor Chrome can deal with it.

However, you can access the media stream directly at https://userpages.umbc.edu/~jmartens/media/2013-05-11_17-28-05.wav.

Tuesday, May 28, 2013

Comcast and Verizon in Competition Again

I understand that Comcast and Verizon have opened restaurants across the street from one another, that their prices are identical, that each wait staff is apathetic, and, though each serves a full menu, every diner is forced to order everything. Also, prospective customers find menus in their junk mail and left at their homes daily.

Sunday, May 19, 2013

About that Rant

So at http://martesmartes.blogspot.com/2013/05/killall-plymouth.html I ranted. How about something positive: XFCE.  I blew away MATE, LXDE, etc., on my office 32b LUBUNTU 12.10 system and replaced it with XFCE. Now I'm running 64b Xubuntu 13.04 at home (at boot it still thinks it's Lubuntu): uninstall Mate, uninstall LXDE, install Xubuntu, and do an in-place upgrade to 13.04.

LXDE was pretty solid, not annoying little bug after annoying little bug like Mate or Cinnamon. However, it was very primitive, and customization took effort, effort takes time, and I don't have much time for this stuff (so why am I writing this?).

XFCE also seems pretty solid, and customization is pretty straightforward. Often there is not a menu choice to make the change I want to make, but a little time in RTFM mode and things become straightforward. I'm going to stick with this for awhile.

In a sense being a Windows user is easier: the environment is terrible, Microsoft and other Windows application vendors bleed customers by 1000 cuts, but people put up with it because they don't know any better. Are the user environments any better on the Linux side? Maybe, maybe not. There has long been a strong "make it like windows" ethic among Linux developers, and Ubuntu has decided to make your desktop UI no better than a tablet. But at least there are choices, and XFCE and LXDE are sufficiently different from Gnome 3 and even from Mate that the choices are significant.

killall plymouth

[ The below was written spring 2012, but somehow never got posted. It still captures my sentiments, so I thought I'd post it now. I've abandoned Mint for now and am using Xubuntu. ]

Yet again I find myself debugging Linux Mint 13. There's a tool, plymouth, that is supposed to provide splash screens on boot--who the heck cares about that? Well, I care, since well after boot plymouthd is still running, holding RAM, and eating CPU.

Googling reveals that others have had problems

<rant>
The whole Ubuntu OS family is annoyingly buggy, and yet people are wasting time with things like splash screens and other useless bells and whistles rather than just fixing the crappy software base
  • Last night I plugged in my Kindle, and Mate tells my I've plugged in a music player. WTF? I want it mounted as a thumb drive so I can use standard Unix tools.
  • Recently I've had to wrestle with cameras on Mint insisting on being opened with special, clumsy apps rather than just being mounted as thumb drives--which is effectively what they are. Even if I can get a file browser in there, it has crippled functionality. And what the hell is the path of the mount point? Nope, I either have to waste time figuring this useless crap out, use the crappy, logically useless, camera software, or just copy my pictures to a Windows machine, and then copy them to my real computer.
  • A friend used to have trouble with sound on Ubuntu. I just shrugged--computers have done sound for a couple decades. Now with my 64b Linux Mint 13 system, sound worked, then it stuttered continuously, and then it worked, and now it's completely dead. I don't have time to fritter away on this tripe.
</rant>

Amusement in Advertising from Google

Web access seemed sluggish this morning, so I hopped over to http://www.speedtest.net/ to look at the results. They were okay:


However, this was with Firefox, and the ad suggested results would be faster with Chrome. Really? I have Chrome, and use it often. Here are my Chrome results:


Faster? My throughput with Chrome was just a little slower but the ping times suggest a lower RTT with Chrome, which could possibly suggest a faster scripting implementation. However, this was from two different servers, one reportedly in Frederick and the other in DC, and just one shot each. Perhaps a more detailed study is warranted, but not now.