Skip to content

Instantly share code, notes, and snippets.

@barseghyanartur
barseghyanartur / random_boolean_in_rust.md
Created February 6, 2023 11:36
Rust random boolean

Random boolean in Rust

Prerequisites

[dependencies]
rand = "0.8.5"

Usage example

Install XnView on Linux using flatpak

Optional

flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

Install XnView

flatpak install https://dl.flathub.org/repo/appstream/com.xnview.XnViewMP.flatpakref
@barseghyanartur
barseghyanartur / rust_cloneable_struct.md
Created February 2, 2023 14:07
Make a struct clonable in Rust

Make a struct clonable in Rust

Also, we make it debuggable

fn main() {
    let user = User {
        active: true,
        username: String::from("someusername123"),
 email: String::from("[email protected]"),
@barseghyanartur
barseghyanartur / rust_debug_struct.md
Last active February 2, 2023 14:27
Debug struct in Rust

Debug struct in Rust

Problem

This will not work

struct User {
    active: bool,
    username: String,
@barseghyanartur
barseghyanartur / rust_split_string_by_char.md
Created February 2, 2023 11:13
Split string by char in Rust

Split string by char in Rust

One way

let original = "What a day!";
let split: Vec<&str> = original.split(" ").collect();
dbg!(&split);
@barseghyanartur
barseghyanartur / cargo_new_no_git.md
Last active February 2, 2023 10:48
Globally prevent `cargo new` from creating `.git` directories inside newly created packages

Globally prevent cargo new from creating .git directories inside newly created packages

Problem

When calling cargo new package_name, cargo by default creates a .git/ directory inside the newly created package. If that's not something that you want, continue reading.

Solution

Modify global Cargo config file

@barseghyanartur
barseghyanartur / rust_dbg_macro_learnings.md
Created February 2, 2023 08:25
Rust `dbg!` macro learnings

Another learning about the fantastic dbg! macro: always pass vars as references!

This works:

let mut s = String::from("hello");
dbg!(&s);

s.push_str(", world!");
dbg!(&amp;s);
@barseghyanartur
barseghyanartur / instr.md
Created February 1, 2023 14:36
Switch focus between VS Code editor and integrated terminal

Switch focus between VS Code editor and integrated terminal

  1. Open the Command Palette (Ctrl+Shift+P Windows/Linux or ⇧ ⌘ P Mac).

  2. Type "Preferences: Open Keyboard Shortcuts (JSON)" and press Enter.

  3. Add the following entries to the keybindings.json file:

// Toggle between terminal and editor focus
@barseghyanartur
barseghyanartur / no_more_leaking_secrets.rst
Last active February 17, 2023 00:24
Protect yourself from accidentally leaking sensitive information

Protect yourself from accidentally leaking sensitive information

Protect yourself from accidentally leaking sensitive information
@barseghyanartur
barseghyanartur / pandoc_convert_howto.md
Last active January 11, 2023 10:22
Convert .rst to .pdf using `pandoc`
pandoc -V geometry:a4paper -V colorlinks=true -f rst --toc -o output.pdf input.rst