Unicode test strings

Some strings you can shove into your application and see if you at least sort of handle Unicode correctly. For example, if you have a form which stores a text value in a database and then shows it later on a webpage, you can try to stick these in the form and see if they come out correctly in the other end.

  • Iñtërnâtiônàližætiøn
  • Ādam

First one includes many non-ascii characters. Second one starts with a multi-byte character.

Convert windows-1252 to utf-8 on Windows

Tried to find out how to convert windows-1252 code files to utf-8 without messing up Norwegian characters today. Couldn’t really find anything good other than linux tools and php stuff. Finally, *facepalm*, I remembered it might be possible using Notepad… And sure enough, seems to work great. Just open up the windows-1252 encoded file in Notepad, then choose ‘Save as’ and set encoding to UTF-8.

Hopefully I won’t forget this the next time I need it… *sigh*

PHP: One way of differing between DEV and PROD environments with Kohana

Usually when I develop websites, they will be deployed to a domain, for example www.geekality.net. But when I develop this site locally, I usually want it to be in some sub-folder of localhost, since I usually have more than one website going on, and I don’t want the trouble with virtual-hosts. So, to solve this for my Kohana websites I do the following simple thing. This technique would work for other websites programmed in PHP as well, but the PHP part would probably be a bit different.

Continue reading

Oracle: Finding all constraints and their affected columns

Found an SQL script to list all constraints in an Oracle database together with affected columns. Putting it here in case I need it again… Took a while to run, but sure beats having to look through all the table definitions to find what exactly is preventing me from deleting a row…

SELECT UC.CONSTRAINT_NAME
,      UCC1.TABLE_NAME||'.'||UCC1.COLUMN_NAME "CONSTRAINT_SOURCE"
,      'REFERENCES'
,      UCC2.TABLE_NAME||'.'||UCC2.COLUMN_NAME "REFERENCES_COLUMN"
FROM USER_CONSTRAINTS uc
,    USER_CONS_COLUMNS ucc1
,    USER_CONS_COLUMNS ucc2
WHERE UC.CONSTRAINT_NAME = UCC1.CONSTRAINT_NAME
  AND UC.R_CONSTRAINT_NAME = UCC2.CONSTRAINT_NAME
  AND UCC1.POSITION = UCC2.POSITION -- Correction for multiple column primary keys.
  AND UC.CONSTRAINT_TYPE = 'R'
ORDER BY UCC1.TABLE_NAME
,        UC.CONSTRAINT_NAME;

How to change or remove file extensions in Windows

Say you have a bunch of files and you want to quickly change or remove the file extension of all of them. Turns out that’s very simple to do with the command-line in Windows. I had no idea…

Change

ren *.old *.new

Will change all files with ‘old’ file extension to have the ‘new’ file extension.

Remove

ren *.old *.

Will remove the ‘old’ file extension.

Simple!

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?)