Skip to content

Instantly share code, notes, and snippets.

@erwiese
erwiese / cmd-start.go
Created November 15, 2018 12:52
run command and pip stdout to file
// Rnx2crx creates a copy of the file that is Hatanaka-compressed (compact RINEX).
// see http://terras.gsi.go.jp/ja/crx2rnx.html
func Rnx2crx(obsFil string) (string, error) {
tool, err := exec.LookPath("RNX2CRX")
if err != nil {
return "", err
}
if !strings.HasSuffix(obsFil, ".rnx") {
return "", fmt.Errorf("file %s with invalid extension", obsFil)
@erwiese
erwiese / io.go
Created July 25, 2019 08:31
io related things
import "bufio"
import "bytes"
func main() {
// Get a new writer
var b bytes.Buffer
w := bufio.NewWriter(&b)
@erwiese
erwiese / javascript.js
Last active January 20, 2020 12:16
javascript/jquery recipes
// Convert array to object
var rnxSearch = formDataArray.reduce(function (o, val) { o[val.name] = val.value; return o; }, {});
// Round float
return Number(myfloat).toFixed(2);
/**************************************************
Forms
***************************************************/
// Check a radio
@erwiese
erwiese / loadinfo.sh
Created September 8, 2020 09:56
Who puts the load on my machine
#!/bin/bash
# who swaps?
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
@erwiese
erwiese / check-http.sh
Last active November 26, 2022 03:43
Monitor a HTTP service, search for strings and reports connection times
#!/bin/bash
# Check availability and response time for a website
# Output is in InfluxDB line protocol
measurement="http.stat"
function dorequest () {
local url=$1
local chkstr=$2
@erwiese
erwiese / readNonUTF8.go
Created December 19, 2023 12:50
Read text that is not utf-8 encoded
// https://go.dev/blog/strings
// https://henvic.dev/posts/go-utf8/
// https://pkg.go.dev/github.com/saintfish/chardet
f, err := os.Open("testdata/tor300est_20230726.log")
if err != nil {
return err
}
defer f.Close()