Skip to content

Instantly share code, notes, and snippets.

View rustyeddy's full-sized avatar
💭
Hacking

Rusty Eddy rustyeddy

💭
Hacking
View GitHub Profile
@rustyeddy
rustyeddy / macaddr.cc
Created October 25, 2022 23:51
Get MAC address on Linux
int getMacAddr(std::string ifname, char *macaddr) {
// need to open a socket to read the mac address
int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock == -1) {
auto err = std::string(strerror(errno));
return Status::UnknownError("failed to open socket" + err);
}
struct ifreq ifr;
strcpy(ifr.ifr_name, ifname.c_str());
# Workflow to build and deploy site to Github Pages using Hugo
# Name of Workflow
name: github pages
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
package main
import (
"flag"
"log"
)
type Configuration struct {
Broker string `json:"broker"`
Addr string `json:"Addr"
@rustyeddy
rustyeddy / mqtt.go
Created March 26, 2022 22:03
Adding MQTT to a Go program
package main
import (
"fmt"
"log"
"os"
mqtt "github.com/eclipse/paho.mqtt.golang"
)
var (
// Start Video opens the camera (sensor) and data (vidoe) starts streaming in.
// We will be streaming MJPEG for our initial use case.
func (vid *VideoPlayer) StartVideo() {
var err error
var buf []byte
l.Info("StartVideo Entered ... ")
defer l.Info("StartVideo Finished")
@rustyeddy
rustyeddy / echo_server.py
Created June 13, 2019 14:29
Echo Server in Python
import socket
def server(host, port):
sock = socket.socket()
sock.bind((host, port))
sock.listen(2)
print(f'Server up and listening on {host} {port}')
@rustyeddy
rustyeddy / led.cpp
Created May 19, 2019 20:35
esp32 C++ Program
#pragma once
class LED {
private:
gpio_num_t _pin = GPIO_NUM_0;
gpio_mode_t _mode = GPIO_MODE_OUTPUT;
int _state = 0;
public:
LED(gpio_num_t p);
@rustyeddy
rustyeddy / blinker.cpp
Created May 19, 2019 20:31
ESP32 C++ main_app
// ====================================================================
const int STACK_SIZE = 256;
const gpio_num_t LED_RED = GPIO_NUM_22;
const gpio_num_t LED_GREEN = GPIO_NUM_23;
// GLobal LEDs
// ====================================================================
LED red = LED(LED_RED);
LED green = LED(LED_GREEN);
class LED {
private:
gpio_num_t _pin = GPIO_NUM_0;
gpio_mode_t _mode = GPIO_MODE_OUTPUT;
int _state = 0;
public:
LED(gpio_num_t p);
void set(int val);
@rustyeddy
rustyeddy / timestamp.go
Last active September 5, 2024 07:44
Go filename friendly RFC3339 inspired timestamps
// GetTimeStamp returns a timestamp in a file name friendly, version of the RFC3339
// format. The string produced by RFC3339 includes a couple colons ':' that are not
// friendly to most filenames (unix and dos a like). The colons need to be escaped
// if used in a filename, since they are useless, we'll rip em.
func TimeStamp() string {
ts := time.Now().UTC().Format(time.RFC3339)
return strings.Replace(ts, ":", "", -1) // get rid of offensive colons
}