Skip to content

Instantly share code, notes, and snippets.

@lamg
lamg / print_tree.fsx
Created August 7, 2024 15:50
Print a tree
type Branch<'a, 'b> =
{ value: 'a
children: Tree<'a, 'b> seq }
and Tree<'a, 'b> =
| Branch of Branch<'a, 'b>
| Leaf of 'b
type PrinterContext<'a, 'b> =
abstract member branchToString: 'a -> string
@lamg
lamg / gtk4.fsx
Created June 4, 2024 06:41
F# 🤝 GTK4
#r "nuget: GirCore.Gtk-4.0,0.5.0"
open System
open Gtk
let label () =
let label = new Label()
label.SetText "hello"
label
@lamg
lamg / permutations_test.rs
Last active January 12, 2022 21:08
check if two vectiors are a permutation of the same set
use std::cmp::PartialEq;
fn is_perm<T: PartialEq>(xs: &Vec<T>, ys: &Vec<T>) -> bool {
let mut ok = xs.len() == ys.len();
let mut ws: Vec<&T> = xs.iter().collect();
let mut zs: Vec<&T> = ys.iter().collect();
while ok && ws.len() != 0 {
let (ok0, i) = exists(&zs, &ws[0]);
ok = ok0;
if ok0 {
@lamg
lamg / permutations_test.go
Last active January 11, 2022 15:55
Check if two string slices are equal by checking if they are a permutation of the other
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestIsPerm(t *testing.T) {
ts := []struct {
xs, ys []string
@lamg
lamg / golang_request_ip_from_context.go
Last active October 25, 2017 14:43
How to get the IP address in the dialer's context, using https://github.com/elazarl/goproxy
package main
import (
"context"
"flag"
"fmt"
gp "github.com/elazarl/goproxy"
"log"
"net"
"net/http"

Keybase proof

I hereby claim:

  • I am lamg on github.
  • I am lamg (https://keybase.io/lamg) on keybase.
  • I have a public key whose fingerprint is A1C2 E5BE EA42 B2B9 1A8A 0D80 3941 99B7 9F03 6583

To claim this, I am signing this object: