Skip to content

Instantly share code, notes, and snippets.

Cédric Luthi 0xced

Block or report user

Report or block 0xced

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@0xced
0xced / netcore single exe.md
Last active Aug 7, 2019
Building a .NET Core single exe for Linux on macOS or Windows
View netcore single exe.md

Building a .NET Core single exe for Linux on macOS or Windows

Run the .NET Core SDK docker image and share your working directory containing your .csproj file at /home in the container.

On Linux/macOS:

docker run --interactive --tty --rm --volume "$(pwd):/home" mcr.microsoft.com/dotnet/core/sdk:2.2 /bin/bash

On Windows:

@0xced
0xced / DisplayException.cs
Created May 1, 2019
Display exceptions with a TaskDialog or a MessageBox
View DisplayException.cs
// For setting up unhandled exceptions handlers: https://stackoverflow.com/questions/5762526/how-can-i-make-something-that-catches-all-unhandled-exceptions-in-a-winforms-a
// Using Ookii.Dialogs: https://www.nuget.org/packages?q=Ookii.Dialogs
static void DisplayException(Exception exception)
{
var baseException = exception.GetBaseException();
var title = @"Error: " + baseException.GetType().Name;
var message = baseException.Message;
if (TaskDialog.OSSupportsTaskDialogs)
{
using (var dialog = new TaskDialog())
@0xced
0xced / Working without a nib.md
Created Mar 7, 2019
Working without a nib blog posts by Jeff Johnson (@lapcatsoftware)
View Working without a nib.md
  • [Working without a nib, Part 1][1]
  • [Working without a nib, Part 2: Also Also Wik][2]
  • [Working without a nib, Part 5: No, 3!][3]
  • [Working without a nib, Part 4: setAppleMenu][4]
  • [Working without a nib, Part 5: Open Recent menu][5]
  • [Working without a nib, Part 6: Working without a xib][6]
  • [Working without a nib, Part 7: The empire strikes back][7]
  • [Working without a nib, Part 8: The nib awakens][8]
  • [Working without a nib, Part 9: Shipping without a nib][9]
  • [Working without a nib, Part 10: Mac Main Menu][10]
@0xced
0xced / NativeSQLiteWithCostura.csproj
Created Feb 27, 2019
Embed native e_sqlite3.dll with Costura without having to manually copy any dll
View NativeSQLiteWithCostura.csproj
<!-- Useful when bundling an app using Microsoft.EntityFrameworkCore.Sqlite, which depends on SQLitePCLRaw.bundle_green, which depends on SQLitePCLRaw.lib.e_sqlite3.v110_xp (having native Windows dlls) -->
<ItemGroup>
<EmbeddedResource Include="$(NugetPackageRoot)\sqlitepclraw.lib.e_sqlite3.v110_xp\1.1.13\runtimes\win-x86\native\e_sqlite3.dll">
<Link>costura32\e_sqlite3.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(NugetPackageRoot)\sqlitepclraw.lib.e_sqlite3.v110_xp\1.1.13\runtimes\win-x64\native\e_sqlite3.dll">
<Link>costura64\e_sqlite3.dll</Link>
</EmbeddedResource>
</ItemGroup>
@0xced
0xced / StringTrimmerInterceptor.cs
Created Nov 13, 2018
Entity Framework interceptor to trim strings (remove leading and trailing spaces) before saving to database
View StringTrimmerInterceptor.cs
using System.Data.Entity;
using System.Data.Entity.Core.Common.CommandTrees;
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure.Interception;
using System.Linq;
namespace gist
{
/// Adapted from https://stackoverflow.com/questions/20133696/how-can-i-configure-entity-framework-to-automatically-trim-values-retrieved-for/27504530#27504530
@0xced
0xced / DbContextExtensions.cs
Created Oct 2, 2018
Get invariant provider name from DbContext
View DbContextExtensions.cs
using System.Data.Entity;
using System.Reflection;
namespace gist
{
public static class DbContextExtensions
{
public static string GetProviderName(this DbContext context)
{
var internalContextProperty = context.GetType().GetProperty("InternalContext", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
@0xced
0xced / WindowsAuthorizationMiddleware.cs
Last active Oct 3, 2018
OWIN Middleware for authenticating + authorizing windows accounts (users or groups)
View WindowsAuthorizationMiddleware.cs
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.Owin;
// ReSharper disable once CheckNamespace
namespace Owin
{
public static class WindowsAuthorizationAppBuilderExtensions
@0xced
0xced / install_mono_workarounds.sh
Last active Jun 27, 2019
Workarounds for using System.Data.SQLite and Microsoft.Azure.Management.ServiceBus on Mono
View install_mono_workarounds.sh
#!/bin/bash -e -x
# For System.Data.SQLite to work on Mono, see https://stackoverflow.com/questions/21293105/system-dllnotfoundexception-on-mono-sqlite/43173220#43173220
function Install_libSQLiteInterop
{
# Latest version is on https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
SQLITE_VERSION=1.0.111.0
SQLITE_DYLIB=sqlite-netFx-source-${SQLITE_VERSION}/bin/2013/Release/bin/libSQLite.Interop.dylib
pushd ~/Downloads
@0xced
0xced / ForEachAsync.cs
Created May 26, 2018
Parallel foreach async enumeration with maximum degree of parallelism
View ForEachAsync.cs
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Parallel
{
public static class EnumerableExtensions
{
@0xced
0xced / DbEntityValidationException.cs
Last active Jun 8, 2018
Improved DbEntityValidationException message
View DbEntityValidationException.cs
public partial class MyContext
{
// Adapted from https://blogs.infosupport.com/improving-dbentityvalidationexception/
public override Task<int> SaveChangesAsync()
{
try
{
return base.SaveChangesAsync();
}
catch (DbEntityValidationException exception)
You can’t perform that action at this time.