Wednesday, March 30, 2011

Webware taskkit keep process executing without loading system

Here is my taskkitsample.py:

from TaskKit.Scheduler import Scheduler
from TaskKit.Task import Task
from time import time, strftime, localtime, sleep
     
class SimpleTask(Task):
    def run(self):
      print "hola "
      print self.name(), strftime("%H:%M:%S", localtime(time()))

def main():
    scheduler = Scheduler()
    scheduler.start()
    scheduler.addPeriodicAction(time(), 1 , SimpleTask(), 'Test')

main()




If I run from command line:

python taskkitsample.py

The process stops inmmediately: 



one common way to keep the process running is by adding the while True loop:

def main():
    scheduler = Scheduler()
    scheduler.start()
    scheduler.addPeriodicAction(time(), 1 , SimpleTask(), 'Test')

    while True:
        pass



Yeah, It works:



But If you take a look to the Task Administrator, there is a big problem: the CPU % use!!!:

The solution is quite simple, do not insert the while True: sentence in your code and run the python file using -i:


Works Much Better :D

Reference: http://stackoverflow.com/questions/1000900/how-to-keep-a-python-script-output-window-open

Tuesday, March 29, 2011

Dell Laptops: home vs business

Some time ago I had a question. What are the diferences between home and business dell laptops.


Here is a link to an article that explains that:
http://www.ehow.com/about_6122110_dell-consumer-vs_-business-laptops.html


Saturday, March 26, 2011

objectve c split string by end on line \n

NSString* answer;
......
...... (answer var is set and has a \n )
......

NSArray *firstSplit = [answer  componentsSeparatedByString:@"\r\n"];

Friday, March 25, 2011

printing addressBook multivalue identifier

ABMultiValueIdentifier identifier;

....
....
....


NSLog(@"identifier");
NSLog(@"%i" , identifier);

source: http://www.roseindia.net/tutorial/iphone/examples/nslog/nslogintegerexample.html

Assertion failed: (((ABCMultiValue *)multiValue)->flags.isMutable), function ABMultiValueAddValueAndLabel

I Had this code

ABMultiValueRef multiPhone = ABRecordCopyValue(person, kABPersonPhoneProperty);
// here y was getting the error: Assertion failed: (((ABCMultiValue *)multiValue)->flags.isMutable), //function ABMultiValueAddValueAndLabel
ABMultiValueAddValueAndLabel(multiPhone, @"1111111111", kABOtherLabel ,NULL);

It was because, in order to add some values to multiPhones var, this had to be mutable, it means to be ABMutableMultiValueRef type, so:

ABMultiValueRef multiPhones = ABRecordCopyValue(person, kABPersonPhoneProperty);
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutableCopy(multiPhones);
ABMultiValueAddValueAndLabel(multiPhone, @"1111111111", kABOtherLabel ,NULL);

that's all.









Wednesday, March 23, 2011

Jasper Report Headings missing in Excel

When I export a report to excel from jasperserver there are no headers shown.

If you look in jasperreports.properties in the relevant server directory - for Tomcat it's in /webapps/jasperserver/WEB-INF/classes - you'll see the following lines:
#suppress page and column headers and footers when exporting to XLS
net.sf.jasperreports.export.xls.exclude.origin.band.1=pageHeader
net.sf.jasperreports.export.xls.exclude.origin.band.2=pageFooter
net.sf.jasperreports.export.xls.exclude.origin.band.3=columnHeader
net.sf.jasperreports.export.xls.exclude.origin.band.4=columnFooter
Comment these lines out and and re-run your reports and you should see the headers and footer.

Source: http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=72256

Friday, March 18, 2011

Objective C: Logged User Singleton


//loggedUserDataSIngleton.h

#import <Foundation/Foundation.h>

@interface loggedUserDataSIngleton : NSObject {
    NSString *loginName;
}
   
@property (nonatomic, retain) NSString* loginName;
   
+(loggedUserDataSIngleton*)sharedMySingleton;
-(NSString*)obtainCurrentUserLoginName;

@end


//loggedUserDataSIngleton.m

#import "loggedUserDataSIngleton.h"


@implementation loggedUserDataSIngleton

@synthesize loginName;

static loggedUserDataSIngleton *_sharedMySingleton = nil;

+(loggedUserDataSIngleton*)sharedMySingleton
{
    @synchronized([loggedUserDataSIngleton class])
    {
        if (!_sharedMySingleton) {
            [[self alloc] init];
        }
       
        return _sharedMySingleton;
    }
   
    return nil;
}

+(id)alloc
{
    @synchronized([loggedUserDataSIngleton class])
    {
        NSAssert(_sharedMySingleton == nil, @"Attempted to allocate a second instance of a singleton.");
        _sharedMySingleton = [super alloc];
        return _sharedMySingleton;
    }
   
    return nil;
}

-(id)init {
    self = [super init];
    if (self != nil) {
        // initialize stuff here
    }
    return self;
}

-(NSString*)obtainCurrentUserLoginName {
    return self.loginName;
}

@end


then, in the .m you want to use the singleton, you have to import the loggedUserDataSIngleton.h:

#import "loggedUserDataSIngleton.h" 
....
....
....
....
// store login Name in singleton class  
//[loggedUserDataSIngleton sharedMySingleton].loginName = @"John";


// get stored login name
[[loggedUserDataSIngleton sharedMySingleton] loginName]




Reference:  http://getsetgames.com/2009/08/30/the-objective-c-singleton/

create person ABRecordRef: adding a contact to address book



CFErrorRef error = NULL;

ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();


ABRecordRef newPerson = ABPersonCreate();

ABRecordSetValue(newPerson, kABPersonFirstNameProperty, @"John", &error);

ABRecordSetValue(newPerson, kABPersonLastNameProperty, @"Doe", &error);

Here is the whole guide, it's very complete:


Source: http://www.modelmetrics.com/tomgersic/iphone-programming-adding-a-contact-to-the-iphone-address-book/

Wednesday, March 16, 2011

ASCII url encoding Objective C

 
NSString* escapedUrlString = [unescapedString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

Source: http://mesh.typepad.com/blog/2007/10/url-encoding-wi.html

Tuesday, March 15, 2011

getting value property from ABRecordRef - Extract Address Book Address Values Tutorial

I was searching for the way to get value properies from an ABRecordRef Object and I found out it was using ABRecordCopyValue:


NSString *name = (NSString *)ABRecordCopyValue(person
, kABPersonFirstNameProperty);
 
but the great thing I found was an Amazing Tutorial : 
Tutorial: Extract Address Book Address Values on iPhone OS 

Monday, March 7, 2011

MySQL - OperationalError: Error on rename (errno: 150)

Trying to execute:

alter table `bismark`.`d_area` drop index `tipo_area_id`

You Get:

Error on rename of '.\bismark\#sql-93c_1' to '.\bismark\d_area' (errno: 150)

You have to delete first the foreign key.

ALTER TABLE d_area DROP FOREIGN KEY tipo_area_id_FK;


Then you can drop the index and the column :D


Tuesday, March 1, 2011

.profile does not exist. Setting path var mac os

 - open a terminal console
- go to your User home:
cd /Users/<MyUser>
- create .profile file
touch .profile 
- open .profile file
open .profile
add the export sentence that you need, i.e.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH