Skip to content

Instantly share code, notes, and snippets.

@pragmatrix
pragmatrix / versioned.rs
Last active October 29, 2023 12:05
A Versioned<T> type.
use std::ops::{Deref, DerefMut, Index};
#[test]
fn test() {
let mut outer: Versioned<_> = Outer {
a: 0.into(),
b: 0.into(),
multiplied: 0,
}
.into();
Prompt: Invent a new language that is more efficient than human language for exchanging information in written text and make some examples.
Introducing OptiScript: A highly efficient language for exchanging information in written text. OptiScript incorporates elements from various human languages, mathematical notations, and logical symbols to optimize information exchange. Here are some key features of OptiScript:
It uses a compact alphabet of 30 symbols, encompassing both phonetic and ideographic characters.
OptiScript employs a context-aware grammar that reduces the need for lengthy syntax and repetitive phrases.
The language utilizes a color-coding system for faster processing and comprehension of text.
It incorporates shorthand symbols and abbreviations from various disciplines to reduce character count and convey complex ideas succinctly.
Here are some examples to illustrate the efficiency of OptiScript:
@pragmatrix
pragmatrix / rc_cache.rs
Created April 14, 2023 09:42
RcCache. - A simple cache that wraps references that point to values to reference counted values in Rust. Mostly written by GPT-4
use std::{cell::RefCell, collections::HashMap, hash::Hash, rc::Rc};
#[derive(Debug)]
pub struct RcCache<K, V>
where
K: Eq + Hash + Clone,
V: Clone,
{
data: RefCell<HashMap<K, Rc<V>>>,
}
@pragmatrix
pragmatrix / paragraph_editor.rs
Created March 31, 2023 10:33
skia-safe based paragraph editor
use crate::{
entities::{colors, DynId},
geometry::{scalar, Point},
input::{
self,
tracker::{movement, Movement},
},
renderer::paragraph::{self, Paragraph},
Jump, UnicodeHelper,
};
@pragmatrix
pragmatrix / paragraph.rs
Created March 31, 2023 10:31
skia-safe based paragraph renderer
use crate::{
default,
geometry::{scalar, Point, Size},
UnicodeHelper,
};
use skia_safe::{
textlayout::{
self, FontCollection, LineMetrics, ParagraphBuilder, ParagraphStyle, PositionWithAffinity,
RectHeightStyle, RectWidthStyle, TextStyle,
},
> rustup component add x86_64-unknwon-linux-musl
- change build_support to support musl
- build with target musl
Failed to find tool Is musl-g++ installed
> sudo apt install musl-dev
> sudo apt install musl-tools
Process: physics [44804]
Path: /Users/USER/*/physics
Identifier: physics
Version: 0
Code Type: X86-64 (Native)
Parent Process: zsh [39813]
User ID: 501
Date/Time: 2020-07-27 21:23:03.377 +0200
OS Version: Mac OS X 10.15.5 (19F101)
let [<Literal>] FilenameMaxLen: int = 64
// Note: this is platform dependent, therefore Windows
// version of System.IO.Path.GetInvalidFileNameChars() is hardcoded here.
let InvalidFilenameCharacters = [|
'"'; '<'; '>'; '|'; '\000'; '\001'; '\002'; '\003'; '\004'; '\005'; '\006';
'\007'; '\b'; '\009'; '\010'; '\011'; '\012'; '\013'; '\014'; '\015';
'\016'; '\017'; '\018'; '\019'; '\020'; '\021'; '\022'; '\023'; '\024';
'\025'; '\026'; '\027'; '\028'; '\029'; '\030'; '\031'; ':'; '*'; '?';
'\\'; '/'
[<AutoOpen>]
module Prelude
let (^) = (<|)
type CR = CompilationRepresentationAttribute
let [<Literal>] ModuleSuffix = CompilationRepresentationFlags.ModuleSuffix
type RQA = RequireQualifiedAccessAttribute
let inline flip f a b = f b a
let inline curry f a b = f(a, b)
@pragmatrix
pragmatrix / Entitlements.plist
Created February 24, 2015 14:44
Empty Entitlements.plist
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>