Skip to content

Instantly share code, notes, and snippets.

View Martyr2's full-sized avatar
🪄
Looking for company to work magic for

Tim Hurd Martyr2

🪄
Looking for company to work magic for
View GitHub Profile
@Martyr2
Martyr2 / user.php
Created October 1, 2017 16:46
Simple User class with supporting Address class. This serves as a basic starting point for developing a quick user class for projects and can be expanded on further.
<?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;
@Martyr2
Martyr2 / semantic_versioning.cs
Created October 7, 2017 23:00
Compare versions semantically and will tell you if the newer version is in fact newer than the current version. For more information refer to http://semver.org
/// <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.");
@Martyr2
Martyr2 / grayscale.cs
Created October 11, 2017 02:42
Grayscale an image (in other words make it black and white)
/// <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)) {
@Martyr2
Martyr2 / read_line_number.cs
Created October 11, 2017 02:51
Reads the Nth line from a text file. It will throw exceptions if the file has fewer lines or Nth line is negative.
/// <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;
@Martyr2
Martyr2 / date_validator.java
Last active February 15, 2020 16:44
DateValidator class in Java which will validate dates
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;
}