Measure upload time and speed with PHP and Javascript

Stumbled upon a question on StackOverflow the other day which got me curious. The question was about how to measure how long it takes to upload a file to a PHP script. This is what had been tried out:

$upload_time = time() - $_SERVER['REQUEST_TIME'];

This pretty much always returns zero, even though the uploading actually took many seconds, because the request start time is after the server has received the post data. That we actually just get how long the script took to run, which of course is pretty close to zero seconds. So, what can we do?

  1. Right before data is posted, nudge the server with an AJAX call which stores the current timestamp in a session variable
  2. Post the data
  3. Compare current timestamp with the one stored in step 1

Wasn’t sure how it would work, but seems to work pretty well. There will of course be a very tiny difference since the AJAX request will be a bit part of the time, but compared to the upload time it shouldn’t matter much. Anyways, here’s how you could do it :)

Continue reading

Better piano sound in MuseScore

I’m singing in a choir, believe it or not, and I’ve started to type in some of our sheet music into MuseScore. That way I play back just my voice, as well as mixed with the others to make sure I’m able to not become confused when the other people sing other voices next to me.

Either way, the default sounds, at least the piano sound I’m using, are pretty blah. But getting better sound is super simple, if you just have happened to read the manual like I have :P

  1. Download the biggest SoundFont file from the MuseScore SoundFont manual page in their manual.
  2. Extract it using for example 7-zip (you’ll have to extract twice, first the gz and then the tar)
  3. Open up MuseScore and go to Display, Synthesizer (see picture to the right)
  4. In the SoundFont field at the bottom put in the path to your extracted SoundFont file (or click on the blue folder thingy to select it that way)

And that’s all. The piano sound should now sound a lot better, and I’m sure other sounds do so as well.

(Can’t stand the Ahh Choir sounds though… yuck… that’s why I’m using the piano… anyone know of a good SoundFont for voices?)

PHP: Simple compression of JSON data

Just discovered how super simple it was to add some gz compression when for example providing JSON data from PHP.

Continue reading

Less useless iOS WiFi sync

Update: As whoever left the comment on this post said, there might be solutions to this now. I probably was checking this out a bit too soon for people to have blogged about issues and such. When checking it out again now it seems there are a lot of people who have had issues with this, and I found a solution which Worked For Me™.

  1. Installed CCleaner
  2. Uninstalled iTunes and all other Apple software (bonjour, software update, etc) I could find through CCleaner (except QuickTime)
  3. Did a registry cleanup using CCleaner
  4. Rebooted my computer
  5. Reinstalled iTunes

When I launched iTunes again then, it worked pretty much right away. Still annoys me that I have to have iTunes running for it to work, but at least it does work. I would also prefer it if this was a feature that could work more like DropBox, in that it would work no matter where I was with my iPhone. Should’ve been a config to enable sync over “foreign” wifi and over 3G as well.

Still don’t really like Apple nor iTunes… :p

Anyone else been looking forward to the WiFi sync coming with iOS 5? I did. Someone gotten it working and found it useful? I haven’t.

Not sure why it doesn’t work, but might be because my computer is connected to the network through cable rather than wifi. Seriously Apple? They are on the same network! It should work! Stupid, stupid stuff…

In addition to that it seems the iPhone have to be connected to power… Seriously Apple? What’s the point of wireless sync if I have to be connected to a cable for it to work?! Makes no sense!

Hopefully I’ve missed something, but until someone points it out: Thanks for nothing, Apple…

Quick installation of LAMP for Kohana on Ubuntu

Needed to get a LAMP environment up and running for some Kohana development. Starting with a more or less fresh install of Ubuntu, here’s what I did.

Continue reading

Er det lov til å gå på rødt lys i Norge?

Under mitt lille eksperiment, om en kan kalle det det, så begynte jeg å lure på hva som egentlig var reglene for fotgjengere i Norge. Så, jeg sendte like godt en epost til Statens Vegvesen og spurte. Her er svaret :)

Norwegian post about Norwegian traffic light rules. Google Translate if you’re too curious :)

Continue reading

Playing with Integrity

I would say that integrity is a vert important quality to have both in your professional life and in your personal life. What is integrity?

Integrity is a concept of consistency of actions, values, methods, measures, principles, expectations, and outcomes. In ethics, integrity is regarded as the honesty and truthfulness or accuracy of one’s actions. Integrity can be regarded as the opposite of hypocrisy, in that it regards internal consistency as a virtue, and suggests that parties holding apparently conflicting values should account for the discrepancy or alter their beliefs.

Source: Wikipedia

My own simplified definition could be something along the lines of

Doing what is right, not just when it’s convenient, but consistently and always, simply because it’s the right thing to do, and you know it. If in doubt, figure it out, and adjust accordingly.

Anyways, do you have it?

Continue reading