Skip to content

Instantly share code, notes, and snippets.

@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("\\?", ".") + "$";
}
@jnm2
jnm2 / WeakEventSource2.cs
Last active September 20, 2023 11:34
Replaces a multicast delegate as an event's backing store. Duplicate behavior, except it is thread safe and holds weak references. (Same as WeakEventSource.cs, but uses WeakDelegate instead of ConditionalWeakTable.)
// MIT license, copyright 2015 Joseph N. Musser II
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
namespace jnm2
{
public struct WeakDelegate<TDelegate> : IEquatable<WeakDelegate<TDelegate>> where TDelegate : class
@jnm2
jnm2 / WeakEventSource.cs
Last active August 27, 2019 07:40
Replaces a multicast delegate as an event's backing store. Duplicate behavior, except it is thread safe and holds weak references.
// MIT license, copyright 2015 Joseph N. Musser II
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
namespace jnm2
{
@DanielSWolf
DanielSWolf / Program.cs
Last active April 17, 2025 05:36
Console progress bar. Code is under the MIT License: http://opensource.org/licenses/MIT
using System;
using System.Threading;
static class Program {
static void Main() {
Console.Write("Performing some task... ");
using (var progress = new ProgressBar()) {
for (int i = 0; i <= 100; i++) {
progress.Report((double) i / 100);
@cjddmut
cjddmut / EasingFunctions.cs
Last active May 31, 2025 14:18
Easing Functions for Unity3D
/*
* Created by C.J. Kimberlin
*
* The MIT License (MIT)
*
* Copyright (c) 2019
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@cjddmut
cjddmut / DelegateWrappers.cs
Last active January 28, 2024 21:39
Wrapper struct for delegates. Helps avoid mistakes like '=' when '+=' was intended. Also checks for null automatically before invoke.
/*
* Created by C.J. Kimberlin (http://cjkimberlin.com)
*
* The MIT License (MIT)
*
* Copyright (c) 2014
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
/// <summary>
/// Wrapper for GDI text rendering functions<br/>
/// This class is not thread-safe as GDI function should be called from the UI thread.
/// </summary>
/// <remarks>
/// http://theartofdev.com/2013/08/12/using-native-gdi-for-text-rendering-in-c/<br/>
/// The MIT License (MIT) Copyright (c) 2014 Arthur Teplitzki.
/// </remarks>
public sealed class NativeTextRenderer : IDisposable
{
@aksakalli
aksakalli / SimpleHTTPServer.cs
Last active January 4, 2025 06:04
SimpleHTTPServer in C#
// MIT License - Copyright (c) 2016 Can Güney Aksakalli
// https://aksakalli.github.io/2014/02/24/simple-http-server-with-csparp.html
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.IO;
@willurd
willurd / web-servers.md
Last active June 3, 2025 15:43
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@klange
klange / TransparentLabel.cs
Created January 6, 2012 23:59
Stroked Transparent Label
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Linq;
using System.Windows.Forms;
public class TransparentLabel : Label {
public TransparentLabel() {