Snipperize snippets

Snipperize is a code clips warehouse, support nearly all the computer languages.
Here are the latest snippets. Please choose your favorite one or add a new one.

Date and Time Difference Calculate in PHP

Calculate date time difference.

PHP / date, time, calculate / by ThePeppersStudio (1 days, 11.86 hours ago)

Kohana System Configuration Hook

Instead of having multiple configurations for multiple domains, and the numerous if/then/else statements not to mention the various locations for storing the configuration....instead, enable hooks in your application config and then add this snippet of code into your application hooks directory.

PHP / php, kohana, system, configuration, hook / by ThePeppersStudio (5 days, 5.55 hours ago)

Check if a file exists

Check if a file exists use fstream.

C++ / file, fstream, exist / by ThePeppersStudio (6 days, 11.88 hours ago)

in-place stream formatting

void f( std::string const & ); void g( const char* ); f( make_string() << "Say hi" ); // works ok g( make_string() << "Bye" ); // kills the application g( (make_string() << "Hi again").c_str() ); // ok again std::string temporary is alive until g() returns

C++ / make_string, string, cstring, iostream / by ThePeppersStudio (7 days, 7.73 hours ago)

Fastest vs Easiest way to read a full file into a std::string.

Fastest vs Easiest way to read a full file into a std::string.

C++ / fastest, easiest, iostream, string, file / by ThePeppersStudio (7 days, 7.83 hours ago)

Useful debugging

It uses variadic macros.(http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html)

C++ / debug, variadic macros / by ThePeppersStudio (7 days, 7.91 hours ago)

Get the number of elements in an array

0[arr] is identical to arr[0] for arrays but will intentionally fail if it's used against a C++ object that overloads operator[] The C++ version is less intuitive but more type-safe

C++ / array, sizeof / by ThePeppersStudio (7 days, 7.94 hours ago)

Rsync Algorithm In Python

An implementation of the rsync algorithm in Python. As my rolling checksum, I just summed all of the ascii byte values in a given window. Even with this simple weak rolling checksum, computing and comparing the produced rolling checksums is still terribly slow. I'm fairly certain the speed could be reduced a fair amount but I haven't decided what the most efficient manner of doing this in Python alone would be.

Python / algorithm, delta, diff, rsync / by ThePeppersStudio (9 days, 9.59 hours ago)

Efficient Algorithm for computing a Running Median

Maintains sorted data as new elements are added and old one removed as a sliding window advances over a stream of data. Running time per median calculation is proportional to the square-root of the window size.

Python / algorithm, indexable, median, running, skiplist, statistics / by ThePeppersStudio (9 days, 9.70 hours ago)

NSDateFormater

How to use NSDateFormater

Objective-C / NSDateFormater, NSDate / by ThePeppersStudio (17 days, 13.18 hours ago)