Sunday, February 26, 2012

More text encoding issues

Is it me or is TextEdit for the mac just not very good at figuring out text encodings?

I'm trying to create a new HTML file from a word doc that has spanish characters in it. If I cut and paste into TextEdit, that works/looks fine, but if I try to display in Safari the character mapping is off. However if I then save the TextEdit file as UTF-8 and then use iconv to convert to ISO-8859-1, then all is fine. Trying to save the TextEdit file as Western OS doesn't do the trick.

I did try to add a meta charset tag to the HTML, but either I did it wrong or it was ignored.

Wednesday, January 11, 2012

Perl, UTF-8, and TextEdit character encoding hell

I'm working on a project where I need to dynamically read in content from a flat file. The flat file contains some template information and then I'm also pasting in the contents (using TextEdit) of a file that was generated using Perl database access.

The problem was that when I read it into a string using stringWithContentsOfFile and NSUTF8StringEncoding it would blow up. I could use NSASCIIStringEncoding, but then some of the characters (e.g em dash, single double quote) were translated incorrectly. If I brought this file up in TextEdit or Dashcode, everything looked great. Displaying the file in vi or the command line did not.

When I did a file -I foo.txt it reported the file type was "unknown" although the Perl generated file was utf-8.

I traced the problem down to the TextEdit "Plain Text File Encoding" preferences. Both "Opening Files" and "Saving Files" were set to UTF-8. This was helpful to read the data, but somehow when saving the pasted-in content, it caused the file type to get hosed such that certain tools (e.g. my command window which is set to UTF-8) could no longer properly read the characters.

Once I set the preferences back to automatic, the saved file is now utf-8, but the special characters don't display correctly in TextEdit. The file also loads with UTF8 encoding into an NSString.

Weird.

That's three hours of my life I'll never get back.

Thursday, November 10, 2011

Dealing with expired developer and distribution certificates

So, round this time every year for the last few, I go into a small panic as I try to remember the steps to recreate my development and distribution certificates.

Fortunately, after cruising various blogs and the Developer Forums I saw a reference to this document:

http://developer.apple.com/library/ios/#technotes/tn2250/_index.html%23//apple_ref/doc/uid/DTS40009933


I worked thru the section on Deleting/Revoking Your Certificates and Starting Fresh and was done in about 10 minutes.

Waaayyy easier than anything else I've seen out there...

Wednesday, October 26, 2011

password protect a zip file on the mac

From the command line: zip -re foo.zip file1.txt file2.txt

you'll be prompted for a password

Saturday, October 1, 2011

iconv - for converting file formats

TextEdit on the mac doesn't do such a good job converting language files from the PC. I've found the following command line command works better:

iconv -f ISO-8859-1 -t UTF-16 [input file] > outputfile

Thursday, September 8, 2011

UIWebview resizing text on rotation

Ran into a multi-layered problem this morning with UIWebView. I have an app where a table view cell can pop open and reveal a UIWebView. The problem was on rotation - if I rotated the device and then popped up the cell, the text was too big. I found the fix here. I just added this to the html style tag:

-webkit-text-size-adjust: none;

Saving for future reference.

Tuesday, August 9, 2011

Clear out a corrupted Xcode 4 project state

I ran into a situation this morning where my Xcode 4 got into a bad state and wouldn't start. Beachballs galore.

Cleared it by going into my user directory, then into Library, and doing a

rm -rf "Autosave Information"