Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Rust Error Handling Cheatsheet - Result handling functions

Introduction to Rust error handling

Rust error handling is nice but obligatory. Which makes it sometimes plenty of code.

Functions return values of type Result that is "enumeration". In Rust enumeration means complex value that has alternatives and that alternative is shown with a tag.

Result is defined as Ok or Err. The definition is generic, and both alternatives have

@t27
t27 / linux-oom-killer-fixes.md
Last active April 22, 2024 11:05
Dealing with the Linux OOM Killer

Dealing with the Linux OOM Killer at the program level

Do this in cases when you dont want to change the os-level settings, but only want to disable the OOM killer for a single process. This is useful when youre on a shared machine/server.

The OOM killer uses the process level metric called oom_score_adj to decide if/when to kill a process. This file is present in /proc/$pid/oom_score_adj. The oom_score_adj can vary from -1000 to 1000, by default it is 0.

You can add a large negative score to this file to reduce the probability of your process getting picked and terminated by OOM killer. When you set it to -1000, it can use 100% memory and still avoid getting terminated by OOM killer.

@myniva
myniva / printTaskInputs.gradle
Last active August 8, 2023 11:22
Prints all inputs of the various tasks of a Gradle project
task printTaskInputs {
doLast {
project.getTasks().each { task ->
println "--------------------------------------------------------------------------------"
println " Task '${project.name}:${task.name}'"
println "--------------------------------------------------------------------------------"
println ""
println "File inputs:"
task.inputs.files.each {
@meirbon
meirbon / Dell XPS 15 9560 Manjaro Setup instructions
Last active March 31, 2024 01:21
Small, quick guide to set up Manjaro on the XPS 15 9560
# 1. First of all of course get Manjaro:
https://manjaro.org/get-manjaro/
# I recommend using Etcher to copy the image to your USB:
https://etcher.io/
# 2. Before installing make sure:
# - Secure boot is disabled in BIOS
# - Your SSD, HDD or NVME drive is set to AHCI instead of RAID
# - Fastboot should be on Auto or minimal, but this shouldn't matter to much
@lummie
lummie / enum.go
Last active November 4, 2023 18:09
Golang Enum pattern that can be serialized to json
package enum_example
import (
"bytes"
"encoding/json"
)
// TaskState represents the state of task, moving through Created, Running then Finished or Errorred
type TaskState int
@zapstar
zapstar / openssl_2way_auth.sh
Last active March 20, 2024 21:07
Steps to create CA, server and client keys + certificates for SSL 2-way authentication
# Move to root directory...
cd /
mkdir keys
cd keys
# Generate a self signed certificate for the CA along with a key.
mkdir -p ca/private
chmod 700 ca/private
# NOTE: I'm using -nodes, this means that once anybody gets
# their hands on this particular key, they can become this CA.
@taoyuan
taoyuan / npm-using-https-for-git.sh
Last active April 19, 2024 18:20
Force git to use https:// instead of git://
# npm using https for git
git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
# npm using git for https
git config --global url."git@github.com:".insteadOf https://github.com/
git config --global url."git://".insteadOf https://
// http://docs.groovy-lang.org/latest/html/documentation/grape.html
// http://mvnrepository.com/artifact/org.codehaus.groovy.modules.http-builder/http-builder/0.7.1
groovy.grape.Grape.grab(group:'org.codehaus.groovy.modules.http-builder', module:'http-builder', version:'0.7.1')
import groovyx.net.http.HTTPBuilder
@staltz
staltz / introrx.md
Last active April 20, 2024 14:15
The introduction to Reactive Programming you've been missing