Skip to content

Instantly share code, notes, and snippets.

View ayazhafiz's full-sized avatar
💭
🫡

Ayaz ayazhafiz

💭
🫡
View GitHub Profile
/* automatically generated by rust-bindgen 0.59.2 */
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct rgba {
pub a: f32,
pub b: f32,
pub c: f32,
pub d: f32,
}
@ayazhafiz
ayazhafiz / README.md
Last active April 4, 2022 17:03 — forked from j-maas/README.md
Roc: Open and closed tag unions

Roc: Open and closed tag unions

People's intuition

As evidenced in the discussions on Zulip (1, 2, 3) there are some cases where open and closed tags behave in a way that goes against people's intuition.

The main problem seems to be that people expect produced values to compose, but the "default" syntax (without *) prohibits this. People understand the openness to mean whether all possible values are listed, not whether more values can be added "later". For example: Roc infers myValue = if True then One else Two to be an open tag unio

@ayazhafiz
ayazhafiz / compress.rs
Created June 22, 2021 14:52
Emits an identical rust program with comments removed and whitespace minimized.
use rustc_lexer::{tokenize, Token, TokenKind};
use std::io::{self, Read};
enum Cmd {
Print(usize),
Space,
Skip(usize),
}
fn layout(toks: impl Iterator<Item = Token>) -> impl Iterator<Item = Cmd> {
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: spark
name: my-notebook-deployment
labels:
app: my-notebook
spec:
replicas: 1
selector:
@ayazhafiz
ayazhafiz / rust.md
Last active October 19, 2020 01:56
rust :):

Things i wish i could do in rust.

Enum variants as types

What I want is

enum Animal { Rabbit, Lizard }
fn do_rabbit(r: Animal::Rabbit) {}
fn do_lizard(l: Animal::Lizard) {}
extern crate libc;
use std::ffi::{CStr, CString};
use std::str;
use libc::c_char;
#[no_mangle]
pub extern "C" fn hello(raw_name: *const c_char) -> *const c_char {
// convert to Rust String
let name = str::from_utf8(
fn hello(name: String) -> String {
format!("Hello, {}!", name)
}
@ayazhafiz
ayazhafiz / 2201.cpp
Last active February 19, 2018 17:52
#include <cmath>
#include <iostream>
#include <roth>
size_t class(roth::EffortMatrix difficulty, double time)
{
double score = std::exp(difficulty.cost) / time;
return roth::linearizeCurve(score);
}
struct Delta {
x: [i8; 4],
y: [i8; 4],
}
fn geometric_center(points: &[[f64; 2]]) -> [f64; 2] {
const DELTA: Delta = Delta {
x: [-1, 0, 1, 0], // movement in `x` direction
y: [0, 1, 0, -1], // movement in `y` direction
};
fn cost(points: &[[f64; 2]], center: &[f64; 2]) -> f64 {
points.iter().fold(0., |net, point| {
let cost = (
(center[0] - point[0]).powi(2) // `x` coordinates
+ (center[1] - point[1]).powi(2) // `y` coordinates
).sqrt();
net + cost
})
}