Saturday, 31 August 2013

Python if elif not working in my script

Python if elif not working in my script

dummy = 10
x=input("""You use your attack by chossing a attack,for now you have 3
attacks.
Chosse one:
1)punch 3dmg
2)use knife 4dmg
3)use pistol 6dmg
""")
if x == 1:
dummy == 10-3
print"Dummies life:"+str(dummy)
elif x == 2:
dummy == 10-4
print"Dummies life:"+str(dummy)
elif x == 1:
dummy == 10-6
print"Dummies life:"+str(dummy)
if x == 1:
dummy == 10-3
print"Dummies life:"+str(dummy)
elif x == 2:
dummy == 10-4
print"Dummies life:"+str(dummy)
elif x == 1:
dummy == 10-6
print"Dummies life:"+str(dummy)
if x <= 0:
os.system("cls")
elif x >= 0:
x=raw_input("""Attack:
1)punch 3dmg
2)use knife 4dmg
3)use pistol 6dmg
""")
if x == 1:
dummy==dummy-3
elif x==2:
dummy==dummy-4
elif x==2:
dummy=dummy-6
print dummy
It prints dummy is 10 again and the 0 or less isnt working too

Whats the point of i++ when ++i "can" be faster in c++?

Whats the point of i++ when ++i "can" be faster in c++?

I've been reading quite a few posts/questions about the micro-optimization
of ++i and i++ in C++. And from what I've learnt is that ++i "can", not
always, but can be faster than i++.
So this makes me ask this question, whats the point of i++ then? I thought
that ++i is that you increment the value first then return it. Where as
i++ you return the value then increment it. But I have made a very simple
test on this:
for(int i = 0; i < 10; ++i)
{
std::cout << i << std::endl;
}
is the same as:
for(int i = 0; i < 10; i++)
{
std::cout << i << std::endl;
}
Both prints out the same results. So my real question is that is there a
situation where you MUST use i++ rather than ++i? If there is, please
explain. Thanks

CSS3 image rotating spinner in JS for non CSS3 browsers?

CSS3 image rotating spinner in JS for non CSS3 browsers?

I have a rotating image spinner that looks fantastic...in browsers that
support it. it can be seen at kingpetroleum.co.uk/background.php - it's in
the top corner.
I need to somehow create the same effect for users that are using browsers
that can't display it.
I'm not great with javascript so would be hoping on finding a good
tutorial / guide etc but after a bit of googling I've not come up with
anything.
Any help is appreciated.

Friday, 30 August 2013

Client side custom validation with radiobuttons

Client side custom validation with radiobuttons

Can I have an example code for this? Two radio buttons in a group name
"Gender". If the user selects nothing, a message should appear saying
"select one". I've done some custom validations with textboxes and
dropdownlists and I became stuck with radiobuttons.

Thursday, 29 August 2013

Is Object memory freed when we explicitly call finalize() on it?

Is Object memory freed when we explicitly call finalize() on it?

As far as my understanding goes finalize() and GC are two different
aspects. GC uses finalize() method to free Object memory. We cannot state
when GC will occur(even if we explicitly call System.gc()). But we can
explicitly call finalize() on an Object.
Will the function be executed immediately(memory freed) or it waits till GC
occurs like System.gc() call?
Also as per the docs the finalize method is never invoked more than once
by a Java virtual machine for any given object.
So what happens when we call finalize() first and GC happens at a later
point of time.
If object memory is not freed on explicit call to object.finalize() then
would't
it being called again in the GC process violate the calling only once rule?

jquery ajax cpu high usage

jquery ajax cpu high usage

I am using this ajax.php to get livenews auto update. but sometimes it
causes high cup usage, sometimes (120%) it is running on a apache. can you
please inform me with this issue: the code is:
<?php
$data = file_get_contents('http://elmarada.org');
preg_match("/<ul[^>]*id=\"toautoupdate\"[^>]*>(.*?)<\\/ul>/si", $data,
$match);
echo $match[1];
?>

Wednesday, 28 August 2013

testdisk - partition : write error

testdisk - partition : write error

Today I bought a SATA-to-usb convertor to copy my data from old hard drive
that had been abandoned for few months. When I connected to PC, the
partition didn't show up so I decided to fix the partitions. I was trying
to recover the damaged parition from my WD hard disk drive using testdisk.
I can see my 3 paritions when I 'Analyse' but when I Write those paritions
it returns error:
Parition: Write Error.
I tried both Linux and Windows, both show same error. Now how do I sort
this out , if not then is there another way to fix my partition tables?
interface_write()
1 * HPFS - NTFS 0 4 5 7230 82 20 116154880 [STR1]
2 P HPFS - NTFS 7230 90 29 15120 113 33 126754304 [Local Disk]
3 P Linux 15120 113 34 15200 30 62 1280000
[_Fedora-16-i686-]
write!
write_mbr_i386: starting...
write_all_log_i386: starting...
No extended partition
Partition: Write error