Skip to content

Instantly share code, notes, and snippets.

@secemp9
secemp9 / tree_sitter_parse_c.py
Created April 21, 2024 22:18
Parsing C code example using tree-sitter Python module
from tree_sitter import Language, Parser, Tree, Node
import tree_sitter_c
from typing import Generator
C_LANGUAGE = Language(tree_sitter_c.language(), "c")
parser = Parser()
parser.set_language(C_LANGUAGE)
c_code = """
@secemp9
secemp9 / escape_sequence_terminal_size.py
Last active April 24, 2024 21:44
Get terminal size in pixels using escape sequence (works on Linux and msys2/mingw)
import sys
import termios
import tty
def get_text_area_size():
# Save the terminal's original settings
fd = sys.stdin.fileno()
original_attributes = termios.tcgetattr(fd)
try:
@secemp9
secemp9 / curses_size.py
Created March 23, 2024 11:41
get size of terminal in pixels (curses)
import curses
def get_terminal_size():
try:
# Initialize curses
stdscr = curses.initscr()
# Turn off echoing of keys, and enter cbreak mode,
# where no buffering is performed on keyboard input
curses.noecho()
@secemp9
secemp9 / threading_wait4.py
Last active February 6, 2024 13:18
Threading wait POC 4
import threading
import time
import signal
class ControlledExecution:
def __init__(self):
self.lock = threading.Lock()
self.condition = threading.Condition(self.lock)
self.shutdown = False
@secemp9
secemp9 / threading_wait3.py
Created February 6, 2024 12:28
Threading wait POC 3
import threading
import time
class ControlledExecution:
def __init__(self):
self.lock = threading.Lock()
self.condition = threading.Condition(self.lock)
self.shutdown = False
def worker(self):
@secemp9
secemp9 / threading_wait2.py
Created February 6, 2024 12:06
Threading wait POC 2
import threading
import time
import signal
class ControlledExecution:
def __init__(self):
self.lock = threading.Lock()
self.condition = threading.Condition(self.lock)
self.shutdown = False
@secemp9
secemp9 / threading_wait.py
Created February 6, 2024 12:06
Threading wait POC
import threading
import time
class ControlledExecution:
def __init__(self):
self.lock = threading.Lock()
self.condition = threading.Condition(self.lock)
self.shutdown = False
def worker(self):
@secemp9
secemp9 / scrape_test.py
Created January 26, 2024 19:05
scraping...
import time
from io import BytesIO
import cv2
import numpy as np
import pytesseract
import requests
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
@secemp9
secemp9 / loom_video_links.py
Last active January 26, 2024 06:01
Get video links from Loom's folder link (no commandline support)
@secemp9
secemp9 / loom_video_links.py
Last active January 26, 2024 05:33
Loom get video links from folder (version that work with commandline)