package main
import (
"bufio"
"compress/gzip"
"log"
"os"
This file contains hidden or 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
// Check to see if the program is already running. returns true if it is or false if it is not. | |
func amIrunning(myname string) bool { | |
currentpid := os.Getpid() // Get the current process ID | |
currentpidStr := strconv.Itoa(currentpid) // Convert the current process ID to a string | |
cmd := exec.Command("ps", "aux") // Run the ps aux command to get a list of all running processes | |
out, err := cmd.CombinedOutput() // Get the output of the command, both srtdout and stderr | |
if err != nil { | |
ErrorLogger.Println("Error running ps aux", err) |
This file contains hidden or 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( | |
"fmt" | |
"os" | |
) | |
func main() { | |
if fileExists("sample.txt") { | |
fmt.Println("sample file exists") | |
} else { | |
fmt.Println("sample file does not exist") |
This file contains hidden or 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 <[email protected]> http://defineanswer42.wordpress.com | |
* Release 2014-04-04 | |
* | |
* Based on Richard W.M. Jones' excellent Jonesforth sources/tutorial | |
* | |
* PUBLIC DOMAIN | |
* |
This file contains hidden or 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 hidden or 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 hidden or 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)