Skip to content

Instantly share code, notes, and snippets.

View aliencaocao's full-sized avatar
🎯
Focusing

Billy Cao aliencaocao

🎯
Focusing
View GitHub Profile
@aliencaocao
aliencaocao / TensorRT Inference.py
Last active June 16, 2024 14:56
TensorRT Inference
from collections import namedtuple, OrderedDict
import numpy as np
import tensorrt as trt
import pycuda.driver as cuda
assert trt.__version__.split('.')[0] >= '10', 'TensorRT version >= 10 is required.'
class TRTInference:
@aliencaocao
aliencaocao / PyTorch_gpu_test.py
Created July 1, 2022 09:51
PyTorch test if using GPU
import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0))
t = torch.randn(1,2).to('cuda')
print(t)
@aliencaocao
aliencaocao / TF_gpu_test.py
Created July 1, 2022 09:48
TensorFlow test if using GPU
import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
print(c)
@aliencaocao
aliencaocao / libc-rip.py
Last active May 15, 2022 14:30
Python wrapper to search and download libc files for ret2libc attacks in CTFs and more.
import json
import hashlib
import requests
API_URL = 'https://libc.rip/api/find'
def search(known_symbols: dict[str, str]) -> dict[str, str]:
"""
Search for the libc version using the known symbols and their offsets.
@aliencaocao
aliencaocao / timing side channel attack.py
Created March 18, 2022 10:10
timing side channel attack
import time
import subprocess
possible_chars = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] # possible characters in the password
length_of_password = 8
max_or_min = max # choose if guessing the 'correct' answer result in longest (use max) or shortest (use min) execution time
path_to_executable = 'path to password checking executable'
error_msg = 'Last row of output you get for entering a wrong password' # the last row of output you get for a wrong password
@aliencaocao
aliencaocao / discord-music-bot.py
Last active April 29, 2024 16:48
A fully working minimal discord music bot with queue system, includes pyinstaller support (can be compiled into exe and ran)
import os, sys
import re
import time
import datetime
import atexit
import random
from typing import Dict, List, Any
import logging
import asyncio
import requests