Skip to content

Instantly share code, notes, and snippets.

@maxfridbe
maxfridbe / program_npgsql.cs
Created November 15, 2012 19:15
postgress npgsql
class Program
{
static void Main(string[] args)
{
var sqlConfig = MsSqlConfiguration.MsSql2008.ConnectionString(@"Server=.\SQLEXPRESS;Database=testdb3;Trusted_Connection=True;");
var config = PostgreSQLConfiguration.PostgreSQL82.ConnectionString(c =>
c.Database("testdb3")
.Host("localhost")
.Port(5432)
@maxfridbe
maxfridbe / timing.cs
Created November 28, 2012 16:53
Timing function
public class DisposableStopwatch: IDisposable {
private readonly Stopwatch sw;
private readonly Action<TimeSpan> f;
public DisposableStopwatch(Action<TimeSpan> f) {
this.f = f;
sw = Stopwatch.StartNew();
}
public void Dispose() {
@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>();
@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 / 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 / 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 / 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 / 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);
}
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 / 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;