Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Martyr2 Martyr2

🎯
Focusing
View GitHub Profile
@Martyr2
Martyr2 / semantic_versioning.cs
Created Oct 7, 2017
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
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.");
@Martyr2
Martyr2 / grayscale.cs
Created Oct 11, 2017
Grayscale an image (in other words make it black and white)
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)) {
@Martyr2
Martyr2 / read_line_number.cs
Created Oct 11, 2017
Reads the Nth line from a text file. It will throw exceptions if the file has fewer lines or Nth line is negative.
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;
@Martyr2
Martyr2 / db_pdo_class.php
Last active Nov 29, 2018
Database PDO wrapper class for PHP
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");
@Martyr2
Martyr2 / date_validator.java
Last active Feb 15, 2020
DateValidator class in Java which will validate dates
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;
}