Skip to content

Instantly share code, notes, and snippets.

View wrongbyte's full-sized avatar
🍊
I like orange juice

wrongbyte

🍊
I like orange juice
View GitHub Profile
@wrongbyte
wrongbyte / hide.md
Created September 1, 2024 13:05
hide top bar in firefox

ctrl + shift + j

(function(){ /*toggle toolbox*/
var doc = Services.wm.getMostRecentWindow("navigator:browser").window.document;
var nt = doc.getElementById("navigator-toolbox");
var ds = nt.style.getPropertyValue("display") == "none";
nt.style.setProperty("display",ds?"-moz-box":"none","important");}
)()

{ "FarmerAnalysis": { "id": [162, 235, 160, 251, 39, 240, 69, 248, 171, 204, 249, 239, 77, 122, 185, 162], "tenant": [179, 140, 35, 20, 130, 21], "parent": [123], "state": -1468854992, "eligibility": null, "policy": [59, 81, 12, 58, 203, 222, 221, 63, 74], "attachments": [ {"id": [216, 26, 82, 239, 4, 198, 28, 249]},

@wrongbyte
wrongbyte / rust.md
Last active July 26, 2024 19:38
List of Rust resources by topic
@wrongbyte
wrongbyte / aoc.rs
Created September 23, 2023 00:24
advent of code 2022 day 13 part 1
// Determine which pairs of packets are already in the right order. What is the sum of the indices of those pairs?
use core::fmt;
use serde::Deserialize;
use std::fs;
static FILENAME: &str = "inputs/13";
#[derive(Deserialize, PartialEq, Clone)]
#[serde(untagged)]

Simple structure

image

Structure with scopes

image

class Circle {
radius: number;
constructor(radius: number) {
this.radius = radius;
}
}
class Square {
sideLength: number;
constructor(sideLength: number) {
@wrongbyte
wrongbyte / question.md
Created December 8, 2022 12:50
question mark as unwrapper of Ok

On the function below, we have a function that returns a bool wrapped by a Result. We want to use the bool that is inside of this function, but we don't want to use things like a if let, for example. How could we do this? image

We can't do it, because we can't apply an unary operator to a Result<bool> - we have to first unwrap the bool inside the Result. image

However, there's a lean solution to it: the question mark operator.

@wrongbyte
wrongbyte / enums3.rs
Created December 1, 2022 14:49
rustlings enums3
// enums3.rs
// Address all the TODOs to make the tests pass!
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
enum Message {
ChangeColor((u8, u8, u8)),
Echo(String),
Move(Point),
@wrongbyte
wrongbyte / closures.md
Last active September 30, 2022 01:38
closures and nested functions

Nested functions, closures and first-class functions

Closures store the environment along with a function. However, closures are only meaningful when a function can be excecuted from outside the scope in which it's declared.

In languages without first-class functions, you could still have nested functions, but they couldn't be used as closures, because you would not be able to execute a function outside of its original scope (since you could not assign this function to any other variable, pass it as an argument or return this function by another function).

Let's see it clearer with some examples:

function outer1() {
  const foo = 42;
@wrongbyte
wrongbyte / graphql.md
Last active July 17, 2022 17:47
GraphQL notes

What's the difference between GraphQL and a REST API?

  • We only define a single endpoint (for example http://example/graphql).
  • Since this is a query language, all actions are done through a POST .

It means we query directly the only endpoint requesting for specific data.

Types of operations

Every GraphQL schema has three special root types: Query, Mutation, and Subscription. The root types correspond to the three operation types offered by GraphQL: queries, mutations, and subscriptions. The fields on these root types are called root fields and define the available API operations.

  • Query: We will look for specific data (equivalent to a GET, but selecting the attributes of our choice)
  • Mutation: We want to change the data (we can compare it to the POST, PUT, and DELETE actions)