Skip to content

Instantly share code, notes, and snippets.

@farshidtz
farshidtz / custom_error.go
Last active May 22, 2020 18:19
Return error message along with a type. https://play.golang.org/p/9QsCFPXv_vV
package main
import (
"errors"
"fmt"
"strings"
)
// Simple errors
type NotFoundError struct{ s string }
@farshidtz
farshidtz / time_prefix_logger.go
Last active August 15, 2018 12:06
Go logger with prefix after the timestamp
package main
import (
"io"
"log"
"os"
"time"
)
type writer struct {
@farshidtz
farshidtz / docker-container-events.go
Last active July 31, 2019 15:27
Getting container events from Docker SDK
package main
import (
"context"
"fmt"
"log"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
@farshidtz
farshidtz / watchdog-network.sh
Last active July 18, 2020 09:56
A watchdog script to monitor the network connectivity (ping status) and reboot when there is no connection
# A watchdog script to monitor the ping status and reboot the device
# when there is no connection after a specified number of tries.
#!/bin/sh
echo '\nStarted watchdog script.'
address=8.8.8.8 # or a local gateway address
max=5 # number of retries before reboot
interval=120 # seconds between each retry
{
"id": "https://tools.ietf.org/rfc/rfc7807.txt",
"$schema": "http://json-schema.org/draft-06/schema#",
"description": "schema for a rfc7807",
"definitions": {
"validation": {
"type": "object",
"required": [
"type"
],
{
"@context": {
"tdd": "https://www.w3.org/2019/wot/tdd#",
"schema": "https://schema.org/",
"registration": "tdd:registration",
"ttl": "tdd:ttl",
"expires": "schema:expires"
}
}
@farshidtz
farshidtz / td-example.jsonld
Last active January 20, 2021 13:21
Namespaces defined in additional context
{
"@context":[
"https://www.w3.org/2019/wot/td/v1",
"https://gist.githubusercontent.com/farshidtz/41f71668a113843cddec8e1593653303/raw/97ddfeb58adad8aecf5a810778ce0c8b37dca36d/tdd-context.jsonld"
],
"security":"nosec",
"securityDefinitions":{
"nosec":{
"scheme":"no_sec"
}
{
"@context": [
"https://www.w3.org/2019/wot/td/v1",
{
"tdd": "https://www.w3.org/2021/wot/discovery#"
}
],
"@type": "tdd:Directory",
"id": "urn:uuid:262bd21d-8c74-4ba6-a2b5-9a2da6061b0c",
"security": "basic_sc",
{
"@context": {
"discovery": "https://www.w3.org/2021/wot/discovery#",
"tdd": "https://www.w3.org/2021/wot/discovery#",
"DirectoryDescription": {
"@id": "discovery:DirectoryDescription"
},
"LinkDescription": {
"@id": "discovery:LinkDescription"
}
@farshidtz
farshidtz / vpc-base.tf
Last active March 19, 2021 15:02
Three ways to define AWS VPC routing table and association with subnet and internet gateway using Terraform.
# Create a VPC, It comes with a default (automatically created route table)
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/24"
enable_dns_support = true
enable_dns_hostnames = true
enable_classiclink = false
instance_tenancy = "default"
tags = {