package main
import (
"bufio"
"compress/gzip"
"log"
"os"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************* | |
* | |
* 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 | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
// 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)