Skip to content

Instantly share code, notes, and snippets.

@csknk
csknk / generate_blocks.sh
Created May 24, 2022 18:32 — forked from System-Glitch/generate_blocks.sh
Tutorial for bitcoin regtest
# Script to generate a new block every minute
# Put this script at the root of your unpacked folder
#!/bin/bash
echo "Generating a block every minute. Press [CTRL+C] to stop.."
address=`./bin/bitcoin-cli getnewaddress`
while :
do

VIM-GO

Plugin https://github.com/fatih/vim-go
Tutorial https://github.com/fatih/vim-go-tutorial
Vimrc https://github.com/fatih/dotfiles/blob/master/vimrc

Run

Commands

  • File :GoRun %
  • Package :GoRun
  • Debug :GoDebugStart
@csknk
csknk / returning-strings-from-function.rs
Last active August 19, 2020 20:33 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn main() {
let s = String::from("book");
let ss = pluralize(s.clone());
println!("One {}, many {}", s, ss);
}
fn pluralize(s: String) -> String {
// Can't push_str directly onto s as s is not mutable
@csknk
csknk / trait_extension_to_print_bytes_as_hex.rs
Last active July 3, 2020 20:15 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::fmt;
fn main() -> Result<(), &'static str> {
let b = vec![0x64, 0x61, 0x76, 0x65];
println!("{}", b.to_hex());
Ok(())
}
trait ToHex {
fn to_hex(&self) -> String;
@csknk
csknk / match-options-rust.rs
Created May 7, 2020 13:57 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn main() {
// Match is an expression as well as a statement. This example shows how
// a variable is set based on an Option enum.
// ------------------------------------------
let msg_option = Some("+++MELON MELON MELON+++"); // Some variant
let msg_option_empty = None; // None variant
let msg = match msg_option {
Some(m) => m, // m is the unwrapped data from the option
@csknk
csknk / alt.rs
Last active May 6, 2020 20:41 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn main() {
// If `option` is Some<T>, unwrap it and stick the value in `x`.
if let Some(x) = option {
foo(x);
}
}
@csknk
csknk / default-values-from-option.rs
Created May 6, 2020 19:18 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn main() {
// If x has a value, unwrap it and set y to it's value.
// Otherwise, set y to a default.
// ------------------------------------------------------------------------
// let x = Some(11); // Uncomment to test
let x = None;
let y;
if x.is_some() {
y = x.unwrap();
@csknk
csknk / rules-of-borrowing.rs
Last active April 30, 2020 20:45 — forked from rust-play/playground.rs
Code shared from the Rust Playground
/// Notes ownership and borrowing.
fn main() -> Result<(), &'static str> {
let mut a = [1,2,3,4];
println!("{:?}", a);
{
let b = &mut a[0..2];
// You can't access a at this point because it has been mutably borrowed
// from. The following line won't compile, with the error message:
// `cannot borrow `a` as immutable because it is also borrowed as mutable`:
// println!("a: {:?}", a);
@csknk
csknk / unwrap_or_else.rs
Last active March 25, 2023 22:35 — forked from rust-play/playground.rs
unwrap_or_else examples
//! Examples for `unwrap_or_else()`
use std::process;
fn func(in_num: u8) -> Option<&'static str> {
if in_num % 2 != 0 {
return None;
}
Some("even")
}
@csknk
csknk / unwrap-or-else-examples.rs
Last active March 6, 2020 18:07 — forked from rust-play/playground.rs
Code shared from the Rust Playground
//! Examples for `unwrap_or_else()`
use std::process;
fn func(in_num: u8) -> Option<&'static str> {
if in_num % 2 != 0 {
return None;
}
Some("even")
}