To run anything here, you need to add this repo to your %PYTHONPATH%
!
Otherwise nothing will work!
A lot of the scripts include tests and demos.
You can find them after if __name__ == '__main__':
or in file __main__.py
.
All the wheels I re-invented.
This repo has various useful python tools and utils...
and some projects that don't deserve a full repo.
If you have questions or suggestions, please open an issue.
(My repo doesn't have an issue yet... I figure it would be cool to have one...)
Do you know the 24 card game?
Meaningless Archive of random Python Scripts I wrote.
A prank.
It was freshman year. I was introduced to Python by NYUSH.
I made this for Zane.
Try figuring out what it does.
Scans LAN
Tried to implement SSH when I was young.
Transmit one file.
Deprecated. Replaced by ../oneship
Keeps beeping, until the computer sleeps.
Purpose: so you can tell if your computer is asleep.
Useful in rare occasions.
Simple experiment of dealing with sound data in real time.
To archive http://rrrrthats5rs.com
experiment regarding covariance, coefficient, regression
F: future price / market portfolio price
S: spot price / stock price
h: hedge ratio / beta
Both F and S refers to per period return.
?????????????????????????????????????????????????????????
Liwei's gamble with ???????????????
Oh damn! I read about dbm
and will now dump this project.
Tests the time complexity of small binary updates to large files.
Conclusion: On my Windows, it's O(1).
This was before I started to use Github, and I didn't do documentation.
Consider this the pre-historical era.
To test the security of getpass.
Too bad. It does not work. Mindustry 6.0 is anti-python?
Transpose an audio up one octave, by removing odd partials.
Does requests_futures interrupt the sockets on exit?
Conclusion: even socket is graceful!
There are two copies of the database.
We use a "which_file" to point to the valid one of the two.
Read operation:
Read the valid database.
Write operation:
Write to the invalid database. Close it.
Change which_file to point to the database we wrote to.
This ensures:
- Whenever the user unplug their machine, the which_file always points to a non-corrupted database.
- Every write operation is atomic. Either we revert back to the state before the write, or the write is 100% complete. There is no middle state.
However, concurrent writing leads to undefined behavior.
I don't know what this strategy is called. If you know what it's called, please open an issue and tell me.
Measures the serial self-playback round trip time.
Bamboozling lyric-rolling music-playing windows-only python script
A game
A game by Daniel
-> LAN -> Midi from TCP
as midi device ->
My personal notebook for learning Python.
Port specification for my applications.
Interactive git commit and push.
A game by Daniel.
My personal second / third python project. You can see a lot of bad coding styles.
Updates description:
V3:
+ Added: new weapon = Holy Sickle
Acquired through Annoying Cat
Ulti: ATK+1
20% Vamparic.
+ Added: Personal high score.
+ Improved: Game over prompt.
V4:
Fixed: Holy Sickle works properly now.
V5:
Fixed: Now the game actually restarts when you die.
+ Added: Next Daily Hint
Edit: Intro screen now uses black background
Fixed: Daily Hint regarding the behavior of Annoying cat.
+ Added: drop weapon msg
Fixed: DeltaHP now reflects the aggregate effect of healing and dmg
Fixed: Easter item drop rate was higher than normal weapons'...
Fixed: Critical Hit chance > 100%
+ Added: Holy Sickle now increase GamePace.
+ Added: When Holy Sickle ATK=100, Ulti becomes IronMan
V6:
very hihg speed -> incredible hihg speed
V7:
First play will show kidding death msg
V8:
Changed the abbr of Space Corgi to " Corgi"
Sleep on an absolute schedule.
An alarm clock because the Win10 Alarm App HCI is trash.
Added support for linux because aur/timer doesn't support repeating until dismissed.
A beautiful script to print the ascii table.
Send exceptions to other threads.
Based on Philippe F's https://stackoverflow.com/a/325528/8622053
If the thread is busy in a system call (socket.accept(), ...),
the exception is simply ignored.
Read from a PIPE async.
See https://stackoverflow.com/questions/375427/a-non-blocking-read-on-a-subprocess-pipe-in-python
Play audio cues.
Can be used as a loudspeaker.
Wait, doesn't VoiceMeeter already do this?
DUPLICATE: playback.py
Auto bin number.
Repeatedly prints 'wobo wabble' indefinitely.
Find local minima of a 1D function without gradient.
Minimizes the number of calls to the function.
Run this script to test it.
Implementation:
- A 3-point recursion of shifting and zooming
- Cacheing with input as Fractions
automaitcally press 222222
A file system.
Encrypts the file system with Fernet.
@cacheWithFile('expanded_matrix')
def expandMatrix(m):
# some heavy computation
result = ...
return result
Inefficiently cache and lookup function returns.
A context to temporarily cd to another directory.
Frequently useful: ChdirAlongside(file)
Input: MS Word generated html file.
What it does: change encoding to utf-8, remove style info specific to Microsoft Outlook, replace curly double quotes (???) with straights (").
Windows only.
Use your phone to send UP and DOWN to your computer!
Useful for reading in Kindle.
WARNING: Running this may open vulnerabilities for your computer.
Don't run this if you don't know what you are doing.
Only run this if you are in a safe network, or inside a firewall.
I am not responsible if someone attacks your computer through this server.
Iterate through all files in this repo
build a readme.md for Github.
Runtime embedded interactive python shell, just like IPython.
Windows only. If not windows, console()
calls IPython.embed()
.
Usage: console(globals())
or console({**locals(), **globals()})
Advantages over IPython:
- Lighter. Launches very quickly.
- Other threads can still print things when user is inputting commands
- Tab auto-completes your phrase, even under Windows! (I'm proud.)
- Tired of having to
import
to test your module everytime you make an edit?restart()
is what you need here. Ctrl+R does the same!
Issues:
- Reassigning module global variables will not be visible to module native codes. Sorry.
- For unknown reasons, you cannot declare any name present in kernal.py that is invisible to the env.
- Sometimes inline generator cannot access namespace. I can't stably replicate this issue, and I don't know what this is about.
Fixed Issues:
- If you wanna scroll up, you don't need to input() anymore!
- Multi-line code continuation is implemented!
- If input command is longer than terminal width, camera rolls.
Future:
- Consider adding a dynamic
return
feature. - Study passing namespace into
exec
andevel
and use them.
For a clean namespace.
I later realized that this can be done with arguments to exec and eval.
For counting votes and ranking the counts.
Oh! I guess from collections import Counter
does the same for you!
Although my thing is still more console friendly.
creality_cr6-se_gcode_postprocess
Log script parameters as well as terminal output to files.
Useful for simulation runs / deep learning experiments.
Compare the shape of two dicts.
i.e. is the structure the same? are the keys the same?
print(sys.argv)
Uses dynamic programming (DP) to calculate the minimum editing distance.
Use a file to denote whether a program is running.
Your code requires Daniel's PythonLib? Use this template to import the required modules.
Play swf files.
To transmit a folder over the internet.
Can continue on half-done job. Auto retry on connection failure. Skip files whose hash is the same.
Does not include subfolders.
Like dummy.Pool.map, but no limit of number of threads.
Useful when IO-bound.
Evaluate beautiful formulas like ???(2??3??4)
(Those non-ascii math symbols)
Given a fraction, find the resistor connection to achieve it.
Formatting time data in a friendly manner.
Automatic retry of OpenAI GPT calls.
Tools to do graphics in the terminal.
clearLine
: fill the current line with ' ' (whitespace)
eastAsianStrLen
: length of str as displayed on terminal (so chinese characters and other fullwidth chars count as 2 or more spaces)
displayAllColors
: display all colors that your terminal supports.
printTable
: print a table in the terminal.
Synthesize sound with harmonics.
Interpolate between frames smartly.
commit 490dd5810f39fc322a61cd444c581374323d8803 removed
accelerated approach to correct mag. So now it only works
if harmonic list input is stable in sequence.
Uses the keyboard
package to hold down a key.
with ...
clause avoids forgetting to release a key.- Blocks the held key, and redirect it to your hook.
Opens a hotspot on linux.
Deprecated in favor of linux-wifi-hotspot.
HTTP man in middle. Prints all traffic. Useful for investigating how http works. Although Chrome Dev Tools prolly have something like this already.
Hub: forward all socket messages.
Connect, sendall(b'OK'), forward...
Uses HarmonicSynth (precise) for the lower register
and IfftSynth (fast) for the higher register.
- automaitcally press FFFFFFFF
- Auto running with stamina management.
Synthesizes an audio page from a spectrum.
Sort files and pass them to imv.
Indent log output in a logical way.
Try this:
from indentprinter import indentPrinter
bois = ['Collie', 'Husky', 'Shoob', 'Shibe']
print('All bois:')
with indentPrinter as print:
[print(x) for x in bois]
Terminal interactivity utils.
listen
: waits for key press.
inputChin
: It does everything. There are too many features to describe. Reading the source code is the only way.
Universe
: x in Universe()
always returns True
no matter what x
is.
inputUntilValid
: re-asks if not valid.
multiLineInput
: user may input multi lines. Terminate with ^Z.
Demo:
Define in __main__.py
. Run it, or run the module.
Issues:
- On Linux, Stopping the job and bringing it back to foreground messes up the terminal setting up (?)
Future work:
Stop telling lies in help(getFullCh)
on Linux.
https://stackoverflow.com/questions/48039759/how-to-distinguish-between-escape-and-escape-sequence
An android-friendly console file explorer.
A Python class implementing KBHIT, the standard keyboard-interrupt poller.
Works transparently on Windows and Posix (Linux, Mac OS X). Doesn't work
with IDLE.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Converts ipynb to py.
Works even when Jupyter is not installed.
Progress bar.
Did you know about tqdm
?
Usage:
with Jdt(500, 'loading...') as j:
for i in range(500):
j.acc()
doJob(i)
Run this file to see demo.
Set override_terminal_width
when using Jupyter Notebook with jdt.
Move cursor with Pro Controller.
Maintain a list of high scores.
This is for me only.
You won't get why this code is here.
Give up.
A double linked file list.
A simple database solution, but highly scalable on systems that use hash map to store files.
Each entry has a timestamp, and the list is sorted by time.
Features:
- Dynamic filename length, grows as the database grows.
Find out local IP addr on Windows
Record, play, save, and load macros.
Windows only.
PROTECTION: global hooked button to stop macro = Windows Key
Manhattan geometry, where Manhattan distance is the distance metric.
Translate markdown .md file to html file.
Note: to work on WordPress, avoid level one header (# Title).
A lot of markdown features are not implemented!
Print the headings of a markdown file.
Stream-based median filter.
Add overlaping notes to a midi file, automatically creating new tracks when necessary.
AFK tool for Minecraft.
Punch the air every 5 seconds so you don't get kicked for inactivity.
Simulate arrow keys with mobile web app.
WARNING: Running this may open vulnerabilities for your computer.
Don't run this if you don't know what you are doing.
Only run this if you are in a safe network, or inside a firewall.
I am not responsible if someone attacks your computer through this server.
Your laptop has no numpad? Can't play Cataclysm:DDA? No worries. Use your phone as a numpad!
This script hosts a webpage on your computer. Open the webpage on your phone.
Issues:
- "0" is not currently supported.
- Digits may come out-of-order if the connection is poor.
WARNING: Running this may open vulnerabilities for your computer.
Don't run this if you don't know what you are doing.
Only run this if you are in a safe network, or inside a firewall.
I am not responsible if someone attacks your computer through this server.
tkinter gadgets and some util functions.
Msgbox
, inputbox
, screenCenter
, StretchMessage
, StretchPicture
, ToughText
, bilingualStringLen
.
Run this file to see demo.
Provides multiple terminal windows for output.
Supports Windows OS.
For demo, run file __main__.py
or run this module via py -m multi_term
.
In the demo, there are multiple levels of output (info, debug, warning, error), redirected to each terminal.
Uses sockets for inter-process communication.
Future work:
- Support more OSes.
- Allow input from other terminals.
- Replace lock for semaphore to launch terminals in parallel.
- Remote terminal?
My misc little tools.
- @profileFrequency() decorates a function to measure how often it's called.
- @profileDuration() decorates a function to report how long it took to run.
e.g. Context managers to enter tags.
Unreliable file utils
Serves through a (super) simplified version of http protocol.
Warning: Running this may expose your computer to attacks.
Don't run this.
More math utils than just import math
Prints QR code to terminal. Ascii only: black whitespace and white whitespace
My socket utils. Provides recvall
, recvFile
, sendFileJdt
, and findAPort
.
My threading utils
XML parser
For an NYU person, convert their netID to profile.
Creates an empty .gitignore
file.
This is useful because Windows File Explorer forbids you from naming a file without base name, and >
now creates files in UTF-16 with BOM encoding.
Just to see how often NYU LAN re-allocates IP.
?????????
Transmit files over the internet / LAN
No encryption! Consider everything you transmit broadcast to the entire network.
My laptop is weird. Running this script makes opening and terminating processes faster.
Speculation: Taking CPU time away from Windows Defender?
LiTouZhiBei(Chinese: '\xe5\x8a\x9b\xe9\x80\x8f\xe7\xba\xb8\xe8\x83\x8c').
Converts pdf from [p1, p2...] to [p1, p1, p2, p2...]
Original author: pmaupin
https://github.com/pmaupin/pdfrw
with minor modification by Daniel Chin for friendlier command-line calling
usage: py -m pdf_unspread my.pdf
Creates my.unspread.pdf
Chops each page in half, e.g. if a source were
created in booklet form, you could extract individual
pages.
Preview a pickle file
A socket that supports object transmission.
Input: datapoints that define a piecewise linear function.
Output: a rule-generated pytorch module implementing such a function.
pip install, and imports
Uses mido to play a midi file.
Playback audio in real-time.
Useful if you want to hear your doorbell while watching videos
with headphones.
Light-weight wav player.
Provides fake p2p, port forwarding.
Ignored the thread-danger of sockets.
Expect unexpected behaviors.
Plays an array of audio signal. Blocking.
Get prime numbers
Make a QR code instantly
Sets up a server, displays a QR code. Scan it to go to a web page. Exchange raw texts!
Useful for sending a URL from the phone to the laptop.
Warning: No authentication or encryption. Don't type in secrets. Don't assume who the remote is.
morph a quad into another quad. It's like 3D projection.
Questions I have about Python.
I just wanna generate a random number very conveniently,
e.g. Win+R py -m rand
Creates a react component file containing boilerplate code.
Time-based round robin scheduling.
Run a python module but it waits at the end as if you called it in command line.
An HTTP backend server.
Really tries to be safe against injection attacks.
Intentionally uses single thread only.
Only answers GET. Does not abide by request http header fields.
Does not defend against DoS.
Problems:
- socket.send without timeout. Could block the entire scheduling.
A simple file server.
Serves file in a folder.
Has a simple html page interface.
Built upon safe_http.py. Please see its documentation.
Problems:
- Does not sanitize html. But Don't panic! This is a file server and the threat only originates from local file names. Plus, "<>" is not allowed in filename.
Scale a PSF font file.
Voice transformer for SCP:SL
Playback a section of your screen.
Useful for sharing PPT (with speaker notes on) over Tencent (VooV) Meeting.
Hit ESC
or q
to quit.
Hit Spacebar
to refresh view.
Click and drag to resize the window.
A terminal interface that lets the user select
the audio input/output device.
PySerial already has a CLI monitor, but when it receives
color formatting codes, it tries to print unprintable
characters. Let's fix that.
Features:
- Color formatting.
- Attach a time stamp to each line.
- Merge multiple ports into one terminal.
Immediately open a port, accept connection
and does nothing.
The bar chart provided by matplotlib is surprisingly manual.
Let's fix that.
Softmax with temperature and probability weighting.
What I learned from Statistics for Business and Finance.
Stellaris game assistant.
Assignes hotkey to planet prev/next buttons and
pop growth specification buttons.
Profiles the computation time of a series of actions in a real-time stream-base application.
Run the script to see a demo.
Examines a directory of .py files and find all imports.
A context to temporarily add paths to sys.path
Useful for importing modules from a different directory.
When importing something from python_lib in an external project.
Contributors of this code: Alexander Belchenko, Harco Kuppens, Justin Riley.
http://code.activestate.com/recipes/440694-determine-size-of-console-window-on-windows/
https://stackoverflow.com/questions/566746/how-to-get-linux-console-window-width-in-python
https://gist.github.com/jtriley/1108174
I changed python2 to python3, and added crediting printing.
Terraria bot. Automated fishing.
Vision: bait catching, and defending invasions.
Result: Failed! This macro does not work on Terraria!
Data type that stores file directory structure.
My personal tool to fix typos.
Assume you only do horizontal typos. No vertical typos. You may mistype E as R, but never as D.
Also you may hit "=" instead of Backspace.
Word data is from https://norvig.com/big.txt
Interactive shell to test UDP.
Scroll whatever you are reading with voice.
low hum to scroll down. high hum to scroll up.
Downloads a web resource.
Provide no argument to enter interactive mode.
Convert xls or xlsx to csv.
This loads the entire file content into RAM. Be careful with big files.
YIN pitch detection for a single page of audio.
Modified from librosa's implementation of YIN.