Skip to content

Instantly share code, notes, and snippets.

@flq
flq / NonTopmostPopup.cs
Created April 5, 2011 08:04
WPF: Popup that is only topmost with respect to parent window. Taken from the comments at http://chriscavanagh.wordpress.com/2008/08/13/non-topmost-wpf-popup/ (Joe Gershgorin) which was in not easy to digest state
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interop;
/// <summary>
/// Popup with code to not be the topmost control
@flq
flq / tax.cs
Created September 22, 2011 10:08
the tax thingy
public decimal GetTaxes(decimal salary)
{
decimal tax = 0;
var progressiveTaxation = new[] { 0.1m, 0.14m, 0.23m, 0.3m, 0.33m, 0.45m };
var progressionSlices = new[] { 5070 - 0, 8660 - 5070, 14070 - 8660, 21240 - 14070, 40230 - 21240, decimal.MaxValue };
var progression = 0;
while (salary > 0)
@flq
flq / AssemblyPoolRegistrar.cs
Last active July 8, 2021 10:23
Utility classes for named dependencies (,NET Core, C# 9)
using System;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
namespace DIPlaygroundWebApp.ServiceCollectionInfrastructure
{
public static class AssemblyPoolRegistrar
{
public static AssembliesForRegistration UseBulkRegistration(this IServiceCollection svcCollection,
@flq
flq / _intro.md
Last active June 18, 2020 19:57
Fizzbuzzes in many colours.

A collection of FizzBuzz implementations over many languages. The specification goes something like this...

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

The expected outcome is something like:

1,2,Fizz,4,Buzz,Fizz,7,8,Fizz,Buzz,
11,Fizz,13,14,FizzBuzz,16,17,Fizz,19,Buzz,

Fizz,22,23,Fizz,Buzz,26,Fizz,28,29,FizzBuzz,

@flq
flq / HttpFileServer.cs
Created April 17, 2010 09:39
Smallest file web server
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
public class HttpFileServer : IDisposable
{
private readonly string rootPath;
private const int bufferSize = 1024*512; //512KB
@flq
flq / UiMessages.cs
Created September 20, 2013 15:01
Example setup for Membus to dispatch messages of a certain kind onto the UI thread...
// Use like BusSetup.StartWith<Conservative>().Apply<UiMessages>().Construct();
internal class UiMessages : ISetup<IConfigurableBus>
{
void ISetup<IConfigurableBus>.Accept(IConfigurableBus setup)
{
setup.ConfigurePublishing(obj =>
{
obj.MessageMatch(mi => mi.IsType<IUIMsg>()).PublishPipeline(new UiMsgDispatcher());
});
@flq
flq / CompileHub.cs
Last active March 8, 2019 22:18
Roslyn Refactoring
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
namespace ReFuc
@flq
flq / dotnet_snippets.txt
Created August 16, 2018 20:44
Some nice .NET snippets
.NET snippets
1. Deconstruct a regex match group collection
@flq
flq / josephus.hs
Last active August 16, 2018 20:27
Stuff I made in Haskell
module Josephus where
import Data.List
-- own, atrocious solution to josephus problem
lastSurvivor :: Int -> Int
lastSurvivor 1 = 1
lastSurvivor noOfPeople = fst . last $ unfoldr theSurvivors (1,(1,[])) where
theSurvivors (person, (count, theKilled))
| length theKilled == noOfPeople - 1 = Just (countOn, breakCondition)
@flq
flq / nasties.cs
Last active December 16, 2017 12:04
Ye olde NRE from a ctor call
using System;
using System.Runtime.Remoting.Proxies;
internal class Program
{
private static void Main(string[] args)
{
var c = new CrazyObject();
Console.WriteLine(c.Hello());
Console.ReadLine();
}