Sonntag, 21. Dezember 2014

NSInternalInconsistencyException: "Invalid update: invalid number of rows in section 0"

After adding deletion to a UITableView in an iOS application  (which is usually pretty straightforward), I got an 

NSInternalInconsistencyException: "Invalid update: invalid number of rows in section 1" 

where the counts were somewhat strange (inserted 0, deleted 0). After disabling the deletion of the elements from the underlying array, I got 

NSInternalInconsistencyException: "Invalid update: invalid number of rows in section 0" 

where the counts were what I expected (inserted 0, deleted 1).  Turns out I had implemented 

numberOfSectionsInTableView()

to return 2; changing this to return 1 fixed the error.

Mittwoch, 6. August 2014

Tracing system calls on Mac OS X

Tracing system calls on Mac OS X is incredibly simple with dtruss (which is just a shell script that wraps a fancy configuration for dtrace):

  sudo dtruss -f ~/scratch/bla.sh

The -f instructs dtruss to also trace system calls for forked child processes (which I usually want).

Freitag, 31. Januar 2014

Ruby one-liner: print only the matching part of a string

Sometimes, you have to extract information from a log file or similar. This is where Ruby's command line parameters -n / -p are very convenient.

Our example input file will look like this:

2014-01-31 13:00:49    "Missing author for experiment ""FS_1"", row ""176""
2014-01-31 14:05:51    "Missing date for experiment ""FS_2"", row ""32""


Simple grep replacement

To get only lines containing "author", you can use

ruby -pe 'next unless $_ =~ /author/'

Output

2014-01-31 13:00:49    "Missing author for experiment ""FS_1"", row ""176""

Explanation 

 -p instructs Ruby to put your script inside "while gets; ...; print; end". You can access the current line with $_.

Transforming the input with regular expressions

To extract the information  for those lines where the author is missing, you can use
ruby -ne 'md = /Missing author for experiment ""([^"]+)"", row ""([^"]+)""/.match($_); puts md[2] + "," + md[1] if md' input.txt

Output:

176,FS_1

Explanation

 -n instructs Ruby to put your script inside "while gets; ...; end". You can access the current line with $_.

Links

http://ruby-doc.com/docs/ProgrammingRuby/ Online version of the original pickaxe (for Ruby 1.6), see section "Ruby and Its World" for a list of Ruby command-line arguments