Skip to content

Commit 2c2282e

Browse files
authored
Merge pull request #265 from myoshi2891/dev-from-macmini
Enhance SRI script robustness and refine Restaurant docs
2 parents 4c015b2 + 3f9e614 commit 2c2282e

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

Mathematics/Fundamentals/HackerRank/Claude/Easy/Restaurant/Restaurant.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,7 @@ from __future__ import annotations
210210

211211
import math
212212
import os
213-
from typing import TYPE_CHECKING
214213

215-
if TYPE_CHECKING:
216-
pass
217214

218215

219216
def restaurant(l: int, b: int) -> int:
@@ -298,12 +295,12 @@ if __name__ == '__main__':
298295
### 定数倍削減テクニック
299296

300297
```python
301-
# ❌ 非効率: 中間変数の無駄な生成
298+
# 可読性重視: 中間変数を使った例
302299
area = l * b
303300
square_area = g * g
304301
result = area // square_area
305302

306-
# ✅ 最適: 1行で計算
303+
# より簡潔に書ける
307304
result = (l * b) // (g * g)
308305
```
309306

calc_sri_fix.sh

100644100755
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
#!/bin/bash
22

3+
set -euo pipefail
4+
35
calculate_sri() {
46
url="$1"
5-
hash=$(curl -sL "$url" | openssl dgst -sha384 -binary | openssl base64 -A)
7+
temp_file=$(mktemp)
8+
9+
# curl options: -f (fail on HTTP error), -S (show error), -s (silent equivalent), -L (follow redirects)
10+
if ! curl -fS -sL "$url" -o "$temp_file"; then
11+
echo "Error downloading $url" >&2
12+
rm -f "$temp_file"
13+
return 1
14+
fi
15+
16+
# Check for empty response
17+
if [ ! -s "$temp_file" ]; then
18+
echo "Error: Empty response from $url" >&2
19+
rm -f "$temp_file"
20+
return 1
21+
fi
22+
23+
hash=$(openssl dgst -sha384 -binary < "$temp_file" | openssl base64 -A)
624
echo "$url sha384-$hash"
25+
rm -f "$temp_file"
726
}
827

928
calculate_sri "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.js"

0 commit comments

Comments
 (0)