Skip to content

Instantly share code, notes, and snippets.

@barseghyanartur
barseghyanartur / how to write a valentine's day message in rust.md
Last active July 29, 2023 20:12
How to write a Valentine's Day message using Stable Diffusion and Rust

How to write a Valentine's Day message using Stable Diffusion and Rust

A practical guide

Step 1

Use your favorite search engine to search for "stable diffusion image generator". You will find a lot of services. Pick one, for example Night Cafe Creator.

Step 2

@barseghyanartur
barseghyanartur / print_function_name_in_rust.md
Created February 13, 2023 11:32
Print function name in Rust

Print function name in Rust

Deps

[dependencies]
function_name = "0.3.0"

Code

@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("someone@example.com"),
@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