Skip to content

Commit

Permalink
nix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Lillecarl committed Dec 9, 2024
1 parent 9e1212a commit fd0d827
Show file tree
Hide file tree
Showing 22 changed files with 108 additions and 127 deletions.
6 changes: 4 additions & 2 deletions nixvim/plugins/lsp/lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@
"http://json.schemastore.org/ansible-playbook" = "*play*.{yml,yaml}";
"http://json.schemastore.org/chart" = "Chart.{yml,yaml}";
"https://json.schemastore.org/dependabot-v2" = ".github/dependabot.{yml,yaml}";
"https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json" = "*docker-compose*.{yml,yaml}";
"https://raw.githubusercontent.com/argoproj/argo-workflows/master/api/jsonschema/schema.json" = "*flow*.{yml,yaml}";
"https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json" =
"*docker-compose*.{yml,yaml}";
"https://raw.githubusercontent.com/argoproj/argo-workflows/master/api/jsonschema/schema.json" =
"*flow*.{yml,yaml}";
};
};
};
Expand Down
6 changes: 2 additions & 4 deletions nixvim/plugins/utils/extra_plugins.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{ pkgs, ... }:
{
extraPlugins =
with pkgs.vimPlugins;
[
];
extraPlugins = with pkgs.vimPlugins; [
];
}
10 changes: 3 additions & 7 deletions scripts/batmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

notify_send = local["notify-send"]


@dataclass
class State:
lastNotify: float
lastPct: int


class Runner:
def __init__(self):
self.state = State(0, 0)
Expand All @@ -38,12 +40,7 @@ def spin(self):
self.state.lastNotify = time()

def notify(self, seconds, percentage):
notify_send[
"-t",
f"{seconds * 1000}",
"Low battery",
f"Battery {percentage}"
]()
notify_send["-t", f"{seconds * 1000}", "Low battery", f"Battery {percentage}"]()

self.state.lastNotify = time()

Expand All @@ -56,4 +53,3 @@ def is_discharging(self):

if __name__ == "__main__":
exit(Runner().spin())

17 changes: 8 additions & 9 deletions scripts/ecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@
for i in evdev.ecodes.keys.items():
if type(i[1]) is list:
for j in i[1]:
keys.append((i[0],j))
keys.append((i[0], j))
else:
keys.append((i[0],i[1]))
keys.append((i[0], i[1]))

keys = sorted(keys, key=lambda x: x[0])


#print(r"class Keys(IntEnum):")
#for i in keys:
# print(r"class Keys(IntEnum):")
# for i in keys:
# print(f" {i[1]} = {i[0]}")

#for k,v in evdev._ecodes.__dict__.items():
# for k,v in evdev._ecodes.__dict__.items():
# if k.startswith("__"):
# continue
# print(k,v)

#for k,v in evdev.ecodes.bytype.items():
# for k,v in evdev.ecodes.bytype.items():
# print(k,v)

for k,v in evdev._ecodes.__dict__.items():
for k, v in evdev._ecodes.__dict__.items():
if not k.startswith("EV_"):
continue
print(k,v)

print(k, v)
18 changes: 12 additions & 6 deletions scripts/fancontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
fanpath = local.path("/proc/acpi/ibm/fan")
_lastwrite = time()


def setwatchdog():
# Set timeout to 120 (fallback to auto fan)
fanpath.write("watchdog 120")


def getlevel():
faninfo: str = fanpath.read()
faninfolines = faninfo.splitlines()
fanlevel = None


for line in faninfolines:
regex = r"^level:\s*(.*)$"
matches = re.match(regex, line)
Expand Down Expand Up @@ -62,14 +63,17 @@ def setlevel(level: int, force: bool = False):

return True


def gettemp():
sensordata: dict[str, dict] = json.loads(sensors["-j"]())
return float(sensordata["thinkpad-isa-0000"]["CPU"]["temp1_input"])


def getspeed():
sensordata: dict[str, dict] = json.loads(sensors["-j"]())
return float(sensordata["thinkpad-isa-0000"]["fan1"]["fan1_input"])


def setfan(cpu_avg: float):
level = getlevel()
temp = gettemp()
Expand All @@ -90,6 +94,7 @@ def setfan(cpu_avg: float):
else:
return setlevel(level - 1)


def main():
setwatchdog()
watchdog_counter: int = 0
Expand All @@ -101,11 +106,11 @@ def main():
while True:
sleep(1)
cpu_pct = cpu_percent()
print("cpu_pct: {} fan_counter: {} watchdog_counter {}".format(
cpu_pct,
fan_counter,
watchdog_counter
))
print(
"cpu_pct: {} fan_counter: {} watchdog_counter {}".format(
cpu_pct, fan_counter, watchdog_counter
)
)

fan_counter += 1
watchdog_counter += 1
Expand All @@ -122,5 +127,6 @@ def main():
setlevel(getlevel(), True)
watchdog_counter = 0


if __name__ == "__main__":
exit(main())
8 changes: 4 additions & 4 deletions scripts/fd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import os

with os.fdopen(1, 'w') as fdfile:
with os.fdopen(1, "w") as fdfile:
fdfile.write("written to fd 1\n")
fdfile.close()
with os.fdopen(2, 'w') as fdfile:
with os.fdopen(2, "w") as fdfile:
fdfile.write("written to fd 2\n")
fdfile.close()
with os.fdopen(3, 'w') as fdfile:
with os.fdopen(3, "w") as fdfile:
fdfile.write("written to fd 3\n")
fdfile.close()
with os.fdopen(4, 'w') as fdfile:
with os.fdopen(4, "w") as fdfile:
fdfile.write("written to fd 4\n")
fdfile.close()
15 changes: 8 additions & 7 deletions scripts/niricfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from pathlib import Path
from jinja2 import Environment, PackageLoader, select_autoescape


def main():
env = Environment(
loader=PackageLoader('niricfg', 'templates'),
loader=PackageLoader("niricfg", "templates"),
autoescape=select_autoescape(),
lstrip_blocks=True,
trim_blocks=True,
Expand All @@ -17,18 +18,17 @@ def main():
while True:
time.sleep(1)

template = env.get_template('niricfg.j2')
template = env.get_template("niricfg.j2")

hostname = socket.gethostname()
keyboard = "AT Translated Set 2 keyboard"
if hostname == "shitbox":
keyboard = "daskeyboard"


info = {
'hostname': socket.gethostname(),
'keyboard': keyboard,
'displays': [],
"hostname": socket.gethostname(),
"keyboard": keyboard,
"displays": [],
}

path = Path("~/.config/niri/config.kdl").expanduser()
Expand All @@ -40,5 +40,6 @@ def main():
print("Writing new config.")
path.write_text(new_conf)

if __name__ == '__main__':

if __name__ == "__main__":
main()
14 changes: 9 additions & 5 deletions scripts/remapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ def get_input_device(name: str, verbose: bool = True):
if device.name == name:
if verbose:
print(f"Found device: {device}")
#print(f"Leds: {device.leds(verbose=True)}")
#print(f"Capabilities: {device.capabilities(verbose=True)}")
# print(f"Leds: {device.leds(verbose=True)}")
# print(f"Capabilities: {device.capabilities(verbose=True)}")
return device

if verbose:
Expand Down Expand Up @@ -579,7 +579,9 @@ async def handle_macropad_input_events():
print(f"event: {util.categorize(event)}")
print(f"Macropad active keys: {mdev.active_keys(verbose=True)}")
print(f"last_key_up_code: {last_key_up_code}, event.code: {event.code}")
print(f"last_key_up_time: {last_key_up_time} diff: {time.time() - last_key_up_time}")
print(
f"last_key_up_time: {last_key_up_time} diff: {time.time() - last_key_up_time}"
)

if (
True
Expand All @@ -590,19 +592,23 @@ async def handle_macropad_input_events():
):
if macropad_attach:
print("Attaching devices")

async def attach():
await attach_device(f"{base_path}/daskeyboard.xml")
await attach_device(f"{base_path}/steelseries-sensei.xml")
await attach_device(f"{base_path}/logitech-g933.xml")

if usb_xtach_task is None or usb_xtach_task.done():
usb_xtach_task = loop.create_task(attach())
macropad_attach = False
else:
print("Detaching devices")

async def detach():
await detach_device(f"{base_path}/logitech-g933.xml")
await detach_device(f"{base_path}/daskeyboard.xml")
await detach_device(f"{base_path}/steelseries-sensei.xml")

if usb_xtach_task is None or usb_xtach_task.done():
usb_xtach_task = loop.create_task(detach())
macropad_attach = True
Expand Down Expand Up @@ -702,8 +708,6 @@ async def handle_input_events():
and event.value == Action.DOWN
and time.time() - key_state[State.UPTIME] < 0.5
):


if in_key_active(Keys.LEFTMETA):
gaming_mode = not gaming_mode
print(f"Gaming mode: {'on' if gaming_mode else 'off'}")
Expand Down
1 change: 1 addition & 0 deletions scripts/remapper_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import json


class MiddleMan:
send = asyncio.Transport
recv = asyncio.Transport
Expand Down
8 changes: 4 additions & 4 deletions scripts/vram.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env fish
while true;
date | tee -a /tmp/vram.log;
nix run "nixpkgs#amdgpu_top" -- -d | rg "^VRAM.*usage" -A 3 | tee -a /tmp/vram.log;
sleep 5;
while true
date | tee -a /tmp/vram.log
nix run "nixpkgs#amdgpu_top" -- -d | rg "^VRAM.*usage" -A 3 | tee -a /tmp/vram.log
sleep 5
end
43 changes: 22 additions & 21 deletions scripts/vram.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
hyprctl = local["hyprctl"]

process = amdgpu_top.popen(
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
bufsize=0,
universal_newlines=True
)
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
bufsize=0,
universal_newlines=True,
)

error = False

while True:
output_line = process.stdout.readline() # type: ignore
if output_line == '' and process.poll() is not None:
if output_line == "" and process.poll() is not None:
break
if output_line:
data = json.loads(output_line)
Expand All @@ -35,31 +35,32 @@

vram_usage_str = ""

for k,v in data["fdinfo"].items():
pattern = r'\((\d+)\)' # Matches an integer inside parentheses
match = re.search(r'\((\d+)\)', k)
for k, v in data["fdinfo"].items():
pattern = r"\((\d+)\)" # Matches an integer inside parentheses
match = re.search(r"\((\d+)\)", k)
procname = k
if match:
if proc := psutil.Process(int(match.group(1))):
procname = proc.cmdline()[0]

vram_usage_str += "{}VRAM: {}, cmd: {}".format(linesep, v["usage"]["VRAM"]["value"], procname)
vram_usage_str += "{}VRAM: {}, cmd: {}".format(
linesep, v["usage"]["VRAM"]["value"], procname
)

if free_vram < total_vram * 0.15:
error = True
print("Setting hyprctl error")
hyprctl[
"seterror",
"rgba(FF0000FF)",
"Free fram is running low, {}% used{}".format(
used_vram / total_vram,
vram_usage_str
),
]()
"seterror",
"rgba(FF0000FF)",
"Free fram is running low, {}% used{}".format(
used_vram / total_vram, vram_usage_str
),
]()
elif error:
error = False
print("Unsetting hyprctl error")
hyprctl[
"seterror",
"disable",
]()
"seterror",
"disable",
]()
14 changes: 7 additions & 7 deletions tf/dns/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ locals {

resource "cloudflare_record" "example" {
for_each = local.zones
zone_id = each.value.id
name = "terraform"
value = "192.0.2.1"
type = "A"
ttl = 3600
zone_id = each.value.id
name = "terraform"
value = "192.0.2.1"
type = "A"
ttl = 3600
}

module "o365" {
source = "./o365"
source = "./o365"
zone_id = local.zones["lillecarl.com"].id
mx = "lillecarl-com.mail.protection.outlook.com"
mx = "lillecarl-com.mail.protection.outlook.com"
}
Loading

0 comments on commit fd0d827

Please sign in to comment.