Skip to content

Instantly share code, notes, and snippets.

@meziantou
meziantou / Index.html
Last active April 7, 2024 14:02
Javascript - Record audio
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>Audio</h1>
@meziantou
meziantou / CredentialManager.cs
Last active March 12, 2024 02:35
Using the Windows Credential API (CredRead, CredWrite, CredDelete, CredEnumerate).
// The most up to date version is available
// on GitHub: https://github.com/meziantou/Meziantou.Framework/tree/master/src/Meziantou.Framework.Win32.CredentialManager
// NuGet package: https://www.nuget.org/packages/Meziantou.Framework.Win32.CredentialManager/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32.SafeHandles;
@meziantou
meziantou / CustomAuthorizeAttribute.cs
Last active October 31, 2023 08:37
Custom `AuthorizeAttribute` that allows boolean operators such as AND, OR, XOR, NOT
/// <summary>
/// [CustomAuthorize(Roles = "A && (!B || C) ^ D")]
/// </summary>
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
/*
* Exp -> SubExp '&&' Exp // AND
* Exp -> SubExp '||' Exp // OR
* Exp -> SubExp '^' Exp // XOR
* SubExp -> '(' Exp ')'
@meziantou
meziantou / ObjectDataReader.cs
Created February 1, 2017 00:28
ObjectDataReader (BulkInsert)
public class ObjectDataReader<T> : DbDataReader
{
private IEnumerator<T> _iterator;
private IDictionary<string, int> _propertyNameToOrdinal = new Dictionary<string, int>();
private IDictionary<int, string> _ordinalToPropertyName = new Dictionary<int, string>();
private Func<T, object>[] _getPropertyValueFuncs;
public ObjectDataReader(IEnumerator<T> items)
{
_iterator = items ?? throw new ArgumentNullException(nameof(items));
@meziantou
meziantou / WebFormsBootstrapValidation.aspx
Last active May 27, 2023 11:29
ASP.NET WebForms Validators & Bootstrap
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ASP.NET WebForms Validators & Bootstrap</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css" />
@meziantou
meziantou / DumpSourceFilesFromPortablePdb.cs
Last active September 23, 2022 08:34
Dump source files from a portable pdb
// Convert full pdb to portable pdb: https://github.com/dotnet/symreader-converter#pdb2pdb
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Reflection.Metadata;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
<HttpRequestLoggerComponent />
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
@meziantou
meziantou / SingleInstance.cs
Last active May 22, 2022 13:41
SingleInstance
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using System.Threading;
namespace SingleInstance
{
class Program
{
@meziantou
meziantou / fileupload.ts
Created February 26, 2017 22:03
FileUpload (drag and drop files and directories, paste)
improveFileUpload();
function improveFileUpload() {
const input = document.getElementById("FileUpload");
if (!input) {
console.warn("input not found.");
return;
}
if (!(input instanceof HTMLInputElement)) {