Skip to content

Instantly share code, notes, and snippets.

package chainsaw
import (
"reflect"
"testing"
)
/*
goos: darwin
goarch: arm64
func stringIt(value interface{}) string {
switch v := value.(type) {
case nil:
return "<nil>"
case string:
return value.(string)
case []byte:
return string(value.([]byte))
case encoding.TextMarshaler:
return safeMarshal(value.(encoding.TextMarshaler))
package main
/*
This is an example of using the paho.golang (supporting MQTT5) library in a way where
the connect call will block and wait for the connection to go down.
I use something like this as I need to generate a TLS cert before each connect.
*/
import (
@perbu
perbu / error.go
Last active January 23, 2021 10:16
go-error-handling
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return forecast, err // return an error and let the caller handle it
}
err = json.Unmarshal(body, &forecast)
if err != nil {
log.Fatalf("error unmarshaling body %s: %s", url, err.Error())
}
forecast.Expires, err = http.ParseTime(res.Header.Get("Expires"))
if err != nil {
@perbu
perbu / filebeat.yum
Last active December 16, 2020 12:29
[elastic-7.x]
name=Elastic repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
package integration
import io.ktor.application.Application
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.TestApplicationEngine
import io.ktor.server.testing.handleRequest
import io.ktor.server.testing.withTestApplication
import ombruk.backend.module
import org.junit.Test
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-diamond-
spec:
entrypoint: diamond
templates:
- name: diamond
dag:
tasks:
#!/bin/zsh
#
# Auto activate a python virtualenv when entering the project directory.
# Installation:
# source virtualenv-auto-activate.sh
#
# Usage:
# Function `venvconnect`:
# Connect the currently activated virtualenv to the current directory.
#
function signalHandle(signal) {
console.log('Received signal ', signal);
server.em.emit("serverShutdown", "Shutdown initiated by signal "+signal);
}
process.on('SIGINT', signalHandle);
process.on('SIGTERM', signalHandle);
/*
This prints out A,B,C,D and E.
What is the order and what is printed after E:
*/
myAdd = (a, b) => {
return new Promise((resolve, reject) => {
resolve(a + b);
});