Skip to content

Commit 1570f94

Browse files
committed
feat(scripts): add clean_submit_code script and claude permissions
1 parent 0b42000 commit 1570f94

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

.claude/settings.local.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(chmod:*)",
5+
"Bash(\"/Users/lzwjava/projects/algorithm-solutions/scripts/clean_submit_code.py\")"
6+
]
7+
}
8+
}

scripts/clean_submit_code.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import re
4+
import subprocess
5+
import textwrap
6+
7+
def main():
8+
try:
9+
code = subprocess.check_output(['pbpaste']).decode('utf-8')
10+
except Exception as e:
11+
print(f"Failed to read pasteboard: {e}", file=sys.stderr)
12+
sys.exit(1)
13+
14+
# Clean trailing whitespace from each line
15+
lines = [line.rstrip() for line in code.splitlines()]
16+
code = '\n'.join(lines) + '\n'
17+
18+
# Dedent the code to fix indentation issues
19+
try:
20+
code = textwrap.dedent(code)
21+
except:
22+
pass # Ignore if dedent fails
23+
24+
# Check if it's Java code
25+
if 'public class' not in code:
26+
print('Not Java code')
27+
sys.exit(1)
28+
29+
30+
# Find and rename class (MainPro, MainPlus, etc. to Main)
31+
match = re.search(r'public\s+class\s+(\w+)', code)
32+
if match:
33+
old_class = match.group(1)
34+
if old_class.startswith('Main') and old_class != 'Main' and len(old_class) > 4:
35+
code = re.sub(r'\b' + re.escape(old_class) + r'\b', 'Main', code)
36+
print(f'Renamed {old_class} to Main')
37+
38+
# Copy cleaned code back to pasteboard
39+
try:
40+
subprocess.run(['pbcopy'], input=code.encode('utf-8'), check=True)
41+
except Exception as e:
42+
print(f"Failed to write to pasteboard: {e}", file=sys.stderr)
43+
sys.exit(1)
44+
45+
print('The code is adjusted, please submit')
46+
47+
if __name__ == '__main__':
48+
main()

src/main/java/com/lzw/solutions/codeforces/p2190A/Main.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.io.InputStreamReader;
66
import java.io.PrintWriter;
77
import java.util.ArrayList;
8-
import java.util.Arrays;
98

109
public class Main {
1110

src/main/java/com/lzw/solutions/codeforces/p2190A/MainPro.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.io.IOException;
55
import java.io.InputStreamReader;
66
import java.io.PrintWriter;
7-
import java.util.ArrayList;
87

98
public class MainPro {
109

0 commit comments

Comments
 (0)