Skip to content

Instantly share code, notes, and snippets.

View lucasteles's full-sized avatar
:shipit:
Ship it!

Lucas Teles lucasteles

:shipit:
Ship it!
View GitHub Profile
@lucasteles
lucasteles / NativeMemoryManager.cs
Last active September 3, 2024 16:11
Unmanaged Array type
using System.Buffers;
using System.Runtime.CompilerServices;
// ReSharper disable ParameterHidesMember
sealed unsafe class NativeMemoryManager<T> : MemoryManager<T>
where T : unmanaged
{
byte* pointer;
@lucasteles
lucasteles / deferred.cs
Created September 3, 2024 15:07
Deferred execution sample
/// <summary>
/// Disposable static functions
/// </summary>
public static class Disposable
{
/// <inheritdoc />
/// <summary>
/// Create new deferred context
/// </summary>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
SortedHashSet<int> values = [];
Console.WriteLine("Start");
using System;
using System.Numerics;
Print(13u);
Print(12L);
Print<short>(2);
Print<UInt128>(2);
static void Print<T>(T p)
@lucasteles
lucasteles / FGScript.fs
Last active August 2, 2024 19:22
BBScript inspired DSL
type Variable = string
type Label = string
type Value =
| Static of int
| Var of Variable
type Pred =
| Always
| Gt of Value * Value
open System
// Phantom Type usage for generic values
// a generic type argument that is never used by the containing type.
// Definition of Id wrapper
[<Struct>]
type Id<'T> =
private
| Id of Guid
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
foreach(var x in 0..5)
Console.Write($"{x}, ");
Console.WriteLine();
@lucasteles
lucasteles / NativeMemoryManager.cs
Last active May 22, 2024 19:23
C# UnmanagedArray type
using System.Buffers;
using System.Runtime.CompilerServices;
using Backdash.Core;
// ReSharper disable ParameterHidesMember
namespace Backdash.Data;
sealed unsafe class NativeMemoryManager<T> : MemoryManager<T>
where T : unmanaged
{
@lucasteles
lucasteles / Atom.fs
Last active May 14, 2024 17:25
F# Atom
open System
open System.Threading
type Atom<'t> =
private
{ mutable CurrentValue: 't }
member this.Value = this.CurrentValue
[<RequireQualifiedAccess>]
@lucasteles
lucasteles / UdpSocket.fsx
Last active March 13, 2024 14:32
F# UDP Socket
open System.Net.Sockets
open System.Net
open System
open System.Text
open System.Threading
let localPort = 8800
let serverPort = 8888
let serverUri = Uri("http://localhost")