Skip to content

Instantly share code, notes, and snippets.

View zohnannor's full-sized avatar
🦀

zohnannor

🦀
View GitHub Profile
const a = [
{ id: 'one', name: "a" },
{ id: 'two', name: "b" },
{ id: 'three', name: "c" },
{ id: 'four', name: "d" },
]
// O(n) 👎👎👎👎👎
console.log(a.find(o => o.id === 'three'))
// logs { id: 'three', name: 'c' }
@zohnannor
zohnannor / rust1plus1.md
Created July 14, 2021 20:44 — forked from gretingz/rust1plus1.md
Proving that 1 + 1 = 2 in Rust

Proving that 1 + 1 = 2 in Rust

The fact that 1 + 1 is equal to 2 is one of those things that is so obvious it may be hard to justify why. Fortunately mathematicians have devised a way of formalizing arithmetic and subsequently proving that 1 + 1 = 2. Natural numbers are based on the Peano axioms. They are a set of simple rules that define (along with a formal system) what natural numbers are. So in order to prove 1 + 1 = 2 in Rust we first need a formal system capable of handling logic. The formal system that we'll be using is not some random crate, but Rust's type system itself! We will not have any runtime code, instead the type checker will do all the work for us.

Implementing the Peano axioms

First let's go trough the Peano axioms. The first axiom is that "Zero is a natural number". Basically what it says is that zero exists. In order to express that in the type system, we just write:

package main
import (
"math/cmplx"
"golang.org/x/tour/pic"
)
func Map(value, start1, stop1, start2, stop2 float64) float64 {
return start2 + (stop2-start2)*((value-start1)/(stop1-start1))

Option<T> and Result<T> methods naming

Option

Method Takes Returns Type Description
is_some &amp;Option bool accessor Returns true if the option is a Some value.
// ==UserScript==
// @name Random Doc Page
// @version 0.1
// @description go to a random documentation page!
// @author Zohnannor
// @include /^http.*doc\.rust-lang\.org\/[\w-]+/
// @include /^http.*(doc|api).+\.rs\/[\w-]+/
// @include /^http.*docs\.rs\/[\w-]+/
// @icon https://www.google.com/s2/favicons?domain=rust-lang.org
// ==/UserScript==

Go to a random documentation page

Why?

I always liked that feature on the wiki websites and I feel like it is useful on rust docs too: there are so many items that you can overlook a lot of interesting stuff if you were to manually go through documentation and click links here and there. Sometimes the way to find something new and unseen is to go to random page!

@zohnannor
zohnannor / theme.md
Last active May 23, 2022 16:54
моя тема в вскоде
{
/* VSCODE */
"explorer.confirmDragAndDrop": false,
"explorer.incrementalNaming": "smart",
"explorer.confirmDelete": false,
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*.ts": "${capture}.js",
"*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts",
"*.jsx": "${capture}.js",
#![feature(test)]
#[cfg(test)]
mod test {
extern crate test;
use std::{hint, ops::RangeInclusive};
use rand::{distributions::Uniform, Rng};
use test::Bencher;
function "btw,"(){print '\033[38;2;23;147;209m
I use
▟█▙
▟███▙
▟█████▙
▟███████▙
▂▔▀▜██████▙
▟██▅▂▝▜█████▙
▟█████████████▙