czwartek, 21 listopada 2013

How to reverse a string in BASH

How to reverse a string in #BASH console ?

Example:
#host$ echo -n "sebastian" |rev
naitsabes

How to load image from remote server on the UIImageView in iphone and save to application ?


Save An Image To Application Documents Folder From UIView On IOS.

Example:
//imageUrl = http://sebob.v1.pl/image.jpg
-(NSString *)saveLocalImageFromUrl:(NSString *)imageUrl
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filename = [imageUrl lastPathComponent]; //get base file name
    NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:filename];
   
    NSString *foofile = [documentsDirectory stringByAppendingPathComponent:localFilePath];
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];
   
    if(fileExists) {
        NSData *thedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];
        [thedata writeToFile:localFilePath atomically:YES];
    }
   
    return localFilePath;
}

wtorek, 5 listopada 2013

Doctrine 2 Zend Framework 2 with UTF-8

It's good solution for problem with Doctrine 2 and coding UTF-8.
This configuration set UTF-8 for DB.
This config: YourProjectPath/config/autoload/doctrine.local.php

return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' =>'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'host',
'port' => '3306',
'user' => 'username',
'password' => 'password',
'dbname' => 'dbname',
'charset' => 'utf8',
'driverOptions' => array(
1002=>'SET NAMES utf8'
))
))));