Skip to content

Instantly share code, notes, and snippets.

@jimmychu0807
jimmychu0807 / string-conversion.rs
Created November 21, 2019 10:20
Conversion between String, str, Vec<u8>, Vec<char> in Rust
use std::str;
fn main() {
// -- FROM: vec of chars --
let src1: Vec<char> = vec!['j','{','"','i','m','m','y','"','}'];
// to String
let string1: String = src1.iter().collect::<String>();
// to str
let str1: &str = &src1.iter().collect::<String>();
// to vec of byte
@CMCDragonkai
CMCDragonkai / nix_inputs.md
Last active October 31, 2025 20:03
Understanding Nix Inputs #nix

Understanding Nix Inputs

Every Nix derivation produces a Nix store output that has 3 things:

  • Executables
  • Libraries
  • Data

Executables are always exported using the PATH environment variable. This is pretty much automatic.

@CMCDragonkai
CMCDragonkai / shebang_scripts_nix_derivations.md
Last active April 25, 2023 07:49
Shebang Scripts in Nix Derivations #nix

Shebang Scripts in Nix Derivations

When you create a derivation, and you later run nix-build on the Nix derivation. Nix will transport the source to a chrooted temporary build directory (this actually can be configured in NixOS configuration.nix). The reason to do this is to ensure deterministic builds in a clean environment.

However the environment is so clean that no dependencies that you don't explicitly declare will be available in that environment. Also things that you take for granted like PATH is something that needs to be explicitly built.

@CMCDragonkai
CMCDragonkai / makeWrapper_and_wrapProgram.md
Created August 24, 2018 07:50
makeWrapper and wrapProgram #nix

makeWrapper and wrapProgram

Nix generally assumes run-time dependencies is a subset of the build-time dependencies.

This means many Nix builder functions try to automatically scan the output for runtime dependencies and "rewrite" them for runtime usage.

However shell scripts which are often exported by packages do not get this automatic scanning treatment.

This means you have to use the makeWrapper package and use either the makeWrapper or wrapProgram utility functions.

@CMCDragonkai
CMCDragonkai / nix_string_and_path_concatenation.md
Last active October 9, 2025 13:51
Nix: String and Path Concatenation #nix #nixos

Nix String and Path Concatenation

From Bas van Dijk:

To understand these things I would recommend using nix-repl:

$ nix-repl
Welcome to Nix version 1.11.2. Type :? for help.
@celadevra
celadevra / switch.el
Last active November 19, 2021 10:18
Sane switching of input methods when using evil-mode in Emacs on OSX
;; switch to english input method when switching to normal mode
;; and switch back when entering insert/replace modes
;; need external script support, currently mac-only
(defvar default-im "com.apple.keylayout.Dvorak" "Default ascii-only input method")
(defvar prev-im (substring (shell-command-to-string "~/bin/im-select") 0 -1)
"IM that I use when starting Emacs and exiting insert mode")
(defun im-use-dvorak ()
"Switch to Dvorak input method on a Mac. im-select is a tool
provided at http://git.io/ndA8Mw"