Skip to content

Instantly share code, notes, and snippets.

@tomcam
tomcam / main.go
Created July 20, 2023 02:55
Demo program #2 for radvoskyb's recursive file watcher package with different order of events
// Minimalish, self-contained demo program for
// https://github.com/radovskyb/watcher
// slightly changed version of https://gist.github.com/tomcam/32760a5049a00ec6ba82bcb42b6759fc
//
// Here's what this code does.
// 1. Creates a small tree of files for a minimal website.
// 2. Places those files in the directory WWW (configurable).
// 3. Watches the WWW directory and its children.
// 4. Refreshes the web page when changes happen
//
@tomcam
tomcam / main.go
Created July 10, 2023 06:02
Demo program for radvoskyb's recursive file watcher package
// Minimalish, self-contained demo program for
// https://github.com/radovskyb/watcher
//
// Here's what this code does.
// 1. Creates a small tree of files for a minimal website.
// 2. Places those files in the directory WWW (configurable).
// 3. Watches the WWW directory and its childrens.
//
// To use it:
// 1. Open up a terminal
@tomcam
tomcam / main.go
Created July 9, 2023 20:06
Generate tree of text files in Go
// Create a small tree of files for a minimal website.
// Run program then open the file WWW/index.html
package main
import (
"os"
"path/filepath"
)
var (
@tomcam
tomcam / dl.go
Last active September 13, 2022 08:02
dl.go - Lists directories in Go. Simplest use of Golang's filepath.Walk() with easily reusable code. golang list directories recursive.
// dl displays a list of directories. Starts at current dir unless
// another is given on the command line. Counts theme.
// Naively written; doesn't do a good job when you don't have
// the right permissions.
// Usage:
// dl [directory]
package main
import (
@tomcam
tomcam / trailingsep.go
Created December 25, 2021 02:02
Golang filepath.Join removes a trailing path separator
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
// golang removes thet trailing path separator.
@tomcam
tomcam / structtomap1.go
Last active October 26, 2021 19:30
Go/Golang: writes a struct to a YAML file, then reads it back from the YAML as a map using the gopkg.in/yaml package
package main
import (
"fmt"
"io/ioutil"
"gopkg.in/yaml.v3"
"os"
)
type Theme struct {
@tomcam
tomcam / listEmbeddedDir
Created October 20, 2021 20:04
Go embed example:/Golang embed tutorial: Embed subdirectory of files at compile time, then display names at runtime
package main
import (
"embed"
"fmt"
"io/fs"
)
// The following embeds all files and subdirectories
// from the themes subdirectory of this package into
@tomcam
tomcam / g.go
Created October 12, 2021 23:30
Self-contained demonstration of the outstanding Goldmark markdown converter package
// Demonstrates the goldmark Markdown to HTML converter.
// Reads name of input file from command line, or creates a
// simple Markdown source file named "foo.md".
// Calls goldmark to convert it to HTML.
// Displays results to standard output.
package main
import (
"bytes"
"fmt"
@tomcam
tomcam / controllers.py
Last active December 4, 2020 09:58
py4web crud example in progress
from py4web import action, request, abort, redirect, URL
from yatl.helpers import A
from .common import db, session, T, cache, auth, logger, authenticated, unauthenticated
from py4web import Field
from py4web.utils.form import Form
from py4web import response
@action('index')
@action.uses(auth, 'index.html')
@tomcam
tomcam / drs.sh
Created February 17, 2020 03:23
zsh list normal directories
#!/bin/zsh
ls -d */