Archive for the ‘Uncategorized’ Category.

My brain

A view weeks ago I fell over and basically scratched my head. However health care in Japan being how it is (of varying quality, but nothing if not high-tech) I could get an MRI done for about $70. I jumped at the chance, because I’ve always wanted to see inside my own head.

Anyway, for your viewing pleasure here are my MRI images, the raw DICOM data is also available as a tarball incase anyone playing with these systems is looking for a test dataset.

brainA

brainB

brainC

awk oneliners

Remove consecutive lines where the 2nd item is the same:

awk '{if($2 != v) print $0; v=$2}'

zlib simple example (gzseek)

Very simple zlib example. The neat thing is that zlib is transparent to uncompressed files, so you can just replace all your file seeking with zlib code and it’ll work with compressed and uncompressed code. It’s worth noting that gzseek does not support SEEK_END, which can cause issues.


#include <zlib.h>
#include <stdio.h>

int main() {
  gzFile file = gzopen("test.gz", "rb");
  if(file == NULL) {
    fprintf(stderr, "gzopen error\n");
  }

  char buffer[1000];
  int uncomprLen = gzread(file, buffer, 1000);
  buffer[uncomprLen]=0;
  printf("data: %s\n",buffer);  

  int pos = gzseek(file, 5, SEEK_SET);
  
  uncomprLen = gzread(file, buffer, 5);
  buffer[6]=0;
  printf("data: %s\n",buffer);  

  gzclose(file);
}

iOS copy/paste routines

Some basic iOS copy/paste sample code:

#import "UIPasteboard.h"

void iphone_copy(char *text) {
  UIPasteboard *pb = [UIPasteboard generalPasteboard];
  NSString *nstext = [NSString stringWithCString:text encoding:NSUTF8StringEncoding];
  [pb setValue:nstext forPasteboardType:@"public.plain-text"];
}

const char *iphone_paste() {
  UIPasteboard *pb = [UIPasteboard generalPasteboard];
  NSString *nstext = [pb valueForPasteboardType:@"public.utf8-plain-text"];
  return [nstext cStringUsingEncoding:NSUTF8StringEncoding];
}