Python seek on remote file using HTTP

If you are downloading the remote file through HTTP, you need to set the Range header. Check in this example how it can be done. Looks like this: myUrlclass.addheader(“Range”,”bytes=%s-” % (existSize)) EDIT: I just found a better implementation. This class is very simple to use, as it can be seen in the docstring. class HTTPRangeHandler(urllib2.BaseHandler): … Read more

iOS Audio Trimming

Here’s the code that I’ve used to trim audio from a pre-existing file. You’ll need to change the M4A related constants if you’ve saved or are saving to another format. – (BOOL)trimAudio { float vocalStartMarker = <starting time>; float vocalEndMarker = <ending time>; NSURL *audioFileInput = <your pre-existing file>; NSURL *audioFileOutput = <the file you … Read more

c++ fastest way to read only last line of text file?

Use seekg to jump to the end of the file, then read back until you find the first newline. Below is some sample code off the top of my head using MSVC. #include <iostream> #include <fstream> #include <sstream> using namespace std; int main() { string filename = “test.txt”; ifstream fin; fin.open(filename); if(fin.is_open()) { fin.seekg(-1,ios_base::end); // … Read more

Safe to have multiple processes writing to the same file at the same time? [CentOs 6, ext4]

What you’re doing seems perfectly OK, provided you’re using the POSIX “raw” IO syscalls such as read(), write(), lseek() and so forth. If you use C stdio (fread(), fwrite() and friends) or some other language runtime library which has its own userspace buffering, then the answer by “Tilo” is relevant, in that due to the … Read more