Skip to content

Instantly share code, notes, and snippets.

View idiotandrobot's full-sized avatar

Michael Phillips idiotandrobot

View GitHub Profile
using Newtonsoft.Json;
public static async Task<Version> GetLatestVersion()
{
const string latestReleaseRequestUrl =
@"https://api.github.com/repos/{user}/{repo}/releases/latest";
try
{
string versionStr;
@idiotandrobot
idiotandrobot / Clear-NuGet-Cache.ps1
Last active December 22, 2018 16:53 — forked from thoemmi/Clear-NuGetCache.ps1
Script to delete old NuGet packages from the default global packages folder which haven't been accessed for 150 days
[CmdletBinding(SupportsShouldProcess=$True)]
Param(
[int]$CutoffDays = 150
)
$cutoffDate = (Get-Date).AddDays(-$CutoffDays)
# get path to cached NuGet packages
$nugetCachePath = .\Get-Nuget-Cache-Path.ps1
@idiotandrobot
idiotandrobot / dosomethingasync.cs
Last active July 21, 2018 08:13
async/await in Windows Runtime Components
public async Task DoSomethingAsync()
{
await SomethingElseAsync();
}
public async Task<Foo> DoAnotherAsync()
{
return await ReturnAFooAsync();
}
3D1W9MPQGSM8P,29C9ZTBRYZTRN,BT1GTNLE3DJW,1EAB07GESHF2W,2PF1IAYUTBODP,204W6ITX1MQF4
var result = List.Select((x, i) => new { Key = i, Value = x }).ToDictionary(x => x.Key, x => x.Value);
@idiotandrobot
idiotandrobot / appbarbutton.xaml
Created January 29, 2018 17:28
AppBarButton focus
<AppBarButton AllowFocusOnInteraction="True"/>
@idiotandrobot
idiotandrobot / masterdetailsview.xaml
Last active January 29, 2018 14:54
Stretch UWP MasterDetailsView ListViewItems to full width
<controls:MasterDetailsView>
<controls:MasterDetailsView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</controls:MasterDetailsView.ItemContainerStyle>
</controls:MasterDetailsView>
@idiotandrobot
idiotandrobot / textbox.xaml
Created January 29, 2018 12:42
UWP multi-line TextBox
<TextBox AcceptsReturn="True" TextWrapping="Wrap"
ScrollViewer.VerticalScrollBarVisibility="Auto"/>
@idiotandrobot
idiotandrobot / HasAdministratorPrivileges.cs
Created January 25, 2018 09:01
Mark .NET application to run as Administrator
private static bool HasAdministratorPrivileges()
{
WindowsIdentity id = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(id);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
@idiotandrobot
idiotandrobot / ComboBox.xaml
Last active January 23, 2018 11:22
Localized UWP ComboBox example
<ComboBox DisplayMemberPath="Content"
SelectedIndex="{x:Bind Status, Mode=TwoWay}">
<ComboBoxItem x:Uid="ProjectStatus_Completed" />
<ComboBoxItem x:Uid="ProjectStatus_Active" />
<ComboBoxItem x:Uid="ProjectStatus_Archived" />
</ComboBox>