Skip to content

Instantly share code, notes, and snippets.

@secemp9
secemp9 / test.md
Last active November 15, 2022 13:22
tkinter text widget with python offset (file.tell()) support

Using only tkinter (bytes offset? need more testing):

  • start: '1.0', '0.0 + N chars'
  • middle: '1.0 + Nc', 'end - Nc' # both N need to be the same
  • end: 'end - Nc', 'end' # need to use N + 1 here

N is to be replaced by the number of char/bytes needed to act on. This wasn't tested extensively, but it seems to hold up when tested with text.delete:

def testdelete_start(event=None):
 text.delete('1.0', '0.0 + 3 chars') # change this line here
@secemp9
secemp9 / panda_clipboard.py
Last active November 17, 2022 13:14
panda copy/paste dataframe using clipboard
# using https://stackoverflow.com/a/68032799/12349101 and https://stackoverflow.com/a/101167/12349101
import win32clipboard
import pandas as pd
# set clipboard data
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(""" 0 1 2
level1 level2
foo a 0.518444 0.239354 0.364764
b 0.377863 0.912586 0.760612
@secemp9
secemp9 / tktest.py
Created November 22, 2022 22:22
tkinter playground v1
import tkinter as tk
container = []
def destroy_window(x):
x.destroy()
def full_window(x):
@secemp9
secemp9 / crontab_start.sh
Created November 27, 2022 19:41
start crontab with the given command (deduplicate entries too)
cronadd() {
if crontab -l | grep -wq -- "$@"; then
:
else
(crontab -l 2>/dev/null; echo "$@") | crontab -
fi
}
@secemp9
secemp9 / picklequeue.py
Created November 28, 2022 17:20
pickle + queue/deque inside a file
import pickle
import collections
import queue
def f():
return "hello" # it's a test
class PickleQueue:
@secemp9
secemp9 / officetest_tk.py
Last active November 30, 2022 14:24
Control OpenOffice and LibreOffice using their respective API (and python executable, which are different versions, *sigh*)
import multiprocessing
import os
import tkinter
import time
import pickle
import collections
import subprocess
import re
import sys
@secemp9
secemp9 / test1.py
Last active November 30, 2022 17:22
define function with dependent function if called locally/inside
import inspect
l = []
copy_dict = dict(locals())
for key, value in copy_dict.items():
if "function" in str(value) and callable(value) and value.__module__ == __name__:
l.append(key)
# print(l)
def increment_indent(a):
@secemp9
secemp9 / tell_test.py
Created November 30, 2022 15:30
file.tell stuff (3.X)
with open("test.txt", "w") as w:
w.write("""
this is a test
this is another test
another test""")
with open("test.txt", "rb") as e: # when using a for loop or next/basically going through the file, using file.tell only works with "rb", but if you use "r" with a for loop + file.tell, then an error occur
for i in e:
print(e.tell())
with open("test.txt", "r") as e: # works since there no for loop/next call
@secemp9
secemp9 / funcdeps.py
Created December 1, 2022 06:56
bring dependencies with your function! (experimental)
import inspect
import ast
from itertools import dropwhile
import types
def get_function_body(func, strip_def=True):# needs recursive function listing, so can support sending nested function/etc
if not strip_def:
return "".join(inspect.getsourcelines(func)[0])
source_lines = inspect.getsourcelines(func)[0]
source_lines = dropwhile(lambda x: x.startswith('@'), source_lines)
@secemp9
secemp9 / vm_automation.md
Created December 1, 2022 11:48
Setting up VM in an automated way 101

This isn't really a guide, but more like a log of what I know when it comes to automating VMs. First I'll details things in a non-specific way (eg: without it depending on a particular application). I'll details things later.

  • SSH (local)
  • ISO extration/editing/re-bundle
    • Chroot to install package, etc
    • Just move files or extract them too (eg: exctrating a .deb files on debian/ubuntu can work too, etc)
    • Compiling (same as above depending on how you look at it)
  • COM bridge (Mostly Windows)
  • socket (tcp, etc)