940Protecting a Single File with .htaccess
In .htaccess:
<Files myfile.php>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile /path/to/.htpasswd
Require valid-user
</Files>
In .htaccess:
<Files myfile.php>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile /path/to/.htpasswd
Require valid-user
</Files>
Getting a single file (with convenience jQuery event handler)
$('#open #chooseFile').change(function(e){
var fileList = e.target.files;
// get the one and only file
var file = fileList[0];
// further process file content...
var reader = new FileReader();
reader.readAsText(file, "text/plain");
reader.onload = localLoaded;
reader.onerror = localError;
// ...
});
Getting multiple files:
$('#open #chooseFile').change(function(e){
var fileList = e.target.files;
// loop over the files
for (var i=0, file; file=fileList[i]; i++) {
var reader = new FileReader();
reader.readAsText(file, "text/plain");
reader.onload = localLoaded;
reader.onerror = localError;
// ...
}
});
Ok, here's a challenge. Say, you have a massive, 11 Gigabyte text file. The first two lines are the header files, unfortunately the header on line 2 is slightly wrong: Instead of 'Done' it should say 'Status:Done'. (Hit: 'Done' is the first occurrence of that string in that line)
Any Ideas?
[Update]
sed seems to be the tool for this job.
sed '2 s/Done/Status:Done/' input.txt > output.txt
Took about 7 minutes on my machine... Any better ideas still very much appreciated.
[Update 2: How to insert a tab with sed]
Inserting a tab with sed turned out to be more resilient than expected. Neither an escaped tab (\t) not a double-escaped tab (\t) seemed to do the trick. On bash it is necessary to drop out of sed and print the tab (\011) directly. 27 in the following statement means of course line 27.
sed '27 s/Done/Status:Done'"$(printf '\011')"'After Tab/' in.txt > out.txt
- (BOOL)writeToFile:(NSString *)path
atomically:(BOOL)useAuxiliaryFile;
Works with:
NSDictionary
NSArray
NSData
NSString
For more complicated purposes, NSOutputStream
might be the best option, but for simply writing a date or even XML this might be the simplest and fasted way.