This commit is contained in:
Hykilpikonna
2021-12-22 22:52:42 -05:00
13 changed files with 206 additions and 7 deletions
View File
+5
View File
@@ -5,3 +5,8 @@ My zshrc
```sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Hykilpikonna/zshrc/HEAD/fastinstall.sh)"
```
## Ubuntu fast setup
```sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Hykilpikonna/zshrc/HEAD/ubuntu_setup.sh)"
```
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.frpc</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/frpc/bin/frpc</string>
<string>-c</string>
<string>/usr/local/etc/frp/frpc.ini</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/frpc.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/frpc.log</string>
</dict>
</plist>
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.menu-bot</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>/Volumes/macWorkspace/CS/CSC110/menubot/menubot.py</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/menubot.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/menubot.log</string>
</dict>
</plist>
+2
View File
@@ -20,8 +20,10 @@ addline .zshrc 'SCR="$HOME/zshrc/scripts"'
addline .zshrc '. $SCR/zshrc.sh'
# Initialize submodules
pushd zshrc
git submodule init
git submodule update
popd
# Return to the previous directory
popd
+28 -5
View File
@@ -1,14 +1,33 @@
#!/usr/bin/env python3
from __future__ import annotations
import json
import sys
import time
from typing import Tuple, List
def ansirgb(r: int, g: int, b: int, foreground: bool = True) -> str:
c = '38' if foreground else '48'
return f'\033[{c};2;{r};{g};{b}m'
def replace_color(msg: str) -> str:
replacements = ["&0/\033[0;30m", "&1/\033[0;34m", "&2/\033[0;32m", "&3/\033[0;36m", "&4/\033[0;31m", "&5/\033[0;35m", "&6/\033[0;33m", "&7/\033[0;37m", "&8/\033[1;30m", "&9/\033[1;34m", "&a/\033[1;32m", "&b/\033[1;36m", "&c/\033[1;31m", "&d/\033[1;35m", "&e/\033[1;33m", "&f/\033[1;37m", "&r/\033[0m", "&n/\n"]
for r in replacements:
msg = msg.replace(r[:2], r[3:])
while '&gf(' in msg or '&gb(' in msg:
i = msg.index('&gf(') if '&gf(' in msg else msg.index('&gb(')
end = msg.index(')', i)
code = msg[i + 4:end]
fore = msg[i + 2] == 'f'
if code.startswith('#'):
rgb = tuple(int(code.lstrip('#')[i:i+2], 16) for i in (0, 2, 4))
else:
code = code.replace(',', ' ').replace(';', ' ').replace(' ', ' ')
rgb = tuple(int(c) for c in code.split(' '))
msg = msg[:i] + ansirgb(*rgb, foreground=fore) + msg[end + 1:]
return msg
@@ -28,13 +47,17 @@ def set():
if __name__ == '__main__':
start_time = time.time()
# start_time = time.time()
args = sys.argv[1:]
parts_raw = args.pop(0)
parts: List[Tuple[int, str]] = json.loads(parts_raw) if parts_raw != '' else []
cmd = args.pop(0).lower()
if cmd == 'color':
print(replace_color(parts_raw))
exit()
parts: list[tuple[int, str]] = json.loads(parts_raw) if parts_raw != '' else []
if cmd == 'show':
show()
elif cmd == 'debug':
+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/env python3
import os
import sys
from datetime import datetime
def comp(input: str = 'latest', proc: str = 'cpu', codec: str = 'x264', crf: int = 24, br: int = 500,
cmd: bool = False, aargs: str = '', suffix: str = 'mp4'):
"""
Compress video
:param input: Input file (Default: latest)
:param proc: cpu (c) or gpu (g)
:param codec: x264 (4) or x265 (5)
:param crf: CRF (quality) for cpu encoding
:param cmd: Whether to output command directly
:param aargs: Additional args
:param suffix: File suffix (Default mp4)
:return:
"""
if input == 'latest':
rename()
i = sorted([s for s in os.listdir('.') if s.startswith('Rec') and s.endswith('mov')])[-1]
else:
i = input
proc = proc[0]
codec = {'4': {'c': 'x264', 'g': 'h264'}, '5': {'c': 'x265', 'g': 'hevc'}}[codec[-1]][proc]
out = i[:i.rindex('.')] + f'.{codec}'
if proc == 'c':
out += f'-{crf}'
out += f'.{suffix}'
if proc == 'c':
c = f'ffmpeg -i "{i}" -vcodec lib{codec} -crf {crf} {aargs} "{out}"'
elif proc == 'g':
c = f'ffmpeg -i "{i}" -c:v {codec}_videotoolbox -b:v {br}k {aargs} "{out}"'
else:
raise AssertionError(f'Processor is invalid ({codec}[0] not in "cg")')
if cmd:
print(c)
else:
os.system(c)
def rename():
for file in os.listdir('.'):
if file.startswith('Screen Recording ') or file.startswith('Screen Shot '):
pre = 'Rec' if 'Recording' in file else 'Shot'
end_index = (file.index('AM') if 'AM' in file else file.index('PM')) + 2
datestr = file[17 if pre == 'Rec' else 12:end_index]
dt = datetime.strptime(datestr, '%Y-%m-%d at %I.%M.%S %p')
date = dt.strftime(f'{pre} %Y-%m-%d %H-%M' + file[end_index:])
print(f'Renaming {file} to {date}')
os.rename(file, date)
if __name__ == '__main__':
if not hasattr(sys, 'ps1'):
args = sys.argv[1:]
if len(args) < 1:
print('Usage: compress [rename/python code]')
# Command to rename all screen recordings
if args[0] == 'rename':
rename()
exit()
# processor = args[0].lower().strip()
# i = args[1]
# crf = args[2] if len(args) > 2 else '24'
# cmd = 'cmd' in processor
# if cmd:
# processor = processor.replace('cmd', '')
# additional_args = ' '.join(args[3:] if len(args) > 3 else [])
print(eval(' '.join(args[0:])))
+3
View File
@@ -3,3 +3,6 @@
alias va-restart='sctl restart va'
alias va-log-all='jctl -u va --output cat'
alias va-log='va-log-all -f'
# General
alias jctlog='jctl --output cat -f -u'
+7 -2
View File
@@ -2,10 +2,9 @@
if [[ $OSTYPE == 'darwin'* ]] && [ -d "/Volumes/External" ]; then
# Minecraft
export MC_DIR="/Volumes/External/Minecraft"
alias minecraft="pushd $MC_DIR; java8 -jar $MC_DIR/HMCL-*.jar; popd"
alias minecraft="pushd $MC_DIR; java17 -jar $MC_DIR/HMCL-*.jar; popd"
# Paths
export PATH="$PATH:/Users/hykilpikonna/.pyenv/versions/3.8.0/bin"
export DOTNET_ROOT="/usr/local/opt/dotnet/libexec"
# export PATH="/Volumes/MacData/SageMath:$PATH"
export PATH="$PATH:/Users/hykilpikonna/.gem/ruby/2.6.0/bin" # https://stackoverflow.com/a/53388305/7346633
@@ -14,4 +13,10 @@ if [[ $OSTYPE == 'darwin'* ]] && [ -d "/Volumes/External" ]; then
export PATH="${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"
export NDK_HOME="/Volumes/MacData/Resources/android-ndk-r21d"
export NDK_ROOT=$NDK_HOME
export PATH="/usr/local/opt/node@14/bin:$PATH"
# Use Python3.9 by default
export PATH="/usr/local/opt/python@3.8/bin:$PATH"
export PATH="/usr/local/opt/python@3.10/bin:$PATH"
export PATH="/usr/local/opt/python@3.9/bin:$PATH"
fi
+3
View File
@@ -4,8 +4,11 @@ if [[ $OSTYPE == 'darwin'* ]]; then
alias ports="netstat -ap tcp | grep -i \"listen\""
alias ports2="sudo lsof -i -P | grep LISTEN"
alias trash="rmtrash"
alias checkrain="/Applications/checkra1n.app/Contents/MacOS/checkra1n"
alias obs="open -n -a OBS.app"
alias idea="open -a Intellij\ IDEA.app"
alias xcode="open -a Xcode.app"
# Java
export JDK8="/usr/local/opt/openjdk@8/libexec/openjdk.jdk/Contents/Home"
+6
View File
@@ -13,14 +13,20 @@ prompt-set() {
prompt-update() {
PROMPT=$(prompt-show)
}
pcolor() {
tmp="$@"
prompt "$tmp" color
}
########### Build a zsh prompt
# New line first
prompt-set 0 "&n"
# Time stamp
prompt-set 10 "&5%D{%a %m-%d %H:%M}&r "
[[ "$HOST" != "HyDEV" ]] && prompt-set 10 "&gf(#55CDFC)%D{%a} &gf(#F7A8B8)%D{%m-}&f%D{%d} &gf(#F7A8B8)%D{%H:}&gf(#55CDFC)%D{%M}&r "
# Hostname
prompt-set 20 "&1%m&r "
[[ "$HOST" == "HyDEV" ]] && prompt-set 20 "&gf(#55CDFC)H&gf(#F7A8B8)y&fD&gf(#F7A8B8)E&gf(#55CDFC)V&r "
# Username, or show a cat if I'm hykilpikonna
prompt-set 30 "&e%n&r "
[[ "$USER" == "hykilpikonna" ]] && prompt-set 30 "🐱 "
+2
View File
@@ -118,6 +118,8 @@ cut() {
echo $start
ffmpeg -i $1 -codec copy -ss $start -t $2 Cut\ $1
}
alias vcomp="$SCR/helpers/video.py"
alias vcompy="ipython -i $SCR/helpers/video.py"
# include if it exists
[ -f $HOME/extra.rc.sh ] && . $HOME/extra.rc.sh
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
# Automatically setup ubuntu
# Install essential packages
apt update
apt install curl git net-tools -y
# Add ssh keys
mkdir ~/.ssh
curl -L https://github.com/Hykilpikonna.keys > ~/.ssh/authorized_keys
# Install zsh
apt install zsh -y
chsh -s /bin/zsh
# Install zshrc
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Hykilpikonna/zshrc/HEAD/fastinstall.sh)"
# Install shadowsocks
apt install shadowsocks-libev -y
git clone https://github.com/hykilpikonna/HyDEV-Proxy
mkdir /etc/shadowsocks-libev
cp -f ./HyDEV-Proxy/ss-server.json /etc/shadowsocks-libev/hydev.json
systemctl stop shadowsocks-libev
systemctl disable shadowsocks-libev
systemctl start shadowsocks-libev-server@hydev.service
systemctl enable shadowsocks-libev-server@hydev.service