Skip to content

Instantly share code, notes, and snippets.

View ianfun's full-sized avatar

ianfun ianfun

View GitHub Profile
@ianfun
ianfun / client.html
Created July 18, 2021 08:43
python console on browser
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet">
<meta charset="utf-8">
<title>python console</title>
</head>
<body>
<button onclick="clo();alert('shell closed');window.close()">close shell</button>
<style type="text/css">
@ianfun
ianfun / see.py
Last active May 9, 2022 07:37
simple python module browser
def show_m(path):
from tkinter import Text, Tk
from idlelib.colorizer import color_config, ColorDelegator
root = Tk()
root.title(path)
text = Text(root)
text.pack(expand=1, fill="both")
with open(path, encoding='utf-8') as f:
text.insert("insert", f.read())
text.focus_set()
@ianfun
ianfun / ABC.py
Created July 28, 2021 03:25
a variable's value is it's name
for i in range(0, 0x110000):
globals()[chr(i)] = chr(i)
print(你+好=='你好')
print(H+e+l+l+o+globals()[' ']+w+o+r+l+d)
@ianfun
ianfun / Scavenger.py
Created July 28, 2021 08:49
Scavenger
_ = BaseException
__ = dir
___ = exec
for i in __(__builtins__):
try:
___(f"{i}=...")
except _:
...
i=...
_ = ...
@ianfun
ianfun / main.nim
Created February 6, 2022 09:07
Consumer and Supplier with thread and condition variable in Nim
# compile nim c --threads:on --hints:off --run main.nim
import locks, random
from os import sleep
var
supplier, consumer: Thread[void]
repeat = 0
lock: Lock
cond: Cond
@ianfun
ianfun / main.cpp
Created May 9, 2022 07:36
ReadFileEx example - async read whole file
#include <windows.h>
#include <stdio.h>
constexpr auto DWORD_size(){
return sizeof(DWORD);
}
#define BUFZ 101
char buf[BUFZ];
@ianfun
ianfun / notification.cpp
Created May 23, 2022 04:01
Shell Notification Example in Win32 API
#include <windows.h>
#pragma comment (lib, "shell32.lib")
#pragma comment (lib, "User32.lib")
static UINT uID = 0;
void notifyUser()
{
uID += 1;
@ianfun
ianfun / main.cpp
Created May 24, 2022 13:43
IOCP readfile example
#include <Windows.h>
#include <stdio.h>
typedef struct _PER_SOCKET_CONTEXT {
OVERLAPPED ol;
char buf[100];
HANDLE hFile;
} PER_IO_CONTEXT, * PPER_IO_CONTEXT;
DWORD WINAPI Worker(LPVOID param);
@ianfun
ianfun / spawn.cpp
Created May 28, 2022 14:04
Read child process’s stdout and stderr using Named Pipe and IO Completion port(IOCP) asynchronously
#include <windows.h>
#include <assert.h>
#include <stdio.h>
struct Stdio;
typedef void (*Callback)(struct Stdio* self, DWORD len);
struct Stdio {
OVERLAPPED ol;
@ianfun
ianfun / server.py
Created June 11, 2022 14:19
pretty simple websocket server in Python (44 lines)
import socket
from hashlib import sha1
from base64 import b64encode
from sys import stdout
client = None
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('', 80))
server.listen(5)