Skip to content

Instantly share code, notes, and snippets.

View otuncelli's full-sized avatar
🎯
Focusing

Osman Tunçelli otuncelli

🎯
Focusing
View GitHub Profile
@otuncelli
otuncelli / UTF8StringMarshaler.cs
Created September 7, 2023 04:33
UTF8 string marshaler
#if !NETSTANDARD2_1_OR_GREATER
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace resvg.net
{
public sealed class UTF8Marshaler : ICustomMarshaler
{
public static readonly UTF8Marshaler Instance = new UTF8Marshaler();
@otuncelli
otuncelli / LazyRegex.cs
Created October 4, 2021 19:38
Regex object that initialized and parsed when needed.
using System;
using System.Text.RegularExpressions;
namespace Tools
{
public class LazyRegex
{
private readonly Lazy<Regex> regex;
private Regex Re => regex.Value;
@otuncelli
otuncelli / GetFileSizeLocal.nsh
Created September 8, 2021 20:06
GetFileSizeLocal NSIS Installer Macro
!macro GetFileSizeLocal file defbase
!verbose push
!verbose 2
!tempfile GetFileSizeLocal_nsi
!tempfile GetFileSizeLocal_exe
!appendfile "${GetFileSizeLocal_nsi}" 'SilentInstall silent$\nRequestExecutionLevel user$\nOutFile "${GetFileSizeLocal_exe}"$\nPage instfiles$\nSection'
!appendfile "${GetFileSizeLocal_nsi}" '$\nFileOpen $0 "${GetFileSizeLocal_nsi}" w$\nFileOpen $1 "${file}" r$\nFileSeek $1 0 END $R0$\nFileClose $1'
!appendfile "${GetFileSizeLocal_nsi}" '$\nFileWrite $0 "!define ${defbase} $R0"$\nFileClose $0$\nSectionEnd'
!system '"${NSISDIR}\makensis" /V2 "${GetFileSizeLocal_nsi}"' = 0
!system '"${GetFileSizeLocal_exe}"' = 0
@otuncelli
otuncelli / FileAssociation.cs
Created August 24, 2017 00:06
Windows File Extension Association Helper Class
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace DiskCatalog.Classes
{
public sealed class FileAssociation
{
public string Extension { get; }
@otuncelli
otuncelli / SingleAssemblyResourceManager.cs
Last active May 10, 2017 00:44
ResourceManager for Single Assembly (Including localization resources) (for use with ILRepack or ILMerge)
public class SingleAssemblyResourceManager : ResourceManager
{
private readonly Type _resourceSource;
private CultureInfo _neutralResourcesCulture;
private readonly Dictionary<string, ResourceSet> _resourceSets;
private readonly string[] _resourceNames;
private SingleAssemblyResourceManager(Type resourceSource) :
base(resourceSource)
{
@otuncelli
otuncelli / MessageBoxEx.cs
Last active April 3, 2024 08:30
Parent centered MessageBox dialog in C#
using System.Drawing;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading.Tasks;
namespace System.Windows.Forms
{
using Point = Drawing.Point;
/// <summary>
using System;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
namespace HenriFormatter
{
public static class HenriFormatter
{
@otuncelli
otuncelli / BiDictionary.cs
Created January 6, 2016 15:14
Bi-directional Dictionary Implementation
using System;
using System.Collections;
using System.Collections.Generic;
namespace BiDictionary
{
public sealed class BiDictionary<T1, T2> : IEnumerable<KeyValuePair<T1, T2>>
{
readonly Dictionary<T1, T2> first;
readonly Dictionary<T2, T1> second;
@otuncelli
otuncelli / StringMultiReplace.cs
Last active April 19, 2020 15:09
Replace multiple strings in single pass (based on regular expressions)
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace MultiReplace
{
public sealed class StringMultiReplace
{
#region Private Members