Random coding notes…

Creating timestamp strings

Python

datetime.datetime.now().strftime("%Y%m%d%H%M%S")

C (POSIX)

char ts_buf[64] = "";
struct timeval tv;
struct tm *tm;
gettimeofday(&tv, NULL);
if ((tm = localtime(&tv.tv_sec)) != NULL)
  strftime(ts_buf, sizeof(ts_buf), "%Y%m%d%H%M%s", tm);

Read file one line at a time

Ruby

File.open(FILENAME,'r') do |f|
  while line = f.gets
    # do something interesting
  end
end