Sunday, 1 September 2013

Checking Process duration with C

Checking Process duration with C

I am checking process duration with C code. It works in Windows 32 bits
environment, but not in Linux 64bits.
At least my process takes longer than 3 minutes, but it shows 0.062 sec.
My code is below.
#include <stdio.h>
#include <time.h>
#include <Windows.h>
int main(void)
{
clock_t start = clock();
//....... doing something. Sorry:D
printf("%.3f sec\n", (double)(clock() - start) / CLOCKS_PER_SEC);
return 0;
}
How to fixed this code to work in 64bits Linux also? Thanks.

Is it safe to store an ios NSHTTPCookie in NSUserDefaults, or do I need to use the Keychain?

Is it safe to store an ios NSHTTPCookie in NSUserDefaults, or do I need to
use the Keychain?

People say to store a username/password in the Keychain which I have done.
Now, however, I need to store a cookie that is handed to me by a web
server because I want that cookie to be persisted forever. Do I use
NSUserDefaults or the Keychain?
Why is keychain more secure than NSUserDefaults in general, and is that
extra security needed for storing cookies?
Thanks!

Getting the permalink to the post in wordpress

Getting the permalink to the post in wordpress

I am trying to append the facebook like button to each of the post on my
blog. I have managed to get whatever I need to add the like button, the
only thing I need is, how can I access the current post's link inside the
function author_bio_display($content) i.e. at the place where it says
rawurlencode('post permalink goes here')?
function author_bio_display($content)
{
$bio_box = '<iframe
src="http://www.facebook.com/plugins/like.php?href='.
rawurlencode('post permalink goes here')
.'&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light"
scrolling="no" frameborder="0" allowTransparency="true"
id="facebook-like"></iframe>';
return $content . $bio_box;
}
add_action("the_content", "author_bio_display");

How to fetch contacts from AddressBook and store it in array in iOS 6?

How to fetch contacts from AddressBook and store it in array in iOS 6?

I am trying to fetch first name of contact in address book and then to
store it in an array.However i am not able to store the contact in array.
This is what i tried.
-(void)fetchAddressBook
{
ABAddressBookRef UsersAddressBook =
ABAddressBookCreateWithOptions(NULL, NULL);
//contains details for all the contacts
CFArrayRef ContactInfoArray =
ABAddressBookCopyArrayOfAllPeople(UsersAddressBook);
//get the total number of count of the users contact
CFIndex numberofPeople = CFArrayGetCount(ContactInfoArray);
//iterate through each record and add the value in the array
for (int i =0; i<numberofPeople; i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(ContactInfoArray, i);
ABMultiValueRef names = (__bridge ABMultiValueRef)((__bridge
NSString*)ABRecordCopyValue(ref, kABPersonFirstNameProperty));
NSLog(@"name from address book = %@",names); // works fine.
NSString *contactName = (__bridge NSString *)(names);
[self.reterivedNamesMutableArray addObject:contactName];
NSLog(@"array content = %@", [self.reterivedNamesMutableArray
lastObject]);//shows null
}
}

Saturday, 31 August 2013

Filtering MySQL query. "AND" operator

Filtering MySQL query. "AND" operator

I'm getting excessive rows selected from the db. However, when i try to
filter the data with AND lt_num it does not select anything at all. What
could be the problem?
$w = $_POST['pal_num'];
$w = "'".implode("','",$_POST['pal_num'])."'";
$r = mysql_query("SELECT * FROM pl_tab WHERE pal_num AND lt_num in
(".$weights.");");

Class, Interface, Prototype, and else

Class, Interface, Prototype, and else

I'm creating a JavaScript Framework for making applications in the classic
Object-Oriented Programming (so with classes/interfaces instead of only
prototypes). However I still have a problem with giving names to those.
For instance :
var Bidule = function() { /*...*/ } ;
Bidule.prototype = { /*...*/ } ;
Is Bidule a OOP Class as a class is a constructor ? Or is it only a
constructor ? As classes don't have prototypes, I don't think it could be
called a true class.
So it means I should call them both 'Constructors'. However, what about an
interface or an abstract class ? What is the correct word if they aren't
constructors ? And is an interface a kind of class ?
I've designed constructor functions, classes and interfaces in my
Framework. However I need a name to regroup all of theme so we may build
one of those like this :
var Bidule = new _NAME_.Class(/*...*/) ; // Where _NAME_ is the name of
the container of class/function/interface.
I was thinking of "Concept" but I'm not sure and would like to know your
opinions.



I also named "visibility" the common word for describing public/private
class, "type" for static/abstract/interface/singleton/final class. Are
those correct ?



And one last question : Is there a difference between the verb 'extend'
and 'inherit' ?
Thanks in advance for your answers.

Function not acting the same way when run twice

Function not acting the same way when run twice

I made a function that basically separates out some php variables on a
document then pieces them back together after altering one.
Runs fine if I call the function once but when I run it twice I cuts off
some of the last segment. It also isn't the same amount cut off each time.
I was wondering if there was any reason for this.
function editvar($filename, $old_var, $new_var)
{
$tmp = fopen($filename, "r");
$content=fread($tmp,filesize($filename));
fclose($tmp);
$ex = explode('<!---->', $content);
$expl = $ex[0];
$expl = explode('"', $ex[0]);
$expl[$old_var] = $new_var; // changed selected variable.
$ii = 0;
$ex[0] = "";
foreach($expl as $value) {
$ex[0] .= $expl[$ii];
if ($ii < count($expl) - 1)
{
$ex[0] .='"';
}
$ii++;
}
$ii = 0;
$new_content = "";
foreach($expl as $value)
{
$new_content .= $ex[$ii];
if ($ii < count($ex) - 1)
{
$new_content .= '<!---->';
}
$ii++;
}
$tmp = fopen($filename, "w");
fwrite($tmp, $new_content);
fclose($tmp);
}