Skip to content

Instantly share code, notes, and snippets.

View floko84's full-sized avatar

Florian Kollmann floko84

View GitHub Profile
@floko84
floko84 / angular-form-init.js
Last active November 7, 2023 14:37
AngularJs initialize scope from pre-existing html form values. Usage: <input ng-model="my.model" form-init-model value="foo" /> or <input form-init="my.model" value="foo" />
/*
AngularJs initialize scope from pre-existing html form values by Florian Kollmann <floko84@gmail.com>
*/
; angular.module('formInit', [])
.directive('formInit', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var value = element.val();
if (value) {
@floko84
floko84 / VirtualPathHelper.cs
Created January 6, 2022 23:27
Reverse of HttpServerUtility.MapPath or HostingEnvironment.MapPath, maps a physical path to an absolute virtual path.
using System;
using System.Web;
using System.Web.Hosting;
public static class VirtualPathHelper
{
/// <summary>
/// Returns the virtual path that corresponds to the specified physical file path.
/// </summary>
/// <param name="path"></param>
@floko84
floko84 / ScreenCapture.cs
Created July 27, 2021 21:37
Capture a screenshot of the entire desktop in C#
using System;
using System.Drawing;
using System.Windows.Forms;
public static class ScreenCapture
{
/// <summary>
/// Creates an <see cref="Image"/> object containing a screen shot of the entire desktop.
/// </summary>
/// <returns></returns>
@floko84
floko84 / FreeImageLoader.cs
Last active February 3, 2020 14:12
FreeImage.NET library loader for AnyCPU projects. Attempts to load the platform specific 32-bit/64-bit FreeImage.dll from x86 or x64 subfolders. Compile with https://sourceforge.net/p/freeimage/svn/HEAD/tree/FreeImage/trunk/Wrapper/FreeImage.NET/cs/Library/
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace FreeImageAPI
{
public static partial class FreeImage
{
private static readonly bool is64BitProcess = (IntPtr.Size == 8);
@floko84
floko84 / MutexLock.cs
Last active April 1, 2020 20:09
C# async safe IDisposable System.Threading.Mutex wrapper.
using System;
using System.Threading;
/// <summary>
/// Thread safe disposable exclusive lock, uses <see cref="Mutex"/>.
/// </summary>
public class MutexLock : IDisposable
{
private volatile ManualResetEventSlim releaseMutexEvent;
@floko84
floko84 / DisabledItem.cs
Last active November 7, 2023 14:39
Parse Microsoft Office DisabledItems from Registry $"HKCU\Software\Microsoft\Office\{version}\{appName}\Resiliency\DisabledItems" in C#.
using System;
using System.IO;
using System.Linq;
using System.Text;
/// <summary>
/// Structure of an Microsoft Office disabled item entry.
/// </summary>
public readonly struct DisabledItem
{
@floko84
floko84 / PasswordCryptoServiceProvider.cs
Created April 28, 2018 12:25
C# password-based encryption helper class.
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
public class PasswordCryptoServiceProvider : IDisposable
{
protected const string Base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
private readonly SymmetricAlgorithm algorithm;
@floko84
floko84 / jquery.preventDoubleSubmit.js
Last active November 28, 2018 09:33
jQuery plugin to prevent multiple HTML form submits. With support for custom validator logic, custom submit action, as well as a timeout to re-enable submits. Submit buttons are disabled for UI feedback.
/*
jQuery Prevent Double Submit Plugin by Florian Kollmann <floko84@gmail.com>
*/
; (function ($) {
"use strict";
var pluginName = "preventDoubleSubmit",
defaults = {
valid: function () {
// run jQuery validate if available
return !$.isFunction($.fn.valid) || $(this).valid();
@floko84
floko84 / SlidingTimer.cs
Last active February 24, 2017 22:52
Simple and transparent sliding timer implementation using MemoryCache, available in .NET 4+.
using System;
using System.Runtime.Caching;
public class SlidingTimer
{
public EventHandler TimeoutElapsed;
private readonly ObjectCache cache;
private readonly CacheItemPolicy cacheItemPolicy;
private readonly string cacheKey;
@floko84
floko84 / ConfigurationElementCollection.cs
Created December 1, 2015 13:56
Generic implementation of the System.Configuration.ConfigurationElementCollection
using System.Collections.Generic;
using System.Configuration;
public abstract class ConfigurationElementCollection<T> : ConfigurationElementCollection, IList<T> where T : ConfigurationElement
{
public new bool IsReadOnly
{
get { return base.IsReadOnly(); }
}