Skip to content

Instantly share code, notes, and snippets.

@secemp9
secemp9 / input_resize.py
Created May 30, 2024 16:04
Tkinter request, twitter
import tkinter as tk
def send_message(event=None):
message = input_entry.get()
if message.strip():
chat_history.configure(state=tk.NORMAL)
chat_history.insert(tk.END, "You: " + message + "\n")
chat_history.configure(state=tk.DISABLED)
input_entry.delete(0, tk.END)
@secemp9
secemp9 / hidden_file.py
Created May 24, 2024 19:27
For Windows, playing around with hidden files
import os
import ctypes
hidden_file_path = '.picasa.ini'
with open(hidden_file_path, 'w') as file:
file.write("Initial content")
# Hide the file using Windows API
FILE_ATTRIBUTE_HIDDEN = 0x02
@secemp9
secemp9 / sys_reload.py
Last active May 23, 2024 18:10
reload sys module (doesn't actually work it turn out :/)
import sys
import importlib
sys.exit = lambda *args, **kwargs: ...
print(f"sys.exit overridden: {sys.exit}")
importlib.reload(sys)
print(f"sys.exit restored: {sys.exit}")
try:
print("test")
sys.exit(0)
except SystemExit as e:
@secemp9
secemp9 / see_through_window.py
Created May 15, 2024 06:57
See-through hole using PyQT5
import sys
from PyQt5.QtCore import Qt, QRect, QPoint
from PyQt5.QtGui import QPainter, QBrush, QColor, QRegion
from PyQt5.QtWidgets import QApplication, QWidget
class SeeThroughHoleWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.dragging = False
@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