Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Sauve jsauve

View GitHub Profile
View NiceViewModelAndPageXamarinFormsExample.cs
using System;
using MvvmHelpers;
using PropertyChanged;
using Xamarin.Forms;
namespace Blah
{
// The rest of this page is of course defined in XAML
public partial class MyPage : ContentPage
{
View RemoveByKey.cs
private static IEnumerable<KeyValuePair<TKey,TValue>> RemoveByKey<TKey,TValue>(
this IEnumerable<KeyValuePair<TKey,TValue>> pairs,
string key)
{
var index = pairs.Select(x => x.Key).ToList().FindIndex(x => x.Equals(key));
if (index >= 0)
{
var result = pairs.ToList();
result.RemoveAt(index);
View gist:3e3de4ba15d89c9ced4d
logoImageUrl =
!String.IsNullOrEmpty(logoImageUrl) ?
logoImageUrl : null;
@jsauve
jsauve / AsyncDapperDemo.cs
Last active May 7, 2021
Async Dapper Demo. Includes buffered and non-buffered connection helpers.
View AsyncDapperDemo.cs
using System;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Dapper;
public class Program
{
public static void Main()
@jsauve
jsauve / gist:ef2a2aab137f7e8f33ad
Created Nov 18, 2014
drop sproc only if exists
View gist:ef2a2aab137f7e8f33ad
-- USE THIS?
IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[mySproc]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
BEGIN
DROP PROCEDURE dbo.mySproc;
END;
GO
-- OR JUST THIS?
View gist:19c084612ac0466921a0
DECLARE @time DATETIME = DATEFROMPARTS(2014, 11, 15);
-- Using 998 for milliseconds portion because using 999 winds up being the same as 000 of the next second, for some weird reason.
-- This winds up being 2014-11-15 23:59:59.997, even though we've specified 998.
SELECT DATETIMEFROMPARTS(DATEPART(year, @endTime), DATEPART(month, @endTime), DATEPART(day, @endTime), 23, 59, 59, 998);
@jsauve
jsauve / gist:d6381ead501a31b85613
Created Nov 6, 2014
join using spaces and registered trademark symbol: proof of concept
View gist:d6381ead501a31b85613
DECLARE @brands TABLE (brand NVARCHAR(50));
INSERT INTO @brands (brand)
VALUES ('BF Goodrich');
SELECT *
FROM dbo.productOwners
INNER JOIN @brands ON
REPLACE(LOWER(brand), ' ', '') = REPLACE(LOWER(productOwner_name), ' ', '') OR
REPLACE(LOWER(productOwner_name), ' ', '') = CONCAT(REPLACE(LOWER(brand), ' ', ''),'®')
View gist:7468fd3046a70665539a
DECLARE @atdString NVARCHAR(50), @ariString NVARCHAR(50);
SET @atdString = 'BF Goodrich'; -- the brand name as it exists in ATD
SET @ariString = 'BFGoodrich®'; -- the brand name as it exists in ARI
SELECT 1
WHERE
(
REPLACE(LOWER(@atdString), ' ', '') = REPLACE(LOWER(@ariString), ' ', '') OR
REPLACE(LOWER(@ariString), ' ', '') LIKE CONCAT(REPLACE(LOWER(@atdString), ' ', ''),'®')
@jsauve
jsauve / CSharpCodingStandards
Last active Aug 29, 2015
My C# coding standards
View CSharpCodingStandards
public class MyClass
{
private Object _Something;
public Object Something
{
get { return _Something; }
set { _Something = value; }
}
public void MyMethod (object myParam)
@jsauve
jsauve / TriggeredQueue
Last active Feb 3, 2021
TriggeredQueue<T>. A very handy little class that I use on some projects. Not thread-safe, like ConcurrentQueue<T>, but good for lots of different queueing jobs where you need events fired before and after enqueuing and dequeuing.
View TriggeredQueue
using System;
using System.Collections.Generic;
namespace JoeSauve
{
/// <summary>
/// Triggered queue. Provides events immediately before and after enqueueuing and dequeuing.
/// </summary>
public class TriggeredQueue<T>
{