Android 2.3 and the HTML5 Audio API

I ran into an issue with Android 2.3 and the HTML5 audio element. Evidently, you cannot reuse an instance of the Audio class. For example, if I define a sound, and play it:

var aud = new Audio();
aud.src = 'mysound.mp3';
aud.play();

And then on finish try to reuse the variable:

aud.src = 'mysecondsound.mp3';
aud.play();

The first sound plays a second time. For it to work, you have to destroy the first variable to reuse it.

This seems to be fixed in Android 4.2. I don’t have any intermediate versions in which to test.

What makes this bug annoying is that in Android 4.2, in order to play audio onFinish, you MUST reuse the variable. The same applies to iOS, by the way. So now we have to do user agent version checking in order to support both…

Sony Dash and general device lock-in

It is so tremendously frustrating when a company releases a device which is locked down and then discontinues it without allowing modifications.

I have a Sony Dash. It is a really slick piece of hardware with a capacitive touch screen and accelerometer. It is also based off of the Chumby OS. I was hoping that I could add the ability to pull media from a server I have downstairs… But nooo.

I’m beginning to think that a law which makes hardware lockdown illegal would be in alignment with the goals of copyright and patents. Namely, “To promote the Progress of Science and useful Arts, by securing for limited Times to Authors and Inventors the exclusive Right to their respective Writings and Discoveries;” . Emphasis on promoting the progress of science.

There are some downsides, such as the cases where a company sells the hardware at a loss in order to recoup with the sales of content. However, I wonder whether the benefit to the economy through the ability of anyone to use hardware in unusual ways would outweigh the loss of that particular business model.

As I understand it, the goal of patents and copyright is to protect innovators and encourage them to create new things which benefit society as a whole. Not to establish ownership of an idea as an element of property rights. As such, when hardware is locked down with the pure goal of keeping competitors out, it is detrimental to our economy as a whole. This is underscored when the company in question is not harmed monetarily when the hardware is used for other purposes.

I’d be curious to know whether there is any case law or statute which establishes the right of an individual to use something which he/she has purchased in whatever way he/she wants, as long as the use does not violate other statutes. I wonder whether such a precedent/statute could be extended to encompass the actions of a company to infringe on the previously stated ‘right’.

I’m not saying that a company must go out of its way to make it possible to modify a device. That would be a positive ‘right’ and damaging. Rather, it would be illegal to put in place protections whose entire goal is to keep modification from happening. For example, on the Sony Dash, there is a check which makes it impossible to load a modified firmware without having it signed by Sony’s private key.

There are cases where such system level protection could be justified, for example with secure systems where software modification would be considered a breach. However, in all such cases, it should be possible for the owner to modify the software. If the owner wanted to lock down the system, it would be permissible.

One wrinkle might be single use systems where the ability to modify might put others in danger. For example, if the computers in a vehicle were modifiable, it could potentially allow someone malicious to endanger the operator of the vehicle. However, this is impacted by the fact that there are other parts of the vehicle which could also be modified to cause damage, so the potential is not really changed by the presence of another attack vector. Especially if the system requires physical access to modify.

Another element might be the case of an owner modifying his/her vehicle’s computers and causing danger to others on the road. Similarly to the above case, a poorly installed tire or other vehicular modification would cause the same effect.

However, in the above cases there are fascinating opportunities for smart people to modify their vehicles and do things which could found new industries. What would the positive economic impact be if every individual could come up with an idea, purchase the hardware and then modify it to make that a reality. Entirely new industries would appear. Devices which would have been individual failures might become successes. The Sony Dash was a failure. If there were an easy way to put a distribution of Android on it, would that have been different?

Android 2.x and inline-table

I hit an issue today with an older Android phone and thought I would document it here.

It appears that Android 2.x (in my case, 2.3) has an issue where if inline-table is used, and then javascript manipulates the dom, strange layout things happen.

HiDPI (Retina) Display jQuery Plugin

Just throwing this out there. A very simple plugin for jQuery to handle images when javascript is already required and/or indexing isn’t important.

It simply allows you to define two images via the data-* attributes and select them based on whether the browser/system is in a HiDPI mode.

Normal HiDPI caveats apply:

  • This requires javascript. It is impossible to stop the browser from downloading the contents of the src attribute in an image tag in client-side code. Which means that the src attribute is left blank and if javascript is not enabled, no images will be displayed.
  • This isn’t indexed. Related to above, the src attribute isn’t used and there is no standard for applying alternate images which is indexable.

The one big advantage is that this avoids the double download issue where a HiDPI browser would download the contents of the src attribute and then a larger image after that.

Hopefully a proper fix such as the picture element will be implemented in major browsers and polyfills created so that we can use it before too long. In the mean time…

I present: jquery.hidpi

G. A. Henty

I responded to a question about G. A. Henty’s books in general via email, and thought it worth including here:

I highly recommend just about all of the Henty books. Consistent themes throughout are honor, character, determination, self-discipline, and respect for women.

For a curriculum, I especially recommend Henty for tracing the history of England. If a reader were to read his books on English history chronologically, they would have a very good grasp of the entire flow of English history.

Henty does have some weirder areas which on occasion pop up. He has a low view of black people, not as less human, but as a culture having less character and determination. This appears on occasion in his books on India as well as his book on the American Civil War. Be aware that these views are not unusual for men of his era, and he might be seen by some as being more “modern” in this way. But it isn’t something to sugarcoat.

He is somewhat universalist, as in he believes that Allah and God are the same and as such, Muslims can go to heaven. This pops up in his books on the crusades, especially the Knight of the White Cross (one of my favorites other than that).

One of his rarer views is the appearance of the idea of “second sight”, namely that people can have a mental connection across space. He simply believes that it exists and is consistent with God’s order, but we haven’t explained it yet. This appears in The Tiger of Mysore and Rujub the Juggler most prominently.

I personally think that his views aren’t dangerous, and any well educated young man can discern these issues, especially if forewarned. For younger readers, I would recommend that the parents read the books aloud to the children to censor or discuss these topics.

Some of his books accurately depict the violence of some eras. By Pike And Dyke and In The Reign Of Terror are examples of this. I personally think it important that our youth understand the natural depravity of mankind so that we may better understand the universal need for salvation, however some are more sensitive to such things than others. Again, parental discernment is always important.

With the above said, I personally love just about everything G.A. Henty has written, especially these:

  • A Knight of the White Cross
  • Facing Death
  • Winning His Spurs (or A Boy Knight)
  • Friends Though Divided
  • In Freedom’s Cause
  • St. George for England
  • True to the Old Flag (fascinating as it is about the American Revolution from the British perspective)
  • The Dragon and the Raven
  • The Lion of the North
  • The Bravest of the Brave
  • The Young Carthaginian (it is almost impossible to read this without making comparisons to the American political situation today. Absolutely phenomenal opportunity to discuss the “cycle of nations”.)
  • With Wolfe in Canada (especially for the theme of undeserved grace)
  • For the Temple
  • In the Reign of Terror
  • The Cat of Bubastes (look out for the universalism here)
  • The Lion of St. Mark
  • By Pike and Dyke
  • By England’s Aid (part 2 to By Pike and Dyke)
  • With Lee in Virginia
  • By Right of Conquest
  • Beric the Briton
  • Rujub the Juggler (possibly Henty’s best storytelling, however it needs an older, discerning reader)
  • In the Heart of the Rockies
  • Wulf the Saxon
  • At Agincourt
  • A March on London

As long as this list is, I have actually eliminated books which I would like to include for sake of length. I would start with the above and then have at everything else in his corpus.

In my opinion, the best way to read Henty is electronically. All of his books are in the public domain, and the vast majority are available through Project Gutenberg. With the cost of a Kindle being what it is, it is probably the least expensive option. I personally read a ton of them on my iPod Touch and iPad.

iTunes API Valid Image Sizes

I needed to find out for work what images sizes were provided by iTunes. The API only provides links to 30×30, 60×60, and 100×100 pixel images. However, you can run a string replace to get larger sizes by replacing the string 100x100 with one of the below sizes. For example:

http://a3.mzstatic.com/us/r1000/019/Music/a6/79/4c/mzi.qqbuvikd.100x100-75.jpg

Eric Whitacre's Water Night

becomes:

http://a3.mzstatic.com/us/r1000/019/Music/a6/79/4c/mzi.qqbuvikd.1200x1200-75.jpg

Eric Whitacre's Water Night

To see whether this could be considered reliable, I ran a series of tests to check what sizes were available across a range of albums. I checked in increments of 25, up to 2000.

It looks like the following sizes can be used:

100
150
200
225
400
450
600
1200

If you want the code to try this on your own:

 

SQL Queries for Cleaning Up Exploits

I am finally getting to bed after spending several hours cleaning up a database infection (not my code). Basically, every string field had a script tag injected into it at the beginning, and some at the end. Here are the SQL queries I ended up writing to fix this:

For the beginning of the field. It basically just grabs a preset string at the beginning of the field and wipes it. Nothing particularly difficult, I just didn’t know how to do it off of the top of my head.
UPDATE [TableName]
SET [ColumnName] = REPLACE(CAST([ColumnName] AS VARCHAR(1000)),'ExploitCode','')
WHERE [ColumnName] LIKE '%ExploitCode%'

A more complicated script for the end of the field. It assumes that the exploit code at the end starts with a < and that there are no other UPDATE [TableName] SET [ColumnName] = LEFT([ColumnName], CHARINDEX('

Hopefully this will be of help to someone else down the road who has to deal with this. Another issue the client will have to deal with are length restrictions on the field causing them to lose data, but I don’t think UPDATE [TableName] SET [ColumnName] = CLAIRVOYANCE([ColumnName], DateThatItWasCorrectWithoutBackups) works. Might I suggest it as a feature for MS SQL 2014?

Random Musings Regarding Individuality and Worship

I thought this worth recording, which generally means it isn’t worth your reading. Some have expressed curiosity at to what goes through my head. Here is a brain dump from this morning’s drive…

Individuality isn’t nearly as good as I usually hear it portrayed. The individual is alone. Very alone. And yet we spend half our lives trying to develop/express our individuality. And the other half trying to find meaning in groups. Ironic? Being an individual is not very meaningful.

Look at youth. We all go through a period of time where we go from blissfully being defined by our family and parents, to trying to become individuals. And yet, what do teens spend most of their time pursuing? Groups — be it Facebook, texting, ‘hanging out’, youth group, et cetera… Perhaps we are going about this incorrectly.

What if we are not meant to be defined by our individuality. Or rather, what if our individuality takes on meaning in the form or presence of the member of something larger — a group? God created man as an individual. And yet, He points out quickly that the man needs a helper/companion, hence woman. We are defined by our connections. In a Godly sense, we are defined first and foremost by our connection to Him. He also defines/places us in relationships with each other, be it marriage, family, et cetera.

A corollary to this is the insidious nature of where a worldly pursuit of individuality invades the sacred. As marriages become more individual, spouses become less important and divorce becomes more prevalent. As Christians become more individual, we disconnect ourselves from the church catholic/universal with a misguided (to put it lightly) view of ‘me and my bible’. As Christians disconnect themselves from each other, we disconnect ourselves from Christ. He set up/defined the church by our corporate worship. Yes, we are saved as individuals, but aren’t we fed as a group? Isn’t there a reason that the sacrament of the altar is called ‘communion’? We are referred as the ‘body of Christ’. Isn’t this in essence defining our being by our affiliation with Him?

Our true selves, our alive selves, our spiritual selves, the new Adam, is defined by our connection to Christ and His church. We are defined by a group. Our individuality adds color to this, but is indeed secondary. Let’s stop encouraging individuality. Let’s encourage our teens to define themselves by their affiliation to Christ and the church catholic, rather than by their friends or age group (company of fools?). Let’s encourage couples to define themselves in their spouses (secondary to their definition in Christ). Let’s allow meaning to come from the external rather than the internal, since that is how we were made in the first place.

Following is a related musing which uses the previous discussion as a starting point but then begins a tangent. This is a brain dump, after all. And yes, I understand the irony of using a word whose root is the ancient Grecian pagan concept of the Muses.

This has another corollary in corporate worship. The pursuit of ‘contemporary’ worship is defined by individualism in several ways. One is that we are catering to the individual desires of the worshiper (singular), rather than the needs of the worshipers (plural). What is needed by Christians as a group as well as individuals? To be fed through the Word and sacraments (both of them). But as individuals, we desire an emotional high. As such our first and foremost goal in worship is that the Word be preached and the sacraments be administered. It makes ‘prayer and praise’ services look insubstantial/inconsequential.

Secondly, by pursuing ‘culturally sensitive’ worship, where we target musical choices specifically to the preferences of the culture (remind me again where the culture became the model for anything sacred), we abandon the catholic/universal nature of worship. We seem to be enthralled/consumed with a misguided attempt to make worship ‘welcoming’. Firstly, what is more welcoming than a familiar worship service, something that is denied the visiting worshiper when every church reinvents the wheel? Secondly, God’s worship, as defined earlier by the Word being preached and the sacraments being administered, is simultaneously natively welcoming in a way that we cannot add to and a massive turnoff in a way only God can overcome. We get sidetracked when we try to target worship towards the culture and end up abandoning worship or worse, being subsumed into the culture itself.

Sidenote: remind me again how we are so arrogant as to believe that we can do a better job in a week than the writers of the hymnal did in years, not to mention the church fathers who developed the basic form of worship over millennia. I’m not saying we have to do the same exact thing every sunday, but less variation and more time to memorize the service form and text (which teaches by the way, have you looked at the doctrinal content therein) is a good thing.

Lastly, I thought that there was once a time where the church defined art, music, and such. Not became a caricature of the profane. If you think that our musical and artistic tastes need to be in line with secular culture, please look up Palestrina, his method of polyphonic composition, and the history of sacred music. For many years (until the so called enlightenment) the church defined its own culture. We still have the ability, and indeed we do so. Look at the music of John Levitt, the latest work in the WELS hymnal supplement, the LCMS Lutheran Service Book, Liturgy Solutions, et cetera. Why is it that we then choose for our services some of the more meaningless fluff to darken the sanctuary? Especially when we can use text like this (great tune too):

This is the three-fold truth on which our faith depends;
and with this joyful cry worship begins and ends:
Christ has died! Christ is risen!
Christ will come again!

 

Made sacred by long use, new-minted for our time,
our liturgies sum up the hope we have in him:
Christ has died! Christ is risen!
Christ will come again!

 

On this we fix our minds as, kneeling side by side,
we take the bread and wine from him, the crucified:
Christ has died! Christ is risen!
Christ will come again!

 

By this we are upheld when doubt or grief assails
our Christian fortitude, and only grace avails:
Christ has died! Christ is risen!
Christ will come again!

 

This is the three-fold truth which, if we hold it fast,
changes the world and us and brings us home at last:
Christ has died! Christ is risen!
Christ will come again!