Skip to content

Instantly share code, notes, and snippets.

View JerryNixon's full-sized avatar
🤔
Trying to make a living.

Jerry Nixon JerryNixon

🤔
Trying to make a living.
View GitHub Profile
@JerryNixon
JerryNixon / Extensions.cs
Last active June 19, 2017 18:57
Some nifty extensions for UWP apps using web services
using System;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Web.Http;
public static class Extensions
{
#Prep
Update-ExecutionPolicy Unrestricted
Disable-UAC
#Win Config
Set-TaskbarOptions -Size Small -Lock -Dock Top
Set-ExplorerOptions -showHiddenFilesFoldersDrives -showProtectedOSFiles -showFileExtensions
Disable-InternetExplorerESC
@JerryNixon
JerryNixon / ObservableDictionary.cs
Created August 13, 2018 18:51
Generic observable dictionary.
public class ObservableDictionary<K, V> : INotifyCollectionChanged, IEnumerable<KeyValuePair<K, V>>
{
private Dictionary<K, V> _dictionary = new Dictionary<K, V>();
private void RaiseChanged(NotifyCollectionChangedAction action, params K[] keys)
{
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(action, keys));
DictionaryChanged?.Invoke(this, new NotifyDictionaryChangedEventArgs(action, keys));
}
@JerryNixon
JerryNixon / TimeZoneHelper.cs
Last active August 16, 2018 20:43
US-centric, 99% accurate time zone helper.
class Program
{
static void Main(string[] args)
{
Console.WriteLine(new DateTimeOffset(DateTime.Now));
foreach (var item in Enumerable.Range(1, 10))
{
var date = new DateTime(2018, 8, 16);
var offset = TimeSpan.FromHours(-item);
var now = new DateTimeOffset(date, offset);
@JerryNixon
JerryNixon / HolidayHelper.cs
Last active August 18, 2018 13:42
Public holidays in North America
public static class HolidayHelper
{
public static DateTime NewYears => new DateTime(DateTime.Now.Year, 1, 1).Date;
public static DateTime Christmas => new DateTime(DateTime.Now.Year, 12, 25).Date;
public static DateTime GoodFriday => GetEaster(DateTime.Now.Year).AddDays(-2);
public static DateTime Easter => GetEaster(DateTime.Now.Year);
public static class Canada
{
public static DateTime LabourDay => new DateTime(DateTime.Now.Year, 5, 1).Date;
public static DateTime Independence => new DateTime(DateTime.Now.Year, 7, 1).Date;
[ContentProperty(Name = nameof(LiteralContent))]
public sealed class AppBarLiteral : AppBarSeparator
{
public AppBarLiteral()
{
DefaultStyleKey = typeof(AppBarLiteral);
}
public object LiteralContent
{
static async Task<string> ScaleImageAsync(string path, uint height = 32, uint width = 32, StorageFile output_file = null)
{
// open file from path
var input_file = default(StorageFile);
try
{
input_file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(path));
}
catch (FileNotFoundException)
@JerryNixon
JerryNixon / app.xaml.cs
Created October 22, 2018 16:57
Preventing UWP Suspension
sealed partial class App : Application
{
public App()
{
InitializeComponent();
Suspending += (s, e) => Helpers.ShowToast("Suspending");
Resuming += (s, e) => Helpers.ShowToast("Resuming");
Helpers.SetupExSession(
allowed: () => Helpers.ShowToast("Allowed"),
denied: () => Helpers.ShowToast("Denied"),
internal class Program
{
private static void Main(string[] args)
{
Test("pass");
Test("password");
Test("Password");
Test("P@ssword");
Test("P@ssw0rd");
Test("P@ssW0rD");
@JerryNixon
JerryNixon / AuthenticationHelper.cs
Created July 25, 2017 21:48
Microsoft's Graph API SDK Helper
//Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
//See LICENSE in the project root for license information.
using System;
using System.Diagnostics;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Linq;
using System.Threading.Tasks;
using Windows.Security.Authentication.Web;