Skip to content

Instantly share code, notes, and snippets.

David Grenier davidgrenier

Block or report user

Report or block davidgrenier

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ElemsRep.fsx
type Meta = interface end
type U<'ty>() =
class
interface Meta
end
type K<'ty, 'x>(elem: 'x) =
interface Meta
member x.Elem = elem
View Remapper.fs
open System.Net
open System.Diagnostics
let netsh arguments =
ProcessStartInfo("netsh", arguments, WindowStyle = ProcessWindowStyle.Hidden)
|> Process.Start
let rec loop source dest =
async {
use _ = netsh "interface portproxy reset"
View await.fsx
let await (timeout: int) task =
async {
let evt = Event<_>()
let! _ =
async {
do! Async.Sleep timeout
evt.Trigger None
} |> Async.StartChild
let! _ =
View HopacLimitr.fsx
#I @"C:\Projects\Lib"
#r "Hopac.dll"
#r "Hopac.Core.dll"
open System
open Hopac
open Hopac.Job.Infixes
open Hopac.Alt.Infixes
open Hopac.Extensions
@davidgrenier
davidgrenier / NTBreakpoint.js
Created Sep 16, 2014
Conditional Breakpoint for javascript
View NTBreakpoint.js
var objUserInfo = new ActiveXObject("WScript.network");
if (objUserInfo.UserName == "dgrenier")
debugger;
View NessosReallyFast.fsx
#r @"C:\Projects\Streams\src\Streams.Core\bin\Release\Streams.Core.dll"
open Nessos.Streams.Core
let data =
[|
let rnd = System.Random().NextDouble >> (*) 1e3
for x in -10.0 .. 10.0 do
yield System.DateTime.Now.AddDays (rnd())
|]
View helper.fs
type T = T with
static member (<@>) (x, y: int) = x * y
static member (<@>) (x, y: float) = x * int y
let inline helper (_: ^o) (left: ^t) (right: ^u) = ((^o or ^t): (static member (<@>): ^t * ^u -> int) (left, right))
let inline (<@>) left right = helper T left right
1 <@> 2
1 <@> 2.3
View guid.fs
[<Inline "$v.toString(16)">]
let toHex (v: int) = X<_>
let guid() =
let rx = EcmaScript.RegExp("[xy]", "g")
EcmaScript.String("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx").Replace(rx, As (fun c ->
let r = EcmaScript.Math.Random() * 16.0 |> int
let v =
View RandomConvolution.fs
#if INTERACTIVE
let (++) a b = System.IO.Path.Combine(a, b)
let source = __SOURCE_DIRECTORY__ ++ __SOURCE_FILE__
let args = sprintf "--platform:x86 %s -o:%s" source <| source.Replace("fs", "exe")
System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.BaseDirectory ++ "fsc", args)
#endif
let time f x =
let ts = System.Diagnostics.Stopwatch.StartNew()
let result = f x
View NumberOfCores.fsx
#r "System.Management"
open System.Management
do
use ma = new ManagementObjectSearcher("Select * from Win32_Processor")
for item in ma.Get() do
try
printfn "%A" item.["NumberOfCores"]
with _ -> ()
You can’t perform that action at this time.