Skip to content

Instantly share code, notes, and snippets.

View natalie-o-perret's full-sized avatar
🐈
F#-ing

Natalie Perret natalie-o-perret

🐈
F#-ing
View GitHub Profile
@carols10cents
carols10cents / c#-to-rust.md
Last active April 18, 2024 22:55
C# to Rust Cheat Sheet

Thanks to @seejee for making this for me!!!

C# to Rust Cheat Sheet

The goal of this is to have an easily-scannable reference for the most common syntax idioms in C# and Rust so that programmers most comfortable with C# can quickly get through the syntax differences and feel like they could read and write basic Rust programs.

What do you think? Does this meet its goal? If not, why not?

Variables

@dvdsgl
dvdsgl / Monads for a C# dev.md
Last active January 8, 2024 06:11
Monads explained (sort of) to a C# developer

A monad is a fancy word for a generic type of the form MyMonad<T> (a generic type of arity 1).

A monad is special because it adds 'special powers' to the T that it wraps. These 'special powers' won't sound very special to an imperative programmer, so you have to squint to see them but bear with me.

  • IEnumerable<T> is a monad that gives values of type T the special power of nondeterminism, or the ability to 'be' multiple values at once.
  • Nullable<T> is a monad that gives values of type T the special power of nullability, or the ability to be absent.
  • Task<T> is a monad that gives values of type T the special power of asynchronicity, or the ability to be used before they are computed.

The trick with monads comes when you want to play with the T values, because they are inside another type. C# introduced language changes to make dealing with values inside these monads easier:

@valyala
valyala / README.md
Last active June 3, 2024 17:00
Optimizing postgresql table for more than 100K inserts per second

Optimizing postgresql table for more than 100K inserts per second

  • Create UNLOGGED table. This reduces the amount of data written to persistent storage by up to 2x.
  • Set WITH (autovacuum_enabled=false) on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we never DELETE or UPDATE the table).
  • Insert rows with COPY FROM STDIN. This is the fastest possible approach to insert rows into table.
  • Minimize the number of indexes in the table, since they slow down inserts. Usually an index on time timestamp with time zone is enough.
  • Add synchronous_commit = off to postgresql.conf.
  • Use table inheritance for fast removal of old data:
@martincooper
martincooper / TryMonad.fs
Created June 29, 2016 15:51
F# Try Exception Monad
namespace Exceptions
open System
module ExceptionTypes =
// TryResult, used to pass results or exception as values.
type TryResult<'r, 'e> =
| Result of 'r
| Error of 'e :> Exception
@SeanSobey
SeanSobey / portainer.md
Last active June 12, 2024 07:40
Portainer Setup on Windows 10

Portainer on Windows 10

Here I have 2 methods for running portainer on windows, a quick, preferred method only requiring a fairly recent version of docker, or a more complicated method to try if that does not work.

Using host.docker.internal

This setup will let you run Portainer on windows by using the host.docker.internal endpoint (docker.for.win.localhost is depricated since docker version 3.2.1, but older versions may use this instead).

Please note:

@AnthonyDGreen
AnthonyDGreen / homeward-bound.md
Last active November 15, 2018 00:05
(Former) Program Manager for Visual Basic details why he's leaving Redmond and moving back to Chicago.

This is my family tree:

22136890_558639237233_2226452117892069088_o

I drew this diagram from memory (it's not complete) on the whiteboard in my office last year to illustrate a point to a colleague: family is everything to me. Those shapes aren't just entries in a historical record, they're people who I've known and who have surrounded me my entire life. Not being near to them is as unnatural to me as not including my middle initial/name in my signature*. The shapes inside the circle are all in Chicago. And it's for that reason that I've always known my time at Microsoft and in Seattle could never be forever.

Since arriving in Seattle 8-years ago I've flown across the country (and to Canada once) for weddings, birthdays, graduations, almost every major US holiday (can you imagine having to call all those people if you miss Christmas?), a couple of drivers tests, and for one particular relation for

@fivemoreminix
fivemoreminix / main.rs
Last active January 14, 2021 16:43
Simple Brainfuck to C compiler written in Rust.
// "Hello, world!"
static PROGRAM: &'static str = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
fn main() {
let tokens = tokenize(PROGRAM);
//println!("{:?}", tokens);
let generated_code = generate(&tokens);
println!("{}", generated_code);
}
@emcake
emcake / applicative-builders.fs
Last active February 15, 2021 15:10
Applicative builders in F# by abusing For and IsLikeZip
type ListBuilder() =
/// map
member x.For(l,f) =
List.map f l
/// id
member x.Yield(v) =
v
@akhansari
akhansari / event-sourced-user.fsx
Last active December 16, 2022 00:09
F# : Event Sourcing in a nutshell
// ========= Event Sourcing in a nutshell
(*
FriendlyName: string
Aggregate friendly name.
Initial: 'State
Initial (empty) state we will start with.
Decide: 'Command -> 'State -> 'Event list
@michaeloyer
michaeloyer / srtp.fsx
Last active July 1, 2024 03:15
F# SRTP Example
// SRTP: Statically Resolved Type Parameters
// https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/statically-resolved-type-parameters
// SRTP Allows for pulling members out of types that where the member is named and typed the same
// In this example SRTP will be used to pull out the 'First: string' and 'Last: string' members
// from different types
// One example of SRTP in the F# Base Class Library is the (+) operator.
// You'll see that it has this type signature: