Skip to content

Instantly share code, notes, and snippets.

View hiway's full-sized avatar

Harshad Sharma hiway

View GitHub Profile
@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 / README.md
Last active April 23, 2024 13:12
Creating a single process FreeBSD (12.1) Jail

How to jail a single process web server on FreeBSD 12.1

You may have found many great resources on how to set up jails on latest FreeBSD, however there is scant information on how to go about creating a barebones jail with nothing but the one process that you want to isolate.

I was curious if I could contain a statically compiled web server that I wrote while learning Rust all by itself in a jail instead of having a full userland.

@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 / mr600.py
Created January 29, 2020 16:40
Fetch and save SMS from Tp-Link Archer MR600 4G Router using Selenium and Firefox to SQLite database.
#!/usr/bin/env python3
import datetime
import logging
import os
import peewee
import time
from collections import namedtuple
from selenium import webdriver
@hiway
hiway / pyqt5_macos_systray.py
Last active September 26, 2023 07:56
PyQt5 (Python3/ MacOS) System Tray application with KeyboardInterrupt (Ctrl+C) on terminal wired to Application > Quit.
import logging
import signal
import sys
from PyQt5 import QtGui, QtWidgets
logger = logging.getLogger(__name__)
def refresh(*args):
@hiway
hiway / auth.py
Last active July 20, 2023 15:56
A bare-minimum implementation of Twitter's Streaming API using python-requests library. Prints out tweets as they come in.
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
@hiway
hiway / README.md
Created July 2, 2023 06:50
Intermittent freezes/hangs - Fedora Linux 38 on Thinkpad X280
@hiway
hiway / pybble.py
Last active June 29, 2023 23:46
Python on Pebble. Yes. It works, with a bit of space to write a decent app and some heap memory to spare. AJAX works, as shown in code.
"""
pybble.py
Yup, you can run Python on your Pebble too! Go thank the good folks who
made Transcrypt, a dead-simple way to take your Python code and translate
it to *very* lean Javascript. In our case, instead of browser, we run it
on Pebble using their equally dead-simple Online IDE and Pebble.js library.
Here's a working example, it runs on a real Pebble Classic.
@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}")