Skip to content

Instantly share code, notes, and snippets.

View bcachet's full-sized avatar

Bertrand Cachet bcachet

  • Neuchatel; Switzerland
View GitHub Profile
namespace Units
type MeasureType =
| BaseUnit of string
| Multiple of Measure * ValueType
with
member this.BaseUnitName =
let rec traverse = function
| BaseUnit s -> s
| Multiple(Measure(_,m),_) -> traverse m
#load "Tree.fs"
open Tree
open System
open System.IO
type FileSystemTree = Tree<IO.FileInfo,IO.DirectoryInfo>
let fromFile (fileInfo:FileInfo) =
LeafNode fileInfo

Keybase proof

I hereby claim:

  • I am bcachet on github.
  • I am bcachet (https://keybase.io/bcachet) on keybase.
  • I have a public key ASDPUpFyYKrP5isTfO0tpoTQoxeRxPm9R0AHt_kIe638Ywo

To claim this, I am signing this object:

@bcachet
bcachet / graph.fs
Last active August 11, 2017 21:00
Kahn sorting in F#
namespace Graph
// Implementation based on https://gist.github.com/alandipert/1263783
module Map =
let keys map =
map |> Map.toSeq |> Seq.map fst |> Set.ofSeq
let values map =
map |> Map.toSeq |> Seq.map snd |> Set.ofSeq
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
static class VariableHeightItems
{
[DllImport("user32")]
static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wp, IntPtr lp);
[StructLayout(LayoutKind.Sequential)]
@bcachet
bcachet / utf-16_encoder.cpp
Last active November 2, 2021 08:05
Convert string to wstring to write to file with utf-16 encoding
// Windows version
#include <string>
#include <iostream>
#include <fstream>
#include <locale>
#include <codecvt>
#include <Windows.h>
std::wstring decode(const std::string &str, int codePage = GetACP())
{
public static readonly Parser<char> Dot = CharP('.');
public static Parser<char> Sign = Sat(c => "+-".Contains(c));
public static Parser<char> Exponent = Sat(c => "Ee".Contains(c));
public static Parser<double> RealNumber() {
return
from integer in Natural
from fractional in (from dot in Dot
from digit in Natural
@bcachet
bcachet / DisplayDShowCameraPropertiesPanel.cpp
Last active March 2, 2016 13:55
MFC application to connect to DirectShow's camera and display properties panel
#include "stdafx.h"
#include <atlstr.h>
#include <dshow.h>
//#include <afxwin.h>
#include <string>
using namespace std;
#define CHECK(err)\
@bcachet
bcachet / splitpatch.rb
Created November 9, 2011 15:03
Script to split a unified patch file into several ones
#!/usr/bin/env ruby
#
# splitpatch is a simple script to split a patch up into multiple patch files.
# if the --hunks option is provided on the command line, each hunk gets its
# own patchfile.
#
# Copyright (C) 2007, Peter Hutterer <peter@cs.unisa.edu.au>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
#!/usr/bin/env python
def convert_base(value, base_k, base_n):
"""
Convert value from base K to base N
>>> convert_base('5', BASE10, BASE2)
101
>>> convert_base('10', BASE10, BASE2)
1010
>>> convert_base('33', BASE4, BASE8)