18th October 2007
To start: as of the latest MySQL, syntax presented in the title is not possible. But there are several very easy ways to accomplish what is expected using existing functionality.
There are 3 possible solutions: using INSERT IGNORE, REPLACE, or INSERT … ON DUPLICATE KEY UPDATE.
Imagine we have a table:
CREATE TABLE `transcripts` (
`ensembl_transcript_id` varchar(20) NOT NULL,
`transcript_chrom_start` int(10) unsigned NOT NULL,
`transcript_chrom_end` int(10) unsigned NOT NULL,
PRIMARY KEY (`ensembl_transcript_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Now imagine that we have an automatic pipeline importing transcripts meta-data from Ensembl, and that due to various reasons the pipeline might be broken at any step of execution. Thus, we need to ensure two things: 1) repeated executions of the pipeline will not destroy our database, and 2) repeated executions will not die due to ‘duplicate primary key’ errors.
Method 1: using REPLACE
Read the rest of this entry »
Posted in Programming | 46 Comments »
16th October 2007
Today, setting up a relatively serious (in CPU resources needed) web-system, I ran into a weird problem of python scripts ending prematurely. After some investigation, it looked like any process which uses up more than 20 seconds of CPU time, is automatically killed. To verify this, I wrote an infinite loop in C,
int main () {
unsigned int i;
for (i = 0; i < 2 ; i++ ) {
i = 0;
}
return 0;
}
[/c]
compiled it and executed several times on the GoDaddy shared hosting server. I did observe the program running for the maximum of 20 seconds of CPU time, not a second more. Please note, that 20 seconds of CPU time can be much more of “real” time, if the script isn’t using 100% of CPU, which often the case for shared hosting. Thus if you have in your php.ini max_execution_time set to, say, 60 seconds, your php script may actually execute as long as one minute; but I’m pretty sure that if your script has lots of CPU-intensive procedures, then as soon as it uses 20 seconds of CPU time, it will be terminated (however, this statement still needs checking – anyone?).
To verify, I also created a cron job with the same file. It ran for 30 seconds CPU time.
Strangely, this behaviour is not documented anywhere.
This limit may also explain a number of other problems, if you have heavy web-applications: they just might be killed before they are finished, causing errors.
I do understand the reason for this limitation, and am sure similar limitations exist in other shared hosting environments. The only important thing here is that this limit should have been documented and even put upfront somewhere in the hosting plans descriptions.
I also wonder if the limit is the same for all godaddy shared hosting plans, or if it differs. 20 seconds when executed from PHP, and 30 seconds when executed as a cron job were observed on the Deluxe Linux Hosting plan.
Extensions, additions and comments are welcome.
Posted in *nix, Misc, Programming, Web | 22 Comments »
16th October 2007
My expectations were half-satisfied: Socialists didn’t make it into the parliament! Great lesson for them, and a new example of political death in Ukraine. (Though I do think that Socialists have resources to return in 5 years, when new elections are due.)
On the other hand, Lytvyn’s block did jump the 3% barrier. By the way, if we take the absolute number of votes Lytvyn had in 2006 elections (619 905 votes), and the number he had at the 2007 snap elections (924 538), the difference is only 304633 votes. When multiplied by 20$, it gives 6 million USD – which isn’t too high a price for getting into the parliament, isn’t it?
Overall, I’m satisfied with these elections. Politicians this time were wise enough to avoid prolonged court trials over the miserable, non-differentiating numbers of votes in distinct voting districts. It saved both time and money. It’s also good to hear that immediately after the official results announcement, the Our Ukraine – Self Defence block and the Block of Yulia Tymoshenko agreed upon the coalition treaty. It’s not yet evident if the treaty will hold, or if it won’t be beaten by the PR – Lytvyn – Communists probable political block – but that is still a good sign of political agility, unseen since the end of 2004 between the two political forces.
I’m also glad that society intelligently handled these elections, which were unfavoured by many. Everything went overall smooth and with no troubles.
The only thing, which is not directly elections-related, is the fighting over the status and interpretation of the OUN-URA (Organisation of Ukrainian Nationalists – Ukrainian Rebel Army) during the World War II. But I hope that in part with the help and actions by the President, this issue will be settled and finally resolved as soon as possible (I expect this to happen within 10 years from now).
Posted in Society | No Comments »
1st October 2007
Today my blog’s domain bogdan.org.ua isn’t resolving to IP address from several worldwide locations. The trouble seems to be with XName, as running nslookup using ns?.xname.org gives me this:
DNS server handling your query: ns1.xname.org
DNS server’s address: 87.98.164.164#53
** server can’t find bogdan.org.ua: SERVFAIL
It’s rather strange that all the other domains I have on XName are functioning properly.
I can’t figure out the reason behind the problem; will keep trying to resolve as soon as possible.
Update: this is in fact XName-related problem: they are again under DDoS attack.
The other domains I have at XName might have stayed unaffected thanks to the secondary nameservers; it might have been just the question of the difference in sync times, that caused bogdan.org.ua to expire earlier than other domains.
It’s a great pity that DDoS attack organizers cannot (yet) be reliably tracked and then punished. Attacking a free web service cannot be explained other than by mental sickness or noticeable loss of profit by some entities…
Posted in Notepad | 1 Comment »
30th September 2007
Today was the voting day in the snap parliament elections-2007 in Ukraine.
Early in the morning, I heard from my wife’s sister that some of her friends were offered 100 UAH (20 USD) for promising to vote for the Lytvyn’s political block (based on his People’s party – “Narodna partiya“, in Ukrainian only). I said “that’s ugly, and they could just take the money and vote for whomever they want, as it’s impossible to enforce them to vote exactly for Lytvyn”. But that was it as for my reaction in the morning.
Read the rest of this entry »
Posted in Society | 1 Comment »
26th September 2007
These are all excerpts from the Python documentation.
To synchronously and simultaneously loop over two sequences:
questions = ['name', 'quest', 'favourite colour']
answers = ['Lancelot', 'the holy grail', 'blue']
for q, a in zip(questions, answers):
print 'What is your %s? It is %s.' % (q, a)
To loop over a sequence with both key and value:
Read the rest of this entry »
Posted in Programming, Python | No Comments »
26th September 2007
Sample script (copypasted from Well House Consultants training course):
click the PLAIN TEXT header for copy-pasteable version
#!/usr/local/bin/python
author = {"php":"Rasmus Lerdorf",\
"perl":"Larry Wall",\
"tcl":"John Ousterhout",\
"awk":"Brian Kernighan",\
"java":"James Gosling",\
"parrot":"Simon Cozens",\
"python":"Guido van Rossum"}
langs = author.keys()
langs.sort()
for language in langs:
print language,"is the child of",author[language]
You can also define the Python ksort() function similar to that found in PHP:
Read the rest of this entry »
Posted in Programming, Python | 1 Comment »