Following on from my previous post on implementing a stack in Java, I now wish to discuss the as important queue data-structure.
Similar in kind to the restrictions placed upon the stack implementation, the queue only allows mutation via two methods.
Addition (enqueue) occurs at the end of the collection, and removal (dequeue) from the beginning, resulting in a FIFO (First-In-First-Out) structure.
Queues are typically used in the application of buffers to store data, objects, events etc. that are to be held for future sequential processing.
Discussed in the post on stacks, you are more than likely never going to have to implement such a data-structure in practical use-cases, as the language libraries will already include such an implementation (i.e. C++ STL and PHP SplQueue).
The Shunting Yard algorithm was developed by the great Edsger Dijkstra as a means to parse an infix mathematical expression into Reverse Polish notation (postfix).
Using said notation allows the computer to evaluate the expression in a simple stack based form, examples of which I have shown in Scala.
The algorithm itself also uses a stack along with a built-up output string to create the resulting value.
Below is an example implementation which only takes into consideration bracket and the four common operator precedences.
Although it is possible to evaluate more, including functions and associativity, I decided on keeping the implementation simple to better highlight the process.
YouTube unfortunately does not provide you with the ability to upload audio tracks individually, which is a pain if you do not work with video (such as a podcast).
The way to get around this limitation is to create a video which includes the desired audio track and a fixed image (i.e. cover-art) which lasts the duration of the track.
There are many ways of achieving such a result, from iMovie and Windows Movie Maker to the online service TunesToTube.
With a little research however, I was able to come up with a even simpler solution that only requires the ever useful ffmpeg.
The stack is a fundamental data-structure used extensively in algorithm design and program implementation.
At an abstract level it can be described very simply, as it only allows for addition (pushing) of new and removal (popping) of existing elements from the top of the stack.
This description can be abbreviated to LIFO, which stands for Last-In-First-Out.
Although you will most likely not have to implement such a structure for practical use-cases, it can be very useful to ‘look under the hood’ to gain a better understanding of what is going on.
Doing so will make you more aware of when this data-structure can be best used.
Tools such as AWStats and Logstalgia are great, but sometimes they can be over-kill for the problem we are trying to solve.
It turns out that with a couple of simple Unix commands we can gather a lot of useful information from the data stored in our the access logs.
Both Apache and Nginx by default use the combined log format which I will be basing this posts examples on.
Below are two different methods of accessing either an uncompressed single file or multiple compressed files (following the supplied wild-card pattern).