Skip to content

Instantly share code, notes, and snippets.

@AndrewNewcomb
AndrewNewcomb / Nullify.ps1
Created December 9, 2018 11:01
Powershell script that given a json file creates files with each file having a different property or element set to null.
#
# Given a json file creates files with each file having a different property or element set to null.
# Useage:
# Nullify -sourceFile "C:\afolder\afile.json" -targetPath "C:\anotherfolder"
#
Function Nullify {
Param(
[Parameter(Mandatory=$true, HelpMessage="The source file.")][string]$sourceFile, `
[Parameter(Mandatory=$true, HelpMessage="The target path to write the output files to.")][string]$targetPath )
@AndrewNewcomb
AndrewNewcomb / BiggestPuddleOnePass.fsx
Last active August 29, 2015 14:19
FSharp solution to the biggest puddle problem
// F# solution to the biggest puddle problem posed at
// http://geekswithblogs.net/BlackRabbitCoder/archive/2015/04/07/little-puzzlersndashlargest-puddle-on-a-bar-chart.aspx
// April 2015
// This solution works in one pass of the array
open System
let heights = [|10; 20; 80; 70; 60; 90; 40; 30; 40; 70|]
//let heights = [|10; 5; 10; 4; 5; 10|]
//let heights = [|0; 20; 80; 70; 60; 90; 40; 30; 40; 70|]
@AndrewNewcomb
AndrewNewcomb / BiggestPuddleMultiplePasses.fsx
Last active August 29, 2015 14:19
FSharp solution to the biggest puddle problem
// F# solution to the biggest puddle problem posed at
// http://geekswithblogs.net/BlackRabbitCoder/archive/2015/04/07/little-puzzlersndashlargest-puddle-on-a-bar-chart.aspx
// April 2015
// this version will use three passes
open System
let heights = [|10; 20; 80; 70; 60; 90; 40; 30; 40; 70|]
type state1 = {Height:int; MaxLeft:int}
@AndrewNewcomb
AndrewNewcomb / AboutTheStockExample.fs
Last active November 29, 2019 17:41
Solutions to the F# Koan for AboutTheStockExample
namespace FSharpKoans
open FSharpKoans.Core
//---------------------------------------------------------------
// Apply Your Knowledge!
//
// Below is a list containing comma separated data about
// Microsoft's stock prices during March of 2012. Without
// modifying the list, programatically find the day with the
// greatest variance between the opening and closing price.
@AndrewNewcomb
AndrewNewcomb / MiniProfilerTraceListener.cs
Created April 6, 2013 08:27
MiniProfilerTraceListener is a custom TraceListener that sends all messages to the StackExchange MiniProfiler.
using System.Diagnostics;
using StackExchange.Profiling;
namespace PSL.Web.Infrastructure
{
//Needs web.config entry
//<add name="TraceToMiniProfiler" type="PSL.Web.Infrastructure.MiniProfilerTraceListener, theassemblyname" initializeData="" />
public class MiniProfilerTraceListener : TraceListener
{
@AndrewNewcomb
AndrewNewcomb / WebSocketServer.fs
Last active January 9, 2017 18:58
OLD from 2010 ... Updated example of using F# MailboxProcessor against an HTML5 WebSocket (in Google Chrome)
// Example of using F# MailboxProcessor against an HTML5 WebSocket (in Google Chrome)
// taken from http://v2matveev.blogspot.com/2010/04/mailboxprocessors-practical-application.html
// and then modified to work with the revised WebSocket protocol that includes a set of challenge bytes.
// The main changes are in the handshake function.
// Have a look at the http://nugget.codeplex.com for example WebSocket code in C#, on which I based the
// challenge processing code.
open System
open System.IO
open System.Linq