Skip to content

Instantly share code, notes, and snippets.

View pedrovhb's full-sized avatar

Pedro Batista pedrovhb

View GitHub Profile
@pedrovhb
pedrovhb / hl-code.html
Last active August 13, 2024 15:38
CSS Highlights API syntax highlighting code custom element
<div><div>
<script type="module">
import { LitElement, html, css } from 'https://esm.sh/lit';
import "https://esm.sh/[email protected]";
class HlCode extends LitElement {
static properties = {
lang: { type: String }
};
@pedrovhb
pedrovhb / snoop_class.py
Created August 16, 2023 22:28
A metaclass and base class which, when inherited from, enables @Snoop on all methods automagically
import inspect
from typing import Dict, Any
import snoop
snoop.install(columns=())
class _SnoopMeta(type):
def __new__(mcs, name: str, bases: tuple, dct: Dict[str, Any]) -> Any:
{ pkgs, stdenv, lib, fetchFromGitHub, fetchpatch
, cmake, pkgconfig
, exiv2, mpv, opencv4
# , qtbase
# , qtimageformats
# , qtsvg
}:
# { pkgs ? import <nixpkgs> { } }:
@pedrovhb
pedrovhb / async_gpt.py
Created April 18, 2023 15:08
A standalone implementation of interacting with the OpenAI ChatGPT API. Uses async iterators for streaming responses and supports multiple concurrent generations with a single API call.
import json
import os
import httpx
import typing
from httpx import AsyncClient
import tiktoken
API_BASE_URL = "https://api.openai.com"
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
@pedrovhb
pedrovhb / set_ergo_scroll.py
Last active September 28, 2024 03:20
This makes it so that as long as that button is being held, moving the cursors scrolls instead.
#! /usr/bin/env python
import re
import subprocess
import textwrap
RE_LOGITECH_ID = rb"Logitech MX Ergo[\s\-\w]+id=(\d+).*pointer"
def set_ergo_scroll() -> None:
from __future__ import annotations
from dataclasses import dataclass
from typing import Tuple, List, Union
import cairo
from abc import ABC, abstractmethod
@dataclass
class HasPosition(ABC):
x: float
y: float
@pedrovhb
pedrovhb / rec_screen
Last active February 28, 2023 17:32
Bash CLI util to record the screen with VAAPI hardware acceleration. Writes to two audio streams - one with the default input device (microphone), and one with the desktop audio.
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p ffmpeg slop
set -e
output_file="$HOME/Videos/recording_$(date +%Y_%m_%d__%H_%M_%S).mp4"
qp=23
usage() {
echo "Usage: $(basename $0) [OPTIONS]"
@pedrovhb
pedrovhb / prompt_gpt.md
Created January 3, 2023 21:20
A prompt to turn ChatGPT into a hallucinating REPL.

Hallucinate code responses

Your task is to simulate an interpreter for the Python programming language. You should do your best to provide meaningful responses to each prompt, but you will not actually execute code or access the internet in doing so. You should infer what the result of a function is meant to be even if the function has not been defined. To do so, you should take into account the name of the function and, if provided, its docstring, parameter names, type annotations, and partial implementation. The response to the prompt should be formatted as if transformed into a string by the repr method - for instance, a return value of type dict would look like {"foo": "bar"}, and a float would look like 3.14. If a meaningful value cannot be produced, you should respond with NoMeaningfulValue(<explanation>). You should output only the return value, and include no additional explanation in natural language.

Here are some example prompts, and acceptable responses:

Prompt: sound_of("

@pedrovhb
pedrovhb / dearasyncgui.py
Last active December 26, 2022 23:56
A quick demo/proof of concept of running dearpygui with an asyncio object oriented interface.
from __future__ import annotations
import asyncio
from asyncio import Queue
from typing import NamedTuple, AsyncIterable, AsyncIterator, Any, Callable
import dearpygui.dearpygui as dpg
from loguru import logger
class ButtonEvent(NamedTuple):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.