Skip to content

Instantly share code, notes, and snippets.

use std::io;
use std::io::Write;
fn main() {
// create a vector to hold the fibonacci values and prefill with 0, 1
println!("Enter -1 to exit");
let mut fill_on_the_fly = vec![0, 1];
loop {
let n = get_isize("Enter a number: ");
if n == -1 {
use std::time::Instant;
// The board dimensions
const NUM_ROWS: usize = 8;
const NUM_COLS: usize = NUM_ROWS;
const INUM_ROWS: isize = NUM_ROWS as isize;
const INUM_COLS: isize = NUM_COLS as isize;
// Whether we want an open or closed tour
const REQUIRE_CLOSED_TOUR: bool = false;
use std::time::Instant;
// the board dimensions
const NUM_ROWS: usize = 6;
const NUM_COLS: usize = NUM_ROWS;
fn main() {
// create a new board with all entries set to UNVISITED
let mut board = [[','; NUM_COLS]; NUM_ROWS];
func bubbleSort(slice []int) {
n := len(slice)
for {
swapped := false
for i := 1; i < n; i++ {
if slice[i-1] > slice[i] {
slice[i-1], slice[i] = slice[i], slice[i-1]
swapped = true
}
}
package main
import (
"fmt"
"math/rand"
)
func main() {
// Get the number of items and maximum item value.
var numItems, max int
@rphuber
rphuber / counting_sort.go
Created April 13, 2024 12:36
Implemtation of counting sort in go
func countingSort(slice []Customer) []Customer {
// slice `sortedSlice` is created to store the sorted values
sortedSlice := make([]Customer, len(slice))
// slice `countSlice` is created to store the count of each value (line 32).
countSlice := make([]int, len(slice))
// `countSlice` is populated by iterating over the input `slice` and incrementing the count of each `Customer`'s `numPurchases`
for _, customer := range slice {
countSlice[customer.numPurchases]++
}
func linearSearch(slice []int, target int) (index, numTests int) {
for idx, val := range slice {
if val == target {
return idx, idx + 1
}
}
return -1, len(slice)
}
@rphuber
rphuber / folds.lua
Created February 19, 2025 20:46
nvim folds config
return {
-- Folding preview, by default h and l keys are used.
-- On first press of h key, when cursor is on a closed fold, the preview will be shown.
-- On second press the preview will be closed and fold will be opened.
-- When preview is opened, the l key will close it and open fold. In all other cases these keys will work as usual.
{
"anuvyklack/fold-preview.nvim",
event = "BufReadPost",
dependencies = "anuvyklack/keymap-amend.nvim",
config = true,

Every developer has experienced that moment of déjà vu – you're tackling a problem that feels familiar, knowing you've solved something similar before, but the solution remains frustratingly out of reach. This is where a code garden comes in – a carefully cultivated collection of code snippets, patterns, and solutions that grows alongside your journey as a developer.

What is a Code Garden?

A code garden is more than just a directory of random code snippets. It's a living, breathing repository of your learning journey, carefully organized and maintained like a real garden. Each snippet represents a seed of knowledge that you've planted, and as you revisit and refine these pieces over time, they grow into robust, reliable solutions that you can transplant into future projects.

The Benefits of Maintaining Your Code Garden

Knowledge Retention and Growth

When you document solutions to problems you've solved, you're not just saving code – you're preserving the context and thinking behind your solution

package main
import (
"slices"
)
func main() {
}
func find_smallest(arr []int) int {