MS Fortran Powerstation 4.0 “Preloaded symbol maynot match” problem during debug

I solved this problem and the solution is different from this one where it is recommended to check the order in which your libraries are loaded. If you encounter this message during debug of your program, you might have a bad directory name for your project.

For example, I had the following directory:

c:\Аспирантура\LACW_CYL\lacw_cyl 3.14\.

As you see, there are some non ASC II letters in this path. I didn’t actually know what to do, when I got that problem, but when I changed my folder name, this helped me and I am very glad, because now I can use my MS Fortran Powerstation 4.0 debugger and program nicely. Before that I even tried to install Intel and Compaq compilers but I didn’t like them, because they had their own problems, although may be they are better. So, I changed my folder to this one, and that worked out:

c:\Aspirantura\LACW_CYL\lacw_cyl 3.14\

How-To: URL Encode NSString with UTF-8 Characters in Objective-C

Let’s say you have to send a POST HTTP request that contains UTF-8 characters. But the problem is that url will not be formed if you simply try to generate it from a string. I managed that problem in the following way:

[crayon-662cc54e044f2290052757/]

References:

http://blog.evandavey.com/2009/01/how-to-url-encode-nsstring-in-objective-c.html

How to export a file to iPhone documents folder programmatically

Here I give an example of how to export a file to iPhone documents folder programmatically. I spent a lot of time on managing of how to do it. My main problem was that I couldn’t find documents folder of iPhone simulator. I couldn’t write anything to file and I used a wrong way with NSData class. Finally, I found a recipe in Internet and modified it a little bit.

So look at the example:

This is just a method. Firstly, we discover a documents Directory of a device. Then we NSLog it in order to find that directory on Mac, if we use iPhone/iPad simulator. Then we make a file name to write the data to using the documents directory. Then create content – four lines of text, including even some non ASCII text(that’ the modification). Then we just save content to the documents directory. Now that file is available through iTunes in programs tab, in the bottom of it for the given Applicaton. Note that you should add “Application supports iTunes file sharing” line and check it in your Info.plist file for your application in order to be able to use iTunes/iPhone/Programs/Your app to share files. Also note that encoding:NSUTF8StringEncoding is needed if you want to use non ASCII letters.

[crayon-662cc54e06803512642056/]

SQLite on Mac OS X examples

Here I decided to write some SQLite(SQLite on wiki) on Mac OS X examples of code for creation of database and database management.

1. Go to the folder where you want to create SQLite database (all this is written on Applications/Services/Terminal):

cd /Users/user/Documents/

2. Create database:

sqlite3 SimpleVocabulary.sql

3. Create table in that database:

CREATE TABLE Cards(CardID VARCHAR(5) PRIMARY KEY, Word VARCHAR(1000), Translation VARCHAR(3000), MemoStatus VARCHAR(1));

4. Insert values to the table:

INSERT INTO Cards VALUES ("1", "Mother", "Mama", "Y");

5. Select values from table:

SELECT * FROM Cards;

Another code examples:

1. cd /Users/user/Documents/
2. sqlite3 TexDatabase.sql
1.SELECT * FROM Lessons;
2.SELECT COUNT(*) FROM Lessons;
3.DELETE FROM Lessons;
4.CREATE TABLE Lessons(LessonID VARCHAR(5) PRIMARY KEY, LessonGroup VARCHAR(5), LessonTopic VARCHAR(100), LessonText VARCHAR(20000), LessonCode VARCHAR(100), LessonPicture VARCHAR(100));
5.Drop table Lessons;
6..schema

Here .schema command allows you to look at your tables structure.

Another example:
1. cd /Users/user/Desktop/Alwawee/AlwaweeApps/Бизнес-цитаты/Database
2. sqlite3 BusCitDatabase.sql
3. sqlite> CREATE TABLE BusCits(ID VARCHAR(5) PRIMARY KEY, Text VARCHAR(3000), Author VARCHAR(500));
4. sqlite> .quit
5. SELECT COUNT(*) FROM BusCits;
6. SELECT COUNT(*) FROM BusAuthors;
7. sqlite> CREATE TABLE BusAuthors(AuthorID VARCHAR(5) PRIMARY KEY, AuthorName VARCHAR(100), AuthorInfo VARCHAR(3000));
8. SELECT COUNT(*) FROM BusAuthors;
9. DELETE FROM BusAuthors;
10. DELETE FROM BusCits;
11. SELECT DISTINCT Author FROM BusCits WHERE Author NOT IN(SELECT AuthorName FROM BusAuthors);
12. cd /Users/user/Documents/
13. cd SimpVoc
14. sqlite3 TransWords.sql
15. INSERT INTO Cards VALUES ("1", "Mother", "Madre", "Y");
16. INSERT INTO Cards VALUES ("2", "Example", "Ejemplo", "Y");
17. INSERT INTO Cards VALUES ("3", "World", "Mundo", "Y");
18. SELECT * FROM Cards;

Here .quit command quits sqlite> mode on your Terminal.

The best way to remove mouse acceleration on Mac Os X

I have tried many shareware programs but finally I found a better, cheaper, faster way to remove it. You don’t need to change or think about any acceleration curves, etc.

This is the best way to remove mouse acceleration on Mac Os X:

In your terminal(terminal is located in Applicatons/Services/Terminal):

macpro:~ user$ curl -O http://ktwit.net/code/killmouseaccel
macpro:~ user$ chmod +x killmouseaccel
macpro:~ user$ ./killmouseaccel mouse

It was copypasted from here.

I write it here just in order not to loose such a useful recipe.

Simple examples of using SVN on Mac OS X

Let’s assume that you need to download some sources using SVN on your Mac from Internet, from some URL.

Creation of new directory
mkdir /Users/user/Documents/TwtAPI

Going to directory
cd /Users/user/Documents/TwtAPI

Example of download command
svn checkout http://svn.cocoasourcecode.com/MGTwitterEngine/

Another example, but it’s depricated because Google Translate is no longer available through API:
1. mkdir /Users/user/Documents/GoogleTranslateAPI
2. cd /Users/user/Documents/GoogleTranslateAPI
3. svn checkout http://objc-google-translate-api.googlecode.com/svn/trunk/ objc-google-translate-api-read-only

Objective C wrap over Microsoft Translator V2 API

We all know, that Google has stopped Google Translate Service for applications and made Google Translate API depricated. So I decided to use Microsoft Bing Translate API for my purposes of online word translation.

I managed to make an objective C wrap over Microsoft Bing Translate API for translation of one word. It is analogous to the wrap for Google Translate API, but it is much simpler because it doesn’t use any JSON or XML parsing.

I just extract a translated word from a string that I get by HTTP GET Method in Obj. C. In the first function I check weather I have an Internet connection setup properly and I start running a background function for translation. I make it in background thread not to freeze user interface.

Then I produce a url and make a request. When I get a contents string, I cut it a little bit to get a translation of word. That’s all.

Please post any comments if this was useful.


#define URL_STRING @"http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=here your own app id&text="

- (IBAction) translateBing:(id)sender
{
SimpVocAppDelegate *appDelegate = (SimpVocAppDelegate *)[[UIApplication sharedApplication] delegate];
// Флаг состояния Translate
appDelegate.translateActive = YES;

// Проверка соединения
if (appDelegate.internetActive == NO){
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Internet Connection problem"
message:@"There is no Internet Connection. Please, type translation yourself or leave blank"
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
// Флаг состояния Translate
appDelegate.translateActive = NO;
return;
}
// Проверка доступности Bing Translate
if (appDelegate.hostActive == NO){
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Translate Service problem"
message:@"Translation Service is not available. Please, type translation yourself or leave blank"
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
// Флаг состояния Translate
appDelegate.translateActive = NO;
return;
}

[self performSelectorInBackground:@selector(performLongTaskInBackground) withObject:nil];
}

- (void) performLongTaskInBackgroundBing
{
// Set up a pool for the background task.
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

SimpVocAppDelegate *appDelegate = (SimpVocAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *tText = wordTextField.text;

if ([tText isEqualToString:@""]==NO){
NSString *translation;
NSString *fromL;
NSString *toL;

fromL = [appDelegate.lang objectForKey:appDelegate.languageFrom];
toL = [appDelegate.lang objectForKey:appDelegate.languageTo];

NSMutableString* urlString = [NSMutableString string];
[urlString appendString: URL_STRING];
[urlString appendString: self.wordTextField.text];
[urlString appendString:@"&from="];
[urlString appendString: fromL];
[urlString appendString:@"&to="];
[urlString appendString: toL];

NSURL* url = [NSURL URLWithString: urlString];
NSURLRequest* request = [NSURLRequest requestWithURL: url cachePolicy: NSURLRequestReloadIgnoringCacheData timeoutInterval: 60.0];
NSURLResponse* response; NSError* error;
NSData* data = [NSURLConnection sendSynchronousRequest: request returningResponse: &response error: &error];
if (data == nil) {
//NSLog(@"Could not connect to the server: %@ %@", urlString, [error description]);
return nil;
} else {
NSString* contents = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease];
//NSLog(@"# %@ %@ %@", fromL, toL, contents);
//return [self translateCharacters: [[[contents JSONValue] objectForKey: @"responseData"] objectForKey: @"translatedText"]];

NSRange match;
match = [contents rangeOfString: @">"];
contents = [contents substringFromIndex: match.location+1];

match = [contents rangeOfString: @"<"]; translation = [contents substringWithRange: NSMakeRange (0, match.location)]; //NSLog(@"%@", contents); translationTextField.text = translation; // Флаг состояния Translate appDelegate.translateActive = NO; } [self performSelectorOnMainThread:@selector(completeLongRunningTask) withObject:nil waitUntilDone:YES]; [pool release]; } }

Here you can get some information about Bing Translate API :

http://www.microsofttranslator.com/dev/
http://msdn.microsoft.com/en-us/library/ff512423.aspx