Skip to content

Instantly share code, notes, and snippets.

Avatar
👾

Jordan Orelli jordanorelli

👾
View GitHub Profile
View list.rs
use std::rc::Rc;
pub enum List<T> {
Node { value: T, next: Rc<List<T>> },
Empty,
}
impl <T> List<T> {
pub fn empty() -> Self {
List::Empty
View iterators2.rs
// iterators2.rs
// In this exercise, you'll learn some of the unique advantages that iterators
// can offer. Follow the steps to complete the exercise.
// Execute `rustlings hint iterators2` or use the `hint` watch subcommand for a hint.
// Step 1.
// Complete the `capitalize_first` function.
// "hello" -> "Hello"
pub fn capitalize_first(input: &str) -> String {
let mut c = input.chars();
View errors6.rs
// errors6.rs
// Using catch-all error types like `Box<dyn error::Error>` isn't recommended
// for library code, where callers might want to make decisions based on the
// error content, instead of printing it out or propagating it further. Here,
// we define a custom error type to make it possible for callers to decide
// what to do next when our function returns an error.
// Execute `rustlings hint errors6` or use the `hint` watch subcommand for a hint.
@jordanorelli
jordanorelli / settings.json
Created August 29, 2022 19:42
git bash in windows terminal
View settings.json
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions": [],
"defaultProfile": "{00000000-0000-0000-ba54-000000000002}",
"profiles":
{
"defaults":
{
"antialiasingMode": "cleartype",
@jordanorelli
jordanorelli / export.py
Created April 22, 2022 02:09
static mesh exporter for blender to unity
View export.py
from math import pi
import bpy
import os
import copy
# export to blend file location
dirname = os.path.dirname
basedir = dirname(dirname(dirname(bpy.data.filepath)))
export_dir = os.path.join(basedir, "Assets", "Models")
View table_test.go
package merge
import (
"testing"
)
func TestMergeTables(t *testing.T) {
alice := Table[string, *additive]{
"vanilla": add(3),
"chocolate": add(5),
@jordanorelli
jordanorelli / maybe.go
Created November 29, 2021 14:04
oh is this all it is
View maybe.go
package main
import (
"fmt"
"unicode/utf8"
)
type Maybe[T any] struct {
val T
ok bool
@jordanorelli
jordanorelli / union.go
Created November 29, 2021 04:39
boxing a value into a union constraint
View union.go
package main
import (
"fmt"
)
// Allowed is a constraint that matches specific types
type Allowed interface {
int | float64 | bool
}
@jordanorelli
jordanorelli / main.go
Created November 29, 2021 01:51
a read-only reference type with generics in Go
View main.go
package main
import (
"fmt"
)
// ref is a reference to a value. A reference can read that
// value but not alter it.
type ref[V any] struct {
v *V
@jordanorelli
jordanorelli / merge.go
Created November 27, 2021 00:04
an abomination
View merge.go
package main
import (
"fmt"
"strings"
)
type A int
func (a *A) Merge(v *A) error {