Skip to content

Instantly share code, notes, and snippets.

View UweKeim's full-sized avatar
😊
www.uwe.co

Uwe Keim UweKeim

😊
www.uwe.co
View GitHub Profile
@UweKeim
UweKeim / convert-wildcards-to-regex.cs
Last active January 28, 2024 21:32
Convert wildcards to Regular Expressions.
private static string convertWildcardToRegex(string pattern)
{
// http://stackoverflow.com/a/6907849/107625
// http://www.codeproject.com/Articles/11556/Converting-Wildcards-to-Regexes
return "^" + Regex.Escape(pattern).
Replace("\\*", ".*").
Replace("\\?", ".") + "$";
}
@UweKeim
UweKeim / DayOfCentury.cs
Last active November 14, 2017 06:53
Calculate DayOfCentury for C# DateTime, similar to DayOfYear
/// <description>
/// Calculates the total number of days passed sind first of January 2000
/// until a given Date.
/// </description>
public static long DayOfCentury(DateTime dt)
{
var span = dt.Date - new DateTime(2000, 1, 1);
return (long)span.TotalDays;
}
@UweKeim
UweKeim / Texturizer.cs
Created September 25, 2017 13:35
Small, incomplete "port" of WordPress "wptexturize" function to .NET/C#
namespace ZetaProducer.RuntimeBusinessLogic.Rendering.Helper
{
using AngleSharp.Dom;
using AngleSharp.Parser.Html;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
public static class Texturizer
{
@UweKeim
UweKeim / QuickLogger.cs
Last active September 5, 2019 16:09
The shortest possible file logging class.
namespace Helper
{
using System;
using System.IO;
using System.Reflection;
/// <summary>
/// The shortest possible logger.
/// </summary>
public static class QuickLogger
@UweKeim
UweKeim / Check whether Outlook is installed via C#
Created May 30, 2013 15:07
Checks whether Microsoft Outlook is installed on a Windows system.
private bool IsOutlookInstalled()
{
Type requestType = Type.GetTypeFromProgID("Outlook.Application", false);
if (requestType == null)
{
RegistryKey key = null;
try
{
key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office", false);
if (key != null)