Skip to content

Instantly share code, notes, and snippets.

@maxfridbe
maxfridbe / del_smaller_than.ps1
Created May 14, 2020 16:36
..fucking powershell
$id = get-random
$maxSizeMB = 500
$code = @"
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace HelloWorld
@maxfridbe
maxfridbe / ShouldSerializeContractResolver.cs
Created January 15, 2020 20:48
will serialize only not null or empty lists
public class ShouldSerializeContractResolver : DefaultContractResolver
{
public static readonly ShouldSerializeContractResolver Instance = new ShouldSerializeContractResolver();
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
JsonProperty property = base.CreateProperty(member, memberSerialization);
if (property.PropertyType == typeof(string))
return property;
@maxfridbe
maxfridbe / gist:b6ad5196894826741cb8fc154986d06f
Created April 9, 2019 16:26 — forked from pmn/gist:1145504
C# Comb Guid generation
// C# Comb Guid generation
// Found at http://stackoverflow.com/questions/665417/sequential-guid-in-linq-to-sql/2187898#2187898
Guid GenerateComb()
{
byte[] destinationArray = Guid.NewGuid().ToByteArray();
DateTime time = new DateTime(0x76c, 1, 1);
DateTime now = DateTime.Now;
TimeSpan span = new TimeSpan(now.Ticks - time.Ticks);
TimeSpan timeOfDay = now.TimeOfDay;
function wait-websiteup($testUrl, $timeoutSeconds){
$webClient = new-object System.Net.WebClient
$webClient.Headers.Add(“user-agent”, “PowerShell Script”)
$startTime = get-date
while (1 -eq 1) {
$output = “”
try{
@maxfridbe
maxfridbe / api.cs
Created August 26, 2014 15:52
File Upload multipart
//API
public async Task<HttpResponseMessage> DeployPackage()
{
if (!Request.Content.IsMimeMultipartContent("form-data"))
{
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
@maxfridbe
maxfridbe / wpflanguageswitch.cs
Created January 23, 2013 21:26
Dynamic Localization wpf
In code:
<Button
Content="{DynamicResource Previous}"
Command="{Binding PrevView}" Grid.Column="0"/>
<Window.Resources>
<ResourceDictionary>
<!--<Selectors:ViewSelector x:Key="ViewSelector">
</Selectors:ViewSelector>-->
<ResourceDictionary.MergedDictionaries>
@maxfridbe
maxfridbe / structure.md
Last active December 10, 2015 21:28
Structure of WPF app

Structure of WPF App

  • Presentation.WPF - Main path in presentation layer for WPF
    • Views - Views xaml to be located here
      • Controls - Page xaml like things here
      • Converters - UI Converters here
      • Validators - Validation code here
      • Windows - Window xaml files here
    • ViewModels - ViewModels matching names of views/windows here
    • Themes - Global themes to be uesd in Views and reused
  • Resources - Files like StringResources.xaml, StringResources.fr-CA.xaml here
@maxfridbe
maxfridbe / getip.cs
Created December 21, 2012 20:31
get ip
//http://stackoverflow.com/a/10407992/51841
using System;
using System.Linq;
using System.Net;
using System.Web;
public class RequestHelpers
{
public static string GetClientIpAddress(HttpRequestBase request)
@maxfridbe
maxfridbe / tasking.cs
Created December 21, 2012 20:31
periodically run task with cancellation input
//original http://stackoverflow.com/a/7472334/518
var cancellationTokenSource = new CancellationTokenSource();
var task = Repeat.Interval(
TimeSpan.FromSeconds(15),
() => CheckDatabaseForNewReports(), cancellationTokenSource.Token);
internal static class Repeat
{
@maxfridbe
maxfridbe / domainAuthentication.cs
Created December 21, 2012 20:26
domain authentication filter
#region Authentication
private List<string> getGroupNames(string userName)
{
using (var pc = new PrincipalContext(ContextType.Domain, _domainUri))
{
var identity = UserPrincipal.FindByIdentity(pc, userName);
if (identity == null)
return new List<string>();