Skip to content

Instantly share code, notes, and snippets.

View UweKeim's full-sized avatar
😊
www.uwe.co

Uwe Keim UweKeim

😊
www.uwe.co
View GitHub Profile
@UweKeim
UweKeim / Impersonator.cs
Last active March 22, 2024 12:21
Impersonation in .NET
namespace Tools;
using Microsoft.Win32.SafeHandles;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security.Principal;
/// <summary>
/// Impersonation of a user. Allows to execute code under another
/// user context.
@UweKeim
UweKeim / NetworkConnection.cs
Created March 22, 2024 12:20
NET USE in .NET C#
namespace Tools;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
/// <summary>
/// Wrapper for the "NET USE" functionality.
/// Connect to a network resource, e.g. a network share under a different user.
/// </summary>
@UweKeim
UweKeim / FileSize.cs
Created October 27, 2020 07:45
Automatically formatting an integer for human-readable file size
namespace Extensions
{
using System;
using System.Globalization;
using System.Threading;
public static class FileSizeExtensions
{
public static string FormatFileSize(
this long fileSize,
@UweKeim
UweKeim / BlazorTimer.cs
Last active January 28, 2024 21:30
Timer in Blazor 3.1
namespace ZetaHelpdesk.MainBlazor.Code.Components
{
using System;
using System.Timers;
// https://wellsb.com/csharp/aspnet/blazor-timer-navigate-programmatically/
public sealed class BlazorTimer
{
private Timer _timer;
namespace ZetaProducer.RuntimeGui.ExtendedWebBrowser
{
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Zeta.VoyagerLibrary.Common.IO;
@UweKeim
UweKeim / ZetaFolderXCopy.cs
Last active January 28, 2024 21:32
XCOPY-like functionality to copy files and folders in C#, ideal for batch scripts
//css_nuget -force:3600 -ng:"-Source https://nuget.org/api/v2/" ZetaLongPaths
using ZetaLongPaths;
namespace Zeta
{
/*
===========================
Zeta XCOPY.
@UweKeim
UweKeim / program.cs
Last active August 7, 2019 10:11
A simple .NET version of SQLCMD for executing an SQL Script against Microsoft SQL Server
namespace uksqlcmd
{
using System;
using System.Data.SqlClient;
using System.IO;
using System.Text;
internal static class Program
{
private static int Main(string[] args)
@UweKeim
UweKeim / program.cs
Last active August 7, 2019 07:04
Convert Oracle "RR" date formats to SQL Server "YYYY" formats
namespace OracleRRConverter
{
// Takes an Oracle-generated SQL script file and converts something like
// to_date('02.10.18','DD.MM.RR') to something like CONVERT(DATETIME,'02.10.2018',126).
// https://dba.stackexchange.com/q/244722/42
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@UweKeim
UweKeim / ColorConverting.cs
Last active January 28, 2024 21:27
HSL color, HSB color and RGB color types, as well as conversion methods between them in C# and .NET
namespace ZetaColorEditor.Colors
{
using System;
using System.Drawing;
/// <summary>
/// Provides color conversion functionality.
/// </summary>
/// <remarks>
/// http://en.wikipedia.org/wiki/HSV_color_space
@UweKeim
UweKeim / wsdl.cs
Created January 15, 2019 11:10
wsdl.cs für cs-script
//css_import credentials;
using System;
using System.Net;
using System.Reflection;
using System.Diagnostics;
using System.Windows.Forms;
using System.Text;
using System.IO;
using CSScriptLibrary;
using csscript;