Skip to content

Instantly share code, notes, and snippets.

View lmllrjr's full-sized avatar
🥬

Lukas Moeller lmllrjr

🥬
View GitHub Profile
@lmllrjr
lmllrjr / slice_of_pointers.go
Created January 19, 2023 10:13
Create/use a pointer to a slice of pointers
// Check it out in go playground:
// https://go.dev/play/p/4FJZ7109K4U
package main
import "fmt"
func main() {
p := NewPointers()
fmt.Printf("\nthe complete pointer to slice of pointers (c): %#v\n", p)
@lmllrjr
lmllrjr / setup_global_gitignore.md
Created February 8, 2023 12:42
Setup a global `.gitignore` file

To prevent adding/commiting/pushing unwanted files, like for example .DS_Store, one should have a global gitignore file. Here is how you can set it up:

  • Use the following command to set up a global gitignore:
    git config --global core.excludesFile '~/.gitignore_global'
    The command above will write/create the following lines in the existing ~/.gitconfig:

[core]

@lmllrjr
lmllrjr / go.mod
Last active February 9, 2023 12:46
Import a specific branch of a forked repo into Go code
module github.com/<username>/<reponame>
go 1.19
require (
github.com/<username>/pkg v0.7.0
)
// Order will matter here
replace github.com/<username>/pkg v0.7.0 => github.com/<username>/pkg v0.7.1
@lmllrjr
lmllrjr / example.proto
Last active February 26, 2023 09:36
Example gRPC proto file
syntax = "proto3";
// https://github.com/protocolbuffers/protobuf/blob/c0bd3dd984399d3302a8f7cf69e7c9330b362ac4/src/google/protobuf/timestamp.proto#L133-L144
import "google/protobuf/timestamp.proto";
option go_package = "github.com/<user>/<repo>/pkg/pb";
package pb;
// The profile service definition
@lmllrjr
lmllrjr / di.go
Created March 19, 2023 17:24
Dependency injection go
// You can edit this code!
// Click here and start typing.
package main
import "fmt"
func main() {
msgRepo := Message{
MSG: "Hello there friends",
}
@lmllrjr
lmllrjr / main.rs
Last active June 4, 2023 00:38
Rust server with regex-table routing and basic auth.
use base64::{engine::general_purpose, Engine as _};
use regex::Regex;
use std::{
io::{prelude::*, BufReader},
net::{TcpListener, TcpStream},
str,
};
fn main() -> std::io::Result<()> {
let listener = TcpListener::bind("127.0.0.1:6969")?;
@lmllrjr
lmllrjr / settings.json
Last active July 1, 2023 23:54
Zed settings file
// Zed settings
//
// For information on how to configure Zed, see the Zed
// documentation: https://zed.dev/docs/configuring-zed
//
// To see all of Zed's default settings without changing your
// custom settings, run the `open default settings` command
// from the command palette or from `Zed` application menu.
{
"theme": "Solarized Dark",
@lmllrjr
lmllrjr / get_user_input.zig
Created June 4, 2023 14:31
[Zig⚡️] get user input
const std = @import("std");
const stdout = std.io.getStdOut().writer();
const stdin = std.io.getStdIn().reader();
pub fn main() anyerror!void {
var buf = std.io.bufferedReader(stdin);
// Get the Reader interface from BufferedReader
var r = buf.reader();
@lmllrjr
lmllrjr / bazighttp.zig
Last active June 4, 2023 19:50
[Zig⚡️] basic http server with multiplexer
// zig version 0.10.1
const std = @import("std");
const net = std.net;
const mem = std.mem;
const log = std.log;
const stdout = std.io.getStdOut().writer();
const BUFSIZE = 8192;
const HTTPHEAD =
@lmllrjr
lmllrjr / updategist.zig
Created July 16, 2023 11:21
[Zig⚡️] update a gist
const std = @import("std");
const http = std.http;
const Client = http.Client;
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const calloc = gpa.allocator();
pub fn main() !void {
// get token and gist id from .envrc file (get ENV VAR)
const token = std.os.getenv("GH_TOKEN") orelse "";