Skip to content

Instantly share code, notes, and snippets.

View conficient's full-sized avatar
🤓
Loving BLAZOR!

Howard Richards conficient

🤓
Loving BLAZOR!
View GitHub Profile
@conficient
conficient / Gravatar.razor
Last active June 10, 2022 11:47
A Razor component that displays a Gravatar image for a user's email address
@* Creates a Gravatar image using Bootstrap styling from email address *@
<img class="rounded-circle" src="@url" />
@code
{
[Parameter] public string Email { get; set; }
[Parameter] public int Size { get; set; } = 24;
protected override void OnParametersSet()
{
// create hash
@conficient
conficient / bUnit.razor
Last active March 1, 2022 18:00
bUnit Quick Reference
@* need to change project SDK *@
<Project Sdk="Microsoft.NET.Sdk.Razor">
@* add bUnit package *@
<PackageReference Include="bunit" Verion="x.x.x" />
@* Use a `@code` block in a `.razor` test file, e.g. *@
@* if the test component inherits from `TestContext ` you don't need the `new TestContext();` bit
@code {
@conficient
conficient / ICalendarSimple.razor
Created October 27, 2021 18:48
A simple ICalendar with no requirement for external libraries
@if(IsValid)
{
<a href=@dataUrl download=@Filename >@ChildContent</a>
}
@code
{
[Parameter] public DateTime? Start { get; set; }
[Parameter] public DateTime? End { get; set; }
@conficient
conficient / ICalendar.razor
Last active October 27, 2021 15:32
ICalendar link generator
@using Ical.Net
@using Ical.Net.Serialization
@* requires Ical.Net library from NUGET *@
@if(Calendar != null)
{
<a href=@dataUrl download=@Filename >@ChildContent</a>
}
@code
{
[Parameter] public Calendar Calendar { get; set; }
@conficient
conficient / NotNull.razor
Created June 24, 2021 14:24
NotNull.razor
@if (Value != null)
{
@ChildContent
}
@code
{
/* sample usage
* <NotNull Value="yourValue">
* // use value
* </NotNull>
@conficient
conficient / Counter.razor
Last active June 22, 2021 08:02
Shared counter sample
@page "/counter"
@inject CounterService counterService
@implements IDisposable
<h1>Counter</h1>
<p>Current count: @counterService.Count</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@conficient
conficient / NugetManager.cs
Created November 20, 2020 10:22 — forked from cpyfferoen/NugetManager.cs
NuGet API wrapper to search/install packages WITH AUTHENTICATION the same way Nuget.Exe/Client does it - looks up CredentialProviders and plugins (also for Credentials). Specific use case was Azure DevOps feed access.
using NuGet.Common;
using NuGet.Configuration;
using NuGet.Credentials;
using NuGet.PackageManagement;
using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.Packaging.Signing;
using NuGet.ProjectManagement;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
@conficient
conficient / Loading.razor
Created September 1, 2020 15:26
Loading content control for Razor
/* shows a loading gif/text if a value is null */
@if (Value == null)
{
<div><img src="/img/SmallLoader.gif" alt="loading" /> Loading</div>
}
else
{
@ChildContent
}
@code {
@conficient
conficient / Test.cs
Last active August 6, 2020 16:38
IEnumerable does not protect your list..
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
namespace Tests
{
[TestClass]
public class Test
{
[TestMethod]
@conficient
conficient / GreyOutZone.razor
Created July 30, 2020 17:23
Blazor - GreyOutZone - adapted from FlightFinder but with embedded styles so works stand-alone
@* creates a container component that greys-out the content when the `IsGreyedOut` parameter is set to true *@
<div style="@(IsGreyedOut ? greyout : null)">
<div style="@cover"></div>
@ChildContent
</div>
@code {
const string greyout = "position: absolute; width: 100%; min-height: 100%;";
const string cover = "background: rgba(150, 150, 150, 0.5); position: absolute; width: 100%; height: 100%; z-index: 1;";