“Read” a file without using a file pointer
I was asked this question in an interview. I’m somehow supposed to “read” a file into my C program as input without using a file pointer (including “f” functions, e.g. fgets, fscanf etc.). I’m also not allowed to redirect it using the terminal, i.e. no system or exec calls. The program will not get the file during runtime.
hash with file instead of array
Is it possible to use hash function but with File instead of Array, and it’s gonna be saving the record in a file position and then search will fseek to that position, but I’m not sure how to open a file with let’s say 1000 line, do you think that method could work?
How are Java ByteBuffer’s limit and position variable’s updated?
There are two scenarios: writing and reading
Writing:
Whenever I write something to the ByteBuffer by calling its put(byte[])
method the position
variable is incremented as: current position + size of byte[]
and limit
stays at the max.
If, however, I put the data in a view buffer then I will have to, manually, calculate and update the position
Before I call the write(ByteBuffer)
method of the channel to write something, I will have to flip()
the Bytebuffer so that
position
points to zero and limit
points to the last byte that was written to the ByteBuffer.
Reading:
Whenever I call the read(ByteBuffer)
method of a channel to read something, the position
variable stays at 0 and the limit
variable of the ByteBuffer points to the last byte that was read. So, if the ByteBuffer is smaller than the file being read, the limit
variable is pushed to max
This means that the ByteBuffer is already flipped and I can proceed to extracting the values from the ByteBuffer.
Please, correct me where I am wrong 🙂
What does “windowed streaming” stand for?
So I was asking around the Mercurial development mailing list about binary diffing and patch handling and I got the following examples:
Criteria for selecting timeout value?
Situation: a piece of software reads frames of data from a file in a seperate thread and puts it on a queue, emptied by another thread. That second thread periodically checks on the queue and fails rather gracefully, by showing an error message stating the read timed out, if no data is available within a certain amount of time. Initially this timeout was set to 200mSec. There was no real reasoning behind that constant though, but it worked fine. We measured on a couple of machines and for large data frames, larger than what would be used by customers, a read took like 20mSec whith no other load on the machine.
PHP file_put_contents File Locking
The Senario:
Quickly compute added and removed lines
I’m trying to compare two text files. I want to compute how many lines were added and removed. Basically what git diff --stat
is doing. Bonus points for not having to store the entire file contents in memory.
Efficient way to check for changes to the contents of folders
I am creating an application that maintains a database of files of a certain type in a given folder (and all subfolders) Initially the program will recurse the folders and add any file it finds of that type to the database.
What’s the best practice for naming uploaded images?
Suppose I have a form in my web application where users can upload a profile picture.
How to design an application that read files using MVC pattern?
I am going to write an application that reads data from a csv file, and display that data to the user. I intend to apply an MVC design pattern to create this application. A user will interact with this application through a console. Hence the view is a console.