Skip to content

Instantly share code, notes, and snippets.

View BrandonClapp's full-sized avatar

Brandon Clapp BrandonClapp

View GitHub Profile
@BrandonClapp
BrandonClapp / gorm-example.go
Created October 24, 2022 03:01
gorm associations + CRUD
package main
import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
type Product struct {
gorm.Model
// gorm.Model adds ID, CreatedAt, UpdatedAt, DeletedAt
@BrandonClapp
BrandonClapp / embeded-fs-loop.go
Last active October 18, 2022 15:18
Loop over files in an embed FS
package main
import (
"embed"
"fmt"
"io/fs"
)
//go:embed template/*
var template embed.FS
// Simple Markdown Parser
// Write a function that accepts a string containing a simplified
// version of markdown-formatted text, and returns a string
// containing the corresponding HTML text. We only need to support
// headers, paragraphs, and unordered lists.
// For example, this markdown:
// # This is a title!
# Dictionary to store stream responses in
responses = {
"123": [],
"456": [],
}
# Dummy stream
port_123_stream = ["I am a line", "I like cake", "Turtles too"]
port_456_stream = ["Some other line", "Pizza party", "Puppy power"]
function anchorLinkHandler(e) {
const distanceToTop = el => Math.floor(el.getBoundingClientRect().top);
e.preventDefault();
const targetID = this.getAttribute("href");
const targetAnchor = document.querySelector(targetID);
if (!targetAnchor) return;
const originalTop = distanceToTop(targetAnchor);
window.scrollBy({ top: originalTop, left: 0, behavior: "smooth" });
@BrandonClapp
BrandonClapp / index.html
Last active August 29, 2015 14:18
Random Homepage
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<script src="redirect.js"></script>
</head>
<body>
<div>Blah</div>
</body>
</html>