Skip to content

Instantly share code, notes, and snippets.

View jsauve's full-sized avatar

Joe Sauve jsauve

View GitHub Profile
var myPage = new MyPage(); // or wherever your page comes from
var navPage = new NavigationPage(myPage);
await Navigation.PushModalAsync(navPage);
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
{
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);
@jsauve
jsauve / gist:3e3de4ba15d89c9ced4d
Created February 18, 2015 15:50
Three line ternary
logoImageUrl =
!String.IsNullOrEmpty(logoImageUrl) ?
logoImageUrl : null;
@jsauve
jsauve / AsyncDapperDemo.cs
Last active August 18, 2023 17:58
Async Dapper Demo. Includes buffered and non-buffered connection helpers.
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 November 18, 2014 18:39
drop sproc only if exists
-- 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?
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 November 6, 2014 19:03
join using spaces and registered trademark symbol: proof of concept
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), ' ', ''),'®')
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 August 29, 2015 14:05
My C# coding standards
public class MyClass
{
private Object _Something;
public Object Something
{
get { return _Something; }
set { _Something = value; }
}
public void MyMethod (object myParam)