Skip to content

Instantly share code, notes, and snippets.

View hiway's full-sized avatar

Harshad Sharma hiway

View GitHub Profile
@hiway
hiway / config_validate.ex
Last active April 15, 2024 11:33
Elixir snippets for writing libraries
defmodule ConfigValidate do
def ensure_value_is_not_nil(key, value, suggestion) do
if value == nil do
raise """
Please set #{key} under mix.exs project configuration.
def project do
[
...
#{suggestion}
@hiway
hiway / freedive.ex
Created April 11, 2024 22:42
Elixir module to execute commands on FreeBSD, using doas and inside jails.
defmodule Freedive do
@moduledoc """
Freedive: Dive into FreeBSD.
"""
@doas_path "/usr/local/bin/doas"
@jexec_path "/usr/sbin/jexec"
@env_path "/usr/bin/env"
@env_path_var "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
@doc """
@hiway
hiway / README.md
Created July 2, 2023 06:50
Intermittent freezes/hangs - Fedora Linux 38 on Thinkpad X280
@hiway
hiway / main.py
Last active June 17, 2023 20:20
Quasar Rating element for NiceGUI
#!/usr/bin/env python3
from nicegui import Client, ui
from rating import Rating
@ui.page("/")
async def main(client: Client):
def score_changed(event):
stars = int(event['args'])
wid_rating.props(f"value={stars}")
@hiway
hiway / freebsd-tailscale-vpn.sh
Last active April 23, 2024 13:35
Script to set up FreeBSD 13 VPS as a Tailscale VPN Exit Node
#!/bin/sh
#
# freebsd-tailscale-vpn.sh
#
# MIT License
#
# Copyright (c) 2023 Harshad Sharma
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@hiway
hiway / quartsio.py
Created April 3, 2023 07:13
Python Quart + SocketIO Async Server
import asyncio
import socketio
import uvicorn
from quart import Quart
from quart_cors import cors
CORS_ALLOWED_ORIGINS = "*"
@hiway
hiway / example_hasspy_tplink_4g_modem.py
Last active March 13, 2023 23:20
Example Python program to publish text messages received on a TP-Link MR200 4G modem to Home Assistant. Note: this example is incomplete as the modules "hasspy" and "tplink_mr200" have not been released yet.
@hiway
hiway / Caddyfile
Last active November 20, 2022 09:01
Caddyfile for Mastodon 3.x and 4.x that also maps @username@example.com -> @username@mastodon.example.com
example.com {
header /.well-known/host-meta Access-Control-Allow-Origin *
respond /.well-known/host-meta `https://mastodon.example.com{uri}`
@webfinger {
path /.well-known/webfinger*
}
reverse_proxy @webfinger {
to http://localhost:3000
@hiway
hiway / mastodon_domain_blocks.py
Last active November 9, 2022 19:54
Mastodon Domain Blocks WebUI
"""
# Mastodon Domain Blocks
## Install
```
python -m venv venv
source venv/bin/activate
pip install click mastodon.py streamlit watchdog
@hiway
hiway / ssh-keygen.py
Last active October 28, 2022 21:17
Streamlit Demo - WebUI to generate/access SSH key-pairs for hosts.
from pathlib import Path
from typing import List
import pyperclip
import streamlit as st
from plumbum import local
SSH_KEYS_DIR = "~/.ssh/keys"
# --- API ---