This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Database PDO Wrapper | |
*/ | |
if (!class_exists('Database')) { | |
// Define configuration | |
define("DB_HOST", "localhost"); | |
define("DB_USER", "username"); | |
define("DB_PASS", "pass"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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)); | |
} |
NewerOlder