Skip to content

Instantly share code, notes, and snippets.

Avatar

Loïc Sharma loic-sharma

View GitHub Profile
@loic-sharma
loic-sharma / 1 - Ideal.cs
Last active Apr 4, 2021
The case for async dependency injection
View 1 - Ideal.cs
public class MyApp {
private IPackageDownloadClient _nuget;
public MyApp(IPackageDownloadClient nuget) {
_nuget = nuget;
}
public RunAsync() {
// This is the code I want to write.
// The NuGet package download client is injected into my application.
View MyApp.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
</ItemGroup>
View Program.cs
using System;
using System.IO;
using System.IO.Compression;
using System.Net.Http;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
@loic-sharma
loic-sharma / ConsoleApp17.csproj
Last active Jan 22, 2020
Get the download count for all versions of a package
View ConsoleApp17.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGet.Protocol" Version="5.5.0-preview.1.6319" />
@loic-sharma
loic-sharma / ConsoleApp17.csproj
Last active Jan 22, 2020
Get the download count for all versions of a package
View ConsoleApp17.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGet.Protocol" Version="5.5.0-preview.1.6319" />
</ItemGroup>
@loic-sharma
loic-sharma / Program.cs
Last active Sep 11, 2019
Improving NuGetVersion parse performance
View Program.cs
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
View RefreshNonCommunityPackageList.sql
BEGIN TRANSACTION;
IF NOT EXISTS (SELECT * FROM [dbo].[Dimension_PackageSet] WHERE [Name] = 'NonCommunityPackages')
BEGIN
INSERT INTO [dbo].[Dimension_PackageSet] (Name) VALUES ('NonCommunityPackages')
END
DECLARE @NonCommunityPackagesId int = (SELECT [Id] FROM [dbo].[Dimension_PackageSet] WHERE [Name] = 'NonCommunityPackages');
DELETE FROM [dbo].[Fact_Package_PackageSet]
View Program.cs
using Microsoft.Azure.Search;
using Microsoft.Azure.Storage;
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
namespace azs_clean
{
public class Program
@loic-sharma
loic-sharma / Program.cs
Last active Aug 3, 2018
Authenticating to a private BaGet feed using Azure Active Directory's Device Flow Authentication
View Program.cs
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
namespace DeviceFlow
{
class Program
@loic-sharma
loic-sharma / prepare.ps1
Last active Sep 11, 2018
Scripts to setup development VM
View prepare.ps1
# Requires:
# Set-ExecutionPolicy RemoteSigned -s CurrentUser
# Install apps
iex (New-Object Net.WebClient).DownloadString('https://get.scoop.sh')
scoop install git
scoop bucket add extras
scoop install vscode