Skip to content

Instantly share code, notes, and snippets.

Zach Peters zpeters

Block or report user

Report or block zpeters

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View apcupsd-influx.py
#!/usr/bin/env python3
import subprocess
OUTPUT = subprocess.run(['/usr/sbin/apcaccess'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
d = dict()
for item in OUTPUT.splitlines():
s = item.split(":")
k = s[0].strip()
v = s[1].strip()
@zpeters
zpeters / AmIPwned.ex
Last active Oct 30, 2018
Example Pwned
View AmIPwned.ex
defmodule ExHaveibeenpwned do
@moduledoc """
https://haveibeenpwned.com/API/v2
get_all_for_account("test@example.com", [truncateresponse: true, domain: "google.com"])
"""
use Tesla
plug Tesla.Middleware.BaseUrl, "https://haveibeenpwned.com/api/v2"
plug Tesla.Middleware.Headers, [
{"User-Agent", "ex_haveibeenpwned"}
@zpeters
zpeters / more.go
Created Oct 28, 2018
More examples
View more.go
func main() {
var rootCmd = &cobra.Command{}
rootCmd.AddCommand(cmdVersion)
rootCmd.Execute()
}
var cmdVersion = &cobra.Command{
Use: "version",
Short: "Get the current version",
Run: func(cmd *cobra.Command, args []string) {
View uploadfile.go
func uploadFile(p serial.Port, filename string) (err error) {
log.Printf("Uploading file: %s\n", filename)
_, destFileName := filepath.Split(filename)
log.Printf("Destination name: %s\n", destFileName)
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
defer file.Close()
View sendcommand.go
func sendCommand(p serial.Port, cmd string) (out string, err error) {
err = writeSerial(p, cmd)
_ = readSerial(p)
out = readSerial(p)
return out, err
}
View readserial.go
func readSerial(p serial.Port) string {
buf := make([]byte, 1024)
r, err := p.Read(buf)
if err != nil {
log.Printf("Can't read from serial port\n")
log.Fatal(err)
}
return strings.TrimSpace(string(buf[:r]))
}
@zpeters
zpeters / readwrite.go
Created Oct 28, 2018
Read/write to wifimcu
View readwrite.go
package main
import "github.com/tarm/serial"
import "log"
func main() {
c := &serial.Config{Name: "/dev/ttyUSB0", Baud: 115200}
s, err := serial.OpenPort(c)
if err != nil {
log.Fatal(err)
@zpeters
zpeters / writefile.lua
Created Oct 28, 2018
Example write file lua
View writefile.lua
file.open("test.lua","w+")
file.writeline("print('hello world!')");
file.close()
View webex_teams.ex
## TODO this is gross
defp maybe_retry(response) do
if response.status_code == 429 do
Logger.debug fn -> "*** Got a Retry-After ***" end
m = Enum.into(response.headers, %{})
if Map.has_key?(m, "Retry-After") do
retry = Map.fetch!(m, "Retry-After")
wait_time = String.to_integer(retry)
Logger.debug fn -> "Retry after seconds #{wait_time}" end
@zpeters
zpeters / webex_teams.ex
Created Oct 6, 2018
http get function with a check for retry
View webex_teams.ex
def get(path) do
url = generate_url(path)
headers = generate_headers()
options = []
response = HTTPoison.get!(url, headers, options)
Logger.debug fn -> "Get Response: #{inspect(response)}" end
if maybe_retry(response) do
get(path)
end
You can’t perform that action at this time.