Înapoi la articole →

Cel mai recent articol

Ultima verificare

Urmăritori 0 urmăritori
Articole: 130
  1. A Vector in Rust is fundamentally a (pointer, capacity, length) triplet.

  2. Suppose that a number $n$ has $d$ digits, then: $$ 10^{d-1} \leq n \lt 10^{d}...

  3. By using generic parameters, you can `impl` a trait for any type that satisfies some trait bounds, for example, implement trait `ToString` for every type `T` that implemented the `Display` trait: ```r...

  4. The Never Type

    Rust has a special type `!

  5. Before Rust 1.0, writing code that returns a reference without any lifetime annotation wouldn't compile.

  6. The built-in `console` comes with the `console.assert` method, which is pretty useful to write some tests in your code.

  7. Overflow can happen when doing integer arithmetics in Rust, for example: ```rust let _ = 255u8 + 1;...

  8. Deref and DerefMut

    The traits [`std::ops::Deref`](https://doc.rust-lang.org/std/ops/trait.Deref.html) and [`std::ops::DerefMut`](https://doc.rust-lang.org/std/ops/trait.DerefMut.html) are used for **explicit dereference...

  9. One of the rules for working with traits in Rust is: You are not allowed to implement a trait on a type if either the trait or the type is not local to your crate.

  10. Due to rounding errors, most floating-point numbers cannot be represented precisely in the computer.

  11. `ArenaAllocator` is one of Zig's built-in allocators.

  12. Build system

    There are 4 build modes in Zig, each can be enabled via the arguments `-O ReleaseSafe`, `-O ReleaseSmall`, and `-O ReleaseFast` when running `zig run` or `zig test`.

  13. Handling errors

    A function in Zig can return either an error or an actual value, most of the time you will see something like this: ```zig pub fn countTheSheep() !

  14. JSON in 5 minutes

    Zig has built-in support for JSON via the `std.json` module.

  15. Implementing a stack is one of my favorite tests when working with a new language because it will show us a lot about the language's ergonomics.

  16. Zig came with a built-in C/C++ compiler `zig cc` and `zig c++`.

  17. Comptime

    One of the unique features of Zig is the ability to let us control what happens in our code, during both runtime and compile time.

  18. Zig has no runtime, hence, no automatic memory management.

  19. Strings in 5 minutes

    Just like C/C++, you can define a string in Zig with an array of bytes or as a null-terminated string literal.

  20. In React, you can mount a component into any DOM node instead of just the current parent component, with the help of `ReactDOM.createPortal([content], [node] )`.

  21. Type Intersection

    Let's say, we are building a component to display some images (with lazy loading): ```javascript const LazyImage = (props: ImageProps) => {...

  22. Sometimes, you'll run into a case where TS keeps complaining about a possibly undefined value.

  23. In Next.js, you can define a [dynamic route](https://nextjs.org/docs/routing/dynamic-routes) by creating a file at `/pages/post/[id].tsx`.

  24. Algorithm to delete a node from a BST: - Find the node to delete - Find the deepest right most (DRM) node of the tree...

  25. To create a custom widget in [Druid](https://linebender.org/druid/), we create a new struct and implement [Widget](https://docs.rs/druid/latest/druid/trait.Widget.html) trait.

  26. This one is a bit more compex than the pre-order (in term of using stack).

  27. Find Palindrome

    When solving palindrome problems, we need to avoid sliding window solution (a.k.a brute force), where we try to generate every substring and check to find the palindrome.

  28. The array **x** is to keep track of all possible integers we can find, the array **t** is to keep the sum **t[i]** of every **x** number from **x[1]** to **x[i]**.

  29. The algorithm is simple: 1.

  30. Like currying, if a function takes some arguments and we invoke that function without all of the arguments, a new function will be created so we can call it with the remaining functions later on.