View date_validator.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateValidator {
public boolean isThisDateValid(String dateToValidate, String dateFromat) {
if (dateToValidate == null) {
return false;
}
View read_line_number.cs
/// <summary>
/// Reads the Nth line from the file specified by filepath.
/// </summary>
/// <param name="filepath">Path to the file to read</param>
/// <param name="linenumber">Line number of the line to return</param>
/// <returns>Returns Nth line</returns>
private String readLineNumber(String filepath, int linenumber) {
if (linenumber > 0) {
using (StreamReader reader = new System.IO.StreamReader(filepath)) {
var count = 1;
View grayscale.cs
/// <summary>
/// Grayscales an image
/// </summary>
/// <param name="source">Source image to grayscale</param>
/// <returns>New grayscaled image</returns>
private Image grayScale(ref Image source) {
Bitmap bitMap = new Bitmap(source);
using (Graphics g = Graphics.FromImage(bitMap)) {
View semantic_versioning.cs
/// <summary>
/// Determines if the new version is semantically newer than the current version.
/// </summary>
/// <param name="currentVersion">Current version number or build</param>
/// <param name="newVersion">New version to compare to the current version</param>
/// <returns>True if the newer version is semantically newer than the current version. False if not.</returns>
/// <remarks>Semantic versioning details at http://semver.org</remarks>
private bool IsSemanticallyNewerVersion(string currentVersion, string newVersion) {
if (!IsVersionSemanticallyValid(currentVersion)) {
throw new ArgumentException("Current version is not semantically valid. Cannot compare.");
View user.php
<?php
/**
* Basic user class to hold some standard data and designed to be expanded and altered as necessary.
*/
class User {
private $userID = 0;
private $firstName = '';
private $lastName = '';
private $address = null;
View logger.php
<?php
class Logger {
private static $timestamp = 'Y-m-d H:i:s';
private static $logFileNameFormat = 'Y-m-d';
private static $logDirLocation = __DIR__;
private static $logLevels = ['DEBUG', 'INFO', 'WARN', 'ERROR'];
private static $minLogLevel = 'INFO';
View cryptor.php
<?php
/**
* Static class for simple encryption and decryption utilities.
*/
class Cryptor {
// This key is used if one is not supplied during encryption / decryption.
private const UNIQUE_KEY = '<some default key here>';
private const METHOD = 'AES-256-CTR';
View flatten_array.php
<?php
namespace FlattenArray;
/**
* Iterative approach to flatten a multi-dimensional array of values.
* Notes: Non-array values are untouched so this could be an array of integers, strings, objects etc. An iterative approach is
* taken here over a recursive one as to not overload the call stack on deeply nested arrays.
*/
function flatten($ar) {
View db_pdo_class.php
<?php
/**
* Database PDO Wrapper
*/
if (!class_exists('Database')) {
// Define configuration
define("DB_HOST", "localhost");
define("DB_USER", "username");
define("DB_PASS", "pass");
View LeftRight.cs
/// <summary>
/// Takes the left "length" characters of a string. Pretty much "Left" from the old VB library.
/// </summary>
/// <param name="str">String to take characters from</param>
/// <param name="length">Length of the string to take</param>
/// <returns>Substring of original string of the left most characters as specified by length</returns>
public static string Left(this string str, int length)
{
return str.Substring(0, Math.Min(length, str.Length));
}