Skip to content

Instantly share code, notes, and snippets.

@SQL-MisterMagoo
SQL-MisterMagoo / README-Hosted.md
Last active May 18, 2023 22:50
Compress Static Files in wwwroot (or anywhere) in Blazor WebAssembly

Compress Static Files in Blazor WebAssembly Hosted

This goes into your msbuild config (normally csproj) and runs before the Publish Task, before files are copied to the final destination.

<!-- 2022 @SQL-MisterMagoo containing some code from (c) .NET Foundation. All rights reserved. -->

<PropertyGroup Condition="'$(_BlazorWebAssemblySdkToolAssembly)'==''">
  <_SDKRoot>$(NetCoreRoot)sdk\$(NETCoreSDKVersion)\Sdks</_SDKRoot>
@okyrylchuk
okyrylchuk / Program.cs
Created January 19, 2022 23:18
Extensions GetEnumerator for foreach loops with Range type
foreach (int i in 3..5)
{
Console.WriteLine(i);
}
foreach (int i in ..3)
{
Console.WriteLine(i);
}
<div id="canvas"></div>
<style>
#canvas {
width: 500px;
height: 300px;
border: 5px solid black;
position: relative;
box-sizing: content-box;
}
@davidfowl
davidfowl / MinimalAPIs.md
Last active May 1, 2024 20:58
Minimal APIs at a glance
@dedale
dedale / Example of usage
Last active December 19, 2022 13:15
Custom MSBuild task with mutex
<!-- Replace -->
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="Restore"
Properties="$(PackageRestoreProperties)"
BuildInParallel="true" />
<!-- With -->
<Import Project="...\MSBuildWithMutex.proj" />
<!-- ... -->
<Target Name="Restore...Packages" DependsOnTargets="CompileMSBuildWithMutex">
@fernandezja
fernandezja / autofact-scanning-modules-into-assembly.txt
Last active February 20, 2020 21:33
Autofact assembly scanning modules and register with parameters (without RegisterAssemblyModules)
var moduleAssembly = Assembly.Load("Starwars.Modules.Empire");
//builder.RegisterAssemblyModules(moduleAssembly); //Not work with parameter, Not work inject DI
var modules = from t in moduleAssembly.GetTypes()
where typeof(Autofac.Module).IsAssignableFrom(t)
select t;
foreach (var module in modules.ToList())
{
@jotapardo
jotapardo / dbo.TRY_CAST.sql
Last active June 1, 2022 13:11
TRY_CAST Function for SQL Server 2008
DECLARE @strSQL NVARCHAR(1000)
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[TRY_CAST]'))
BEGIN
SET @strSQL = 'CREATE FUNCTION [dbo].[TRY_CAST] () RETURNS INT AS BEGIN RETURN 0 END'
EXEC sys.sp_executesql @strSQL
END
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
@maxigs7
maxigs7 / PartitionArray.js
Created April 22, 2015 14:48
Partir un array en varios a partir de una cantidad
var array = [1,2,3,4,5,6],
step = 4,
finalArray = [],
i, j;
for (i=0,j=array.length; i < j; i += step) {
finalArray.push(array.slice(i,i+step));
}
@maxigs7
maxigs7 / GenericRepository.cs
Created April 8, 2015 20:12
Generic Repository Pattern for Entity Framework
public class GenericRepository<TModel> : IGenericRepository<TModel> where TModel : class
{
#region Constructors
protected readonly IDbContext Context;
protected readonly DbSet<TModel> DbSet;
public GenericRepository(IDbContext context)
{
Context = context;
@maxigs7
maxigs7 / GenericBusiness.cs
Last active August 29, 2015 14:18
Business class and Interface for generic entities. Intermediate with Presentation Layer and Repository(DAL). Dependencies: https://gist.github.com/maxigs7/57795d8052010f0c8f25
public class GenericBusiness<TModel> : IGenericBusiness<TModel> where TModel : class
{
#region Properties
protected IGenericRepository<TModel> _genericRepository;
protected virtual IGenericRepository<TModel> GenericRepository
{
get { return _genericRepository ?? (_genericRepository = new GenericRepository<TModel>()); }
}