Skip to content

Instantly share code, notes, and snippets.

[StructLayout(LayoutKind.Sequential)]
public struct BitArray512<TEnum> : IEquatable<BitArray512<TEnum>>
{
private ulong _a0;
private ulong _a1;
private ulong _a2;
private ulong _a3;
private ulong _a4;
private ulong _a5;
private ulong _a6;

Keybase proof

I hereby claim:

  • I am paavohuhtala on github.
  • I am paavohtl (https://keybase.io/paavohtl) on keybase.
  • I have a public key ASAMdOYX6Q8PxOvmdwLuknUkDDWjr3paAkTAxx3z7KChqgo

To claim this, I am signing this object:

let time = 0;
function getSine(freq, time) {
const period = 2;
const phase = freq * (time % period);
return phase - Math.floor(phase);
//return Math.sin(2 * Math.PI * freq * time) > 0.5 ? 1 : 0.0;
}
function loop(numFrames, outL, outR, sampleRate) {
@paavohuhtala
paavohuhtala / partial.lenses.d.ts
Last active March 29, 2018 18:05
Crazy evil type system hacking to get partial.lenses working in TypeScript.
declare module "partial.lenses" {
// This is a fairly simple, heterogenous type-level linked list.
// We use this to represent lense types in an easy-to-use way.
type ConsNil = { "__NIL__": never };
type Cons<A, B> = { head: A, tail: B | ConsNil }
// Just a bit of syntax sugar.
type ConsLast<A> = Cons<A, ConsNil>
// TupleToCons converts a tuple type into a linked list.
open System
open System.Collections.Generic
let samples = 100000
let rand = Random()
let lenTo1 () =
Seq.unfold (fun sum -> if sum > 1.0 then None else Some ((), sum + rand.NextDouble ())) 0.0
|> Seq.length
@paavohuhtala
paavohuhtala / bit_struct.rs
Created January 12, 2017 00:59
Rust macro issue, "no rules expected the token `2`"
macro_rules! field_size {
(1) => (bool);
(2) => (u8);
(3) => (u8);
(4) => (u8);
(5) => (u8);
(6) => (u8);
(7) => (u8);
(8) => (u8);
}
@paavohuhtala
paavohuhtala / Bot.fs
Created December 6, 2016 12:42
F# telegram bot with Hopac
namespace FsBots
open System
open Hopac
type ChatMessage<'id, 'msg, 'user> = {
chatId: 'id
content: string
conversation: Conversation<'id, 'msg, 'user>
internalMessage: 'msg
@paavohuhtala
paavohuhtala / Program.fs
Created December 3, 2016 19:08
Telegram echo bot in F# \w Hopac
open System
open Telegram.Bot
open Telegram.Bot.Types
open Telegram.Bot.Types.Enums
open Hopac
let token = "nope"
@paavohuhtala
paavohuhtala / GenericFib.cs
Created November 14, 2016 10:44
Trying out the typeclass encoding proposed in Classes for the masses
using System;
using System.Linq;
using System.Collections.Generic;
namespace ClassesForTheMasses
{
public interface Zero<A> { A Zero(); }
public interface One<A> { A One(); }
public interface Add<A> { A Add(A x, A y); }
@paavohuhtala
paavohuhtala / PE.rs
Created November 10, 2016 20:57
PE parsing with rust
use std;
use std::io::{Read, Seek, SeekFrom};
use byteorder::{ReadBytesExt, LittleEndian};
trait ReadableStruct {
fn read_from<R: Read + Seek>(reader: &mut R) -> Result<Self, std::io::Error> where Self : std::marker::Sized;
}
#[derive(Debug)]