Skip to content

Instantly share code, notes, and snippets.

View misterunix's full-sized avatar
😁
Hey, drop me an email if you like!

Bill Jones misterunix

😁
Hey, drop me an email if you like!
View GitHub Profile
@misterunix
misterunix / lbForth.c
Created April 29, 2024 01:38 — forked from lbruder/lbForth.c
A minimal Forth compiler in ANSI C
/*******************************************************************************
*
* A minimal Forth compiler in C
* By Leif Bruder <leifbruder@gmail.com> http://defineanswer42.wordpress.com
* Release 2014-04-04
*
* Based on Richard W.M. Jones' excellent Jonesforth sources/tutorial
*
* PUBLIC DOMAIN
*
// copied from https://gist.github.com/unakatsuo - thank you
// IterateIPRange calculates the sequence of IP address from beginAddr to endAddr
// then calls the callback cb for each address of the sequence.
// beginAddr value must be smaller than endAddr.
func IterateIPRange(beginAddr, endAddr net.IP, cb func(addr net.IP)) error {
incIP := func(ip net.IP) net.IP {
for j := len(ip) - 1; j >= 0; j-- {
ip[j]++
if ip[j] > 0 {
break
@misterunix
misterunix / seconds2weeks.go
Created April 26, 2024 02:47
I run some very long tasks and I like to know how long they ran.
// Convert seconds to days, hours, minutes and seconds
func Seconds2Weeks(s float64) string {
var result string
si := int(s)
weeks := si / (7 * 24 * 3600) // get weeks from seconds
si = si % (7 * 24 * 3600)
day := si / (24 * 3600) // get days from seconds
@misterunix
misterunix / 1000separator.go
Created May 5, 2023 13:10
Pretty print, add 1000s separator.
package main
import (
"golang.org/x/text/language"
"golang.org/x/text/message"
)
func main() {
p := message.NewPrinter(language.English)
p.Printf("%d\n", 1000)

load a gzip compressed file in to a slice, line by line.

package main

import (
	"bufio"
	"compress/gzip"
	"log"
	"os"
@misterunix
misterunix / gist:3ace3b5a7e3afb94ceb617193be0e2e2
Last active February 12, 2023 00:23
Convert seconds into a readable time string.

Convert elapsed seconds into a nicely formatted string.

// Convert seconds into a readable time. This is not for real time, only for elapsed time. 
func TimeStr(sec int) (res string) {
	wks, sec := sec/604800, sec%604800
	ds, sec := sec/86400, sec%86400
	hrs, sec := sec/3600, sec%3600
	mins, sec := sec/60, sec%60
	res += fmt.Sprintf("%02dw:", wks)
	res += fmt.Sprintf("%02dd:", ds)