Skip to content

Instantly share code, notes, and snippets.

View bjartwolf's full-sized avatar

Bjørn Einar Bjartnes bjartwolf

View GitHub Profile
@bjartwolf
bjartwolf / 2.5.4.fs
Created April 21, 2014 19:14
2.5.4.fs
let VolumeA0IsPyramid ((h:decimal<m>), (b:decimal<m>)) =
RoundM3(V h 0m<m> b) = RoundM3( b * b * h / 3m )
Check.Quick (Prop.forAll twoDecimals VolumeA0IsPyramid)
@bjartwolf
bjartwolf / streamingowinstuff.cs
Last active August 29, 2015 14:00
streaming
using System;
using System.IO;
using System.Text;
namespace AllCapsMiddleware
{
class CapsStream: Stream
{
private readonly Stream _stream;
private readonly Decoder _decoder;
@bjartwolf
bjartwolf / capsstreams.cs
Last active August 29, 2015 14:00
streams to make caps
using System;
using System.IO;
using System.Text;
namespace HelloWorldMiddleWare2
{
class CapsStream: Stream
{
private Stream _stream;
@bjartwolf
bjartwolf / allCapsMiddleware.cs
Last active August 29, 2015 14:00
all caps middleware
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Owin;
namespace AllCapsMiddleware
{
using AppFunc = Func<IDictionary<string,object>, Task>;
public class AllCaps
{
public class Startup
{
public void Configuration(IAppBuilder appBuilder)
{
HttpConfiguration config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
appBuilder.Use<AllCapsMiddleware.AllCaps>();
appBuilder.UseWebApi(config);
}
}
@bjartwolf
bjartwolf / contentnegotiation.cs
Created May 1, 2014 18:28
contentnegotiation
public async Task Invoke(IDictionary<string, object> env)
{
var ctx = new OwinContext(env);
var accepts = ctx.Request.Accept;
if (accepts != null && accepts == accepts.ToUpper())
{
ctx.Response.Body = new CapsStream(ctx.Response.Body);
}
await next(env);
}
@bjartwolf
bjartwolf / color.st
Created June 8, 2014 11:14
Change color of Rapiro from Pharo
sPort := SerialPort new.
sPort baudRate: 57600.
sPort close.
sPort openPort: '/dev/ttyAMA0'.
sPort nextPutAll: '#PR010G255B255T001'.
namespace FDK.SmsSender
open PSWinCom.Gateway.Client;
open Model;
open log4net.Ext.EventID;
type ISmsService =
abstract member SendSms: recieverNumber: string -> body: string -> unit
type UnknownError = { Error: string}
@bjartwolf
bjartwolf / easter.fs
Created December 13, 2014 14:30
easter.fs
let ``In Western Christianity, using the Gregorian calendar, Easter always falls on a Sunday between 22 March and 25 April inclusive``(date: DateTime) =
let easter = EasterDay date.Year
let firstPossibleDay = new DateTime(date.Year, 3, 22)
let lastPossibleDay = new DateTime(date.Year, 4, 25)
easter >= firstPossibleDay && easter <= lastPossibleDay && easter.DayOfWeek = DayOfWeek.Sunday
@bjartwolf
bjartwolf / longversion.fs
Last active August 29, 2015 14:11
antlong
module ant
// The position is a x-y coordinate
type Pos = int*int
// The set of all points on the board which are black
type Blacks = Set<Pos>
type Dir = Right | Up | Left | Down
// This is the entire game state in one turn
type State = Pos * Dir * Blacks