Skip to content

Instantly share code, notes, and snippets.

View nbevans's full-sized avatar
💭
Cutting code

Nathan Evans nbevans

💭
Cutting code
  • Housing Insight Ltd
  • London
View GitHub Profile
@nbevans
nbevans / Owin.Sitelets.fs
Last active November 25, 2019 11:58
Fixes MIME parsing on WebSharper OWIN middleware. Also implements request entity body limit to 20MB to prevent rogue request entity bodies. Also fixes other perf/robustness issues. Request entity bodies are streamed to file system temp file to avoid holding in memory. Search in code for "FIXUP" to find relevant edited areas. Requires reference t…
namespace WebSharper.Owin
// FIXUP NOTICE: CONTAINS CRITICAL BUGFIX FIXUP ON LINE 230. MORE INFO IS THERE.
open System
open System.Collections.Generic
open System.Collections.Concurrent
open System.IO
open System.Configuration
open System.Security.Principal
// Fixes broken ListView header heights on iOS
public sealed class ListViewRendererHackfix_AutomaticHeaderHeights_20190418 : ListViewRenderer {
private static readonly FieldInfo fieldInfo_ListViewRenderer_dataSource = typeof(ListViewRenderer).GetField("_dataSource", BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly Type type_ListViewRenderer_ListViewDataSource = typeof(ListViewRenderer).GetNestedType("ListViewDataSource", BindingFlags.NonPublic);
private static readonly Type type_ListViewRenderer_UnevenListViewDataSource = typeof(ListViewRenderer).GetNestedType("UnevenListViewDataSource", BindingFlags.NonPublic);
private static readonly ConstructorInfo ctorInfo_ListViewRenderer_ListViewDataSource = type_ListViewRenderer_ListViewDataSource.GetConstructor(new[] { fieldInfo_ListViewRenderer_dataSource.FieldType });
private static readonly ConstructorInfo ctorInfo_ListViewRenderer_UnevenListViewDataSource = type_ListViewRenderer_UnevenListView
@nbevans
nbevans / Pre-build event in VS project (ensure the script is in your project's root folder)
Last active August 29, 2015 14:27
Temporary productivity workaround for Xamarin bug #31423
pushd $(ProjectDir)
fsi kill-locked-handles.fsx
popd
@nbevans
nbevans / gist:e7d6356624ea0d85aff8
Created November 21, 2014 10:21
Simple F# wrapper around the "triggers" functionality of Quartz.NET
/// Provides a simple scheduler service for time and calendar oriented events.
module Singapore.Scheduler
open System
open Quartz
open Quartz.Impl
let private schedulerFactory = StdSchedulerFactory()
let private scheduler = schedulerFactory.GetScheduler()
/// Initializes the scheduler agent.
@nbevans
nbevans / gist:db695ad5e1ad02126b2e
Created November 17, 2014 05:15
LzmaDecodeStream that actually works in a: streaming / chunked / blocked fashion.
/* This file is part of SevenZipSharp.
SevenZipSharp is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SevenZipSharp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@nbevans
nbevans / gist:9519088
Last active February 25, 2020 23:43
PBKDF2 password hash function for F#
// Author: Nathan B. Evans
// Twitter: @nbevans
// Blog: http://nbevans.wordpress.com/2014/03/13/pbkdf2-hash-function-for-fsharp/
// License: MIT
module Crypto.Pbkdf2
open System
open System.Security.Cryptography
let private subkeyLength = 32
@nbevans
nbevans / gist:9429542
Last active August 29, 2015 13:57
Split a F# sequence (Seq) into chunks
// Author: Nathan B. Evans
// Twitter: @nbevans
// Blog: https://nbevans.wordpress.com/2014/03/13/really-simple-way-to-split-a-f-sequence-into-chunks-partitions/
// License: MIT
/// Returns a sequence that yields chunks of length n.
/// Each chunk is returned as an array.
let toChunks n (s:seq<'t>) = seq {
let pos = ref 0
let buffer = Array.zeroCreate<'t> n
@nbevans
nbevans / gist:6279980
Created August 20, 2013 10:53
PBKDF2 functions for secure password storage, and supports custom iterations (defaults to a OWASP 2013 recommendation of 100,000). Created from decompiling the System.Web.Helpers.Crypto class.
using System;
using System.Security.Cryptography;
namespace Nbevans.Cryptography {
public static class Pbkdf2 {
private const int Pbkdf2SubkeyLength = 32;
private const int SaltSize = 16;
private static bool ByteArraysEqual(byte[] a, byte[] b) {
if (ReferenceEquals(a, b)) return true;
@nbevans
nbevans / gist:4737222
Created February 8, 2013 07:10
Idea for CorrugatedIron's Links API
internal static class RiakObjectExtensions {
/// <summary>
/// Creates (or updates) a link to point to the designated object.
/// </summary>
/// <param name="ro">The Riak object whose link will be created or updated.</param>
/// <param name="riakObjectId">The Riak object identifier to be linked to.</param>
/// <param name="tag">The tag (or name) of the link.</param>
public static void SingleLinkTo(this RiakObject ro, RiakObjectId riakObjectId, string tag) {
SingleLinkTo(ro, riakObjectId.Bucket, riakObjectId.Key, tag);