Skip to content

Instantly share code, notes, and snippets.

View ethanhs's full-sized avatar
🐍
▄▄▀▀▄▄▀▀▄▄▀▀▄▄▀ꜚ

Ethan Smith ethanhs

🐍
▄▄▀▀▄▄▀▀▄▄▀▀▄▄▀ꜚ
View GitHub Profile
@ethanhs
ethanhs / example.rs
Last active April 21, 2024 11:53
Example using pickling in pyo3
#![feature(arbitrary_self_types)]
use pyo3::prelude::*;
use pyo3::pyclass::PyClassShell;
use pyo3::types::{PyBytes, PyTuple};
use pyo3::ToPyObject;
use bincode::{deserialize, serialize};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
@ethanhs
ethanhs / PurepyHook.py
Last active December 13, 2023 02:02
This is a pure python (or as close as possible) keyboard hook module.
# Some of this adapted from BoppreH's answer here:http://stackoverflow.com/questions/9817531/applying-low-level-keyboard-hooks-with-python-and-setwindowshookexa
import ctypes
from ctypes import wintypes
from collections import namedtuple
KeyEvents=namedtuple("KeyEvents",(['event_type', 'key_code',
'scan_code', 'alt_pressed',
'time']))
handlers=[]
@ethanhs
ethanhs / print_scanner.py
Created September 7, 2023 20:35
OCF Printing -- Client side
#!/usr/bin/env python3.7
from ocflib.printing.quota import get_quota
from ocflib.printing.quota import get_connection
from ocflib.account.search import user_is_sorried
from ocflib.account.search import user_exists
from imutils.video import VideoStream
from pyzbar import pyzbar
import imutils
import cv2
#include <windows.h>
void SetWindowBlur(HWND hWnd)
{
const HINSTANCE hModule = LoadLibrary(TEXT("user32.dll"));
if (hModule)
{
@ethanhs
ethanhs / pypitest.log
Last active February 18, 2020 10:58
running pegen on pypi's top 4000 packages
This file has been truncated, but you can view the full file.
pegen/pegen.c:101:1: warning: ‘token_name’ defined but not used [-Wunused-function]
token_name(int type)
^~~~~~~~~~
pegen/parse_string.c: In function ‘FstringParser_ConcatFstring’:
pegen/parse_string.c:604:24: warning: ‘expr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
return expr->v.Expr.value;
~~~~~~~~~~~~^~~~~~
pegen/parse_string.c:584:13: note: ‘expr’ was declared here
stmt_ty expr = asdl_seq_GET(mod->v.Module.body, 0);
^~~~
@ethanhs
ethanhs / Readme
Created October 14, 2015 00:32
example to get a tuple of the mouse coordinates when one clicks ctrl+a
This gist is for pywinauto. I would suggest that you `print(e)` above `if type(e)==MouseEvents:`, as this will be particlarly enlightening for looking at the low level info gained by this function.
@ethanhs
ethanhs / output.log
Created February 28, 2019 22:41
Trying to build typed_ast with pypy
ethanhs▶~\Documents\typed_ast◇master❯ ..\..\Downloads\pypy3.6-v7.0.0-win32\pypy3 -m pip install .
Processing c:\users\ethanhs\documents\typed_ast
Installing collected packages: typed-ast
Running setup.py install for typed-ast ... error
Complete output from command C:\Users\ethanhs\Downloads\pypy3.6-v7.0.0-win32\pypy3.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\ethanhs\\AppData\\Local\\Temp\\pip-req-build-13ik00j7\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ethanhs\AppData\Local\Temp\pip-record-qn2gezr2\install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build\lib.win32-3.6
creating build\lib.win32-3.6\typed_ast
@ethanhs
ethanhs / client.py
Last active October 24, 2018 19:51
An experiment writing nice wrappers around namedpipes using the _winapi module.
import time
import sys
from namedpipe import *
if __name__ == '__main__':
if len(sys.argv) < 2:
print("need s or c as argument")
elif sys.argv[1] == "s":
with NamedPipeServer('testFoo') as server:
count = 10
while count > 0:
@ethanhs
ethanhs / py-spy-mypy
Created October 18, 2018 09:48
Running py-spy on mypy
Collecting samples from 'python -m mypy mypy' (python v3.7.0)
Total Samples 4700
GIL: 0.00%, Active: 32.00%, Threads: 1
%Own %Total OwnTime TotalTime Function (filename:line)
8.50% 8.50% 1.77s 1.82s atomic_write (C:\Users\ethanhs\Documents\mypy\mypy\build.py:866)
1.00% 9.50% 0.190s 2.78s __eq__ (C:\Users\ethanhs\Documents\mypy\mypy\types.py:532)
1.00% 1.00% 0.025s 0.085s check_arg (C:\Users\ethanhs\Documents\mypy\mypy\checkexpr.py:1163)
1.00% 3.50% 0.190s 1.19s __hash__ (C:\Users\ethanhs\Documents\mypy\mypy\types.py:527)
0.50% 9.50% 0.045s 3.76s literal_hash (C:\Users\ethanhs\Documents\mypy\mypy\literals.py:93)
<?xml version="1.0" encoding="utf-8"?>
<Language>
<lang_name>fr</lang_name>
<title_error>Erreur</title_error>
<title_info>Information</title_info>
<title_warning>Avertissement</title_warning>
<title_finished>Fini</title_finished>
<title_eula>CLUF</title_eula>
<title_bg_disabled>Background désactivée</title_bg_disabled>
<title_are_you_sure>Est-ce que vous êtes sûr</title_are_you_sure>