Skip to content

Instantly share code, notes, and snippets.

View CallumWatkins's full-sized avatar

Callum Watkins CallumWatkins

View GitHub Profile
@CallumWatkins
CallumWatkins / SumBetween.cs
Last active February 18, 2017 16:31
Calculates the sum of all the integers in the range between two integers, with the option to exclude them. License: MIT
/// <summary>
/// Calculates the sum of all the integers in the range between two integers.
/// </summary>
/// <param name="start">The starting integer.</param>
/// <param name="end">The ending integer.</param>
/// <param name="exclusive">Whether or not the <paramref name="start"/> and <paramref name="end"/> integers are excluded from the sum.</param>
/// <returns>Returns the sum of the integers in the range.</returns>
private static long SumBetween(int start, int end, bool exclusive = false)
{
if (start > end) { throw new ArgumentException("End value must be more than or equal to start value."); }
@CallumWatkins
CallumWatkins / Compass.cs
Last active February 18, 2017 16:31
A class to convert between bearings and compass directions. License: MIT
public static class Compass
{
public enum CompassDirection { N, NbE, NNE, NEbN, NE, NEbE, ENE, EbN, E, EbS, ESE, SEbE, SE, SEbS, SSE, SbE, S, SbW, SSW, SWbS, SW, SWbW, WSW, WbS, W, WbN, WNW, NWbW, NW, NWbN, NNW, NbW }
public enum CompassPoints { Four = 4, Eight = 8, Sixteen = 16, ThirtyTwo = 32 }
public static Dictionary<CompassDirection, string> CompassDirections
{
get
{
return new Dictionary<CompassDirection, string>()
@CallumWatkins
CallumWatkins / CreateFileAndDirectory.cs
Last active February 18, 2017 16:31
Creates all directories and subdirectories unless they already exist and creates or overwrites a file in the specified path. License: MIT
using System;
using System.IO;
/// <summary>
/// Creates all directories and subdirectories unless they already exist and creates or overwrites a file in the specified path.
/// </summary>
/// <param name="path">The full path of the file.</param>
public static FileStream CreateFileAndDirectory(string path)
{
if (path == null) { throw new ArgumentNullException(nameof(path)); }
@CallumWatkins
CallumWatkins / OpenWindowsExplorerSearch.cs
Last active February 18, 2017 16:30
Opens a Windows Explorer file/folder search for the specified query, with the option of a location. License: MIT
public void SearchWindowsExplorer(string query, string location = null)
{
if (location != null && !Directory.Exists(location))
{
throw new ArgumentException("Directory does not exist.", "location");
}
string uri = "search:query=" + Uri.EscapeDataString(query) +
(location == null ? string.Empty : "&crumb=location:" + Uri.EscapeDataString(location));
Process.Start(uri);
}
@CallumWatkins
CallumWatkins / IsInIntegerRange.cs
Last active February 18, 2017 16:29
Checks whether any given integer is located in the range between two other integers. License: MIT
/// <summary>
/// Checks whether any given integer is located in the range between two other integers.
/// </summary>
/// <param name="i">The integer to check.</param>
/// <param name="min">The minimum value of the range.</param>
/// <param name="max">The maximum value of the range.</param>
/// <param name="inclusive">Whether or not the minumum and maximum values are included in the range.</param>
/// <returns>Boolean</returns>
private static bool IsInIntegerRange(this int i, int min, int max, bool inclusive = true)
{

Keybase proof

I hereby claim:

  • I am CallumWatkins on github.
  • I am callumwatkins (https://keybase.io/callumwatkins) on keybase.
  • I have a public key whose fingerprint is 7A2C 9986 AF66 4A9E 2A8D 869F C71C 342D A44D AB84

To claim this, I am signing this object:

Verifying that +callumwatkins is my blockchain ID. https://onename.com/callumwatkins
@CallumWatkins
CallumWatkins / SplitInParts.cs
Last active June 27, 2017 19:25
Splits a string into blocks of a specified length, delimited by a specified string. License: MIT
/// <summary>
/// Splits a string into blocks of a specified length, delimited by a specified string.
/// </summary>
/// <param name="value">The string to split up.</param>
/// <param name="partLength">The number of characters between each delimiter.</param>
/// <param name="delimiter">The delimiter to be inserted.</param>
public static string SplitInParts(string value, int partLength, string delimiter)
{
if (value == null) { throw new ArgumentNullException(nameof(value)); }
if (partLength < 1) { throw new ArgumentException("Part length must be positive and greater than zero.", nameof(partLength)); }
@CallumWatkins
CallumWatkins / NetworkChecker.bat
Last active March 20, 2024 08:58
A batch file to periodically check your internet connection, restart on failed connection and write to log. License: MIT
@echo off
mode con: cols=55 lines=12
title Network Checker
REM Server to be pinged
SET server=google.co.uk
REM Size of packet to be send to server (bytes)
SET packetSize=1
REM Network info
SET netSSID=[SSID]