Skip to content

Instantly share code, notes, and snippets.

@Coutlaw
Coutlaw / tree.zig
Created November 4, 2025 14:16
Simple tree in Zig
const std = @import("std");
pub fn Node(comptime T: type) type {
return struct {
value: T,
left_child: ?*Node,
right_child: ?*Node,
const Self = @This();
@Coutlaw
Coutlaw / stack.zig
Last active October 27, 2025 14:06
Created a simple generic stack in Zig with an ArrayList
const std = @import("std");
const mem = std.mem;
const StackErrors = error{EmptyStack};
pub fn Stack(comptime T: type) type {
return struct {
items: std.ArrayList(T),
allocator: mem.Allocator,
@Coutlaw
Coutlaw / main.zig
Created October 23, 2025 09:55
First Zig program, executing bash from zig
const std = @import("std");
pub fn main() !void {
const allocator = std.heap.page_allocator;
const commands = &[_][]const u8{ "bash", "-c", "echo Hello from Bash" };
var child = std.process.Child.init(commands, allocator);
try child.spawn();
@Coutlaw
Coutlaw / generics.go
Last active December 17, 2021 17:42
Generics in Go
// This is a function to pull all the keys from a map and return them
// Its bad because it only works for strings right now
func getKeys(m map[string]int) []string {
var keys []string
for k := range m {
keys = append(keys, k)
}
return keys
}
.intercom-app,
.intercom-launcher-frame,
#intercom-container {
display: none !important;
}
button,
input,
optgroup,
select,
@Coutlaw
Coutlaw / reverse_prefix.go
Created November 29, 2021 22:00
reverse the prefix in a word, leetcode #2000 https://leetcode.com/problems/reverse-prefix-of-word/
/*
Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing.
For example, if word = "abcdefd" and ch = "d", then you should reverse the segment that starts at 0 and ends at 3 (inclusive). The resulting string will be "dcbaefd".
Return the resulting string.
Example 1:
@Coutlaw
Coutlaw / length_of_last_word.go
Last active November 29, 2021 21:58
Length of last word in a string, leetcode #58 https://leetcode.com/problems/length-of-last-word/
/*
Given a string s consisting of some words separated by some number of spaces, return the length of the last word in the string.
A word is a maximal substring consisting of non-space characters only.
Example 1:
Input: s = "Hello World"
@Coutlaw
Coutlaw / i32_reverser.rs
Last active June 7, 2020 11:41
leetcode: reverse i32 preventing overflow (rust)
/*
Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
Input: 123
Output: 321
Example 2:
@Coutlaw
Coutlaw / palindrome_i32.rs
Created June 6, 2020 11:43
leetcode: can find palindrome i32 (rust)
/*
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
Input: 121
Output: true
Example 2:
@Coutlaw
Coutlaw / merge_two_lists.rs
Last active August 31, 2022 01:51
Leetcode: Merge two sorted lists (Rust)
/*
Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists.
Example:
Input: 1->2->4, 1->3->4
Output: 1->1->2->3->4->4
*/