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.
Category Archives: Software Development
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…
, 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;
If you’re just looking for one particular constraint you can of course also add and UC.CONSTRAINT_NAME = 'SOME NAME'
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:
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?
- Right before data is posted, nudge the server with an AJAX call which stores the current timestamp in a session variable
- Post the data
- 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
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.
Quick installation of LAMP for Kohana on Ubuntu
MySQL tables for continent names, country names and their ISO-3166 codes
Here is a MySQL table containing continent names, country names and their ISO-3166 codes.
Needed one a while ago, but the ones I found were either kind of lacking or kind of old. So I made one myself by converting a datafile on Wikipedia into the format I wanted. Used some regular expressions and manual corrections. Later I also went through newsletters with Updates on ISO 3166. Hopefully I got it all right, and hopefully it can save you and others some time as well.
If you find any mistakes or updates I’ve missed, please let me know
PHP: What’s a valid JavaScript identifier (or function name)?
After another reply to a question I’ve had on StackOverflow for a while, I decided that I perhaps should add another level of security to my method of providing JSONP from PHP. The way I did it before, I didn’t do any checking on the provided callback. This means that someone could technically put whatever they wanted in there, including malicious code. So, therefore it might be a good idea to check if the callback, which should be a function name, actually is a valid function name. But,