From 3f9e614a8ba507b46045b695997376076b603782 Mon Sep 17 00:00:00 2001 From: myoshizumi Date: Wed, 11 Feb 2026 13:21:02 +0900 Subject: [PATCH] Enhance SRI script robustness and refine Restaurant docs --- .../Claude/Easy/Restaurant/Restaurant.md | 7 ++----- calc_sri_fix.sh | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) mode change 100644 => 100755 calc_sri_fix.sh diff --git a/Mathematics/Fundamentals/HackerRank/Claude/Easy/Restaurant/Restaurant.md b/Mathematics/Fundamentals/HackerRank/Claude/Easy/Restaurant/Restaurant.md index a6199d0f..82da7bbc 100644 --- a/Mathematics/Fundamentals/HackerRank/Claude/Easy/Restaurant/Restaurant.md +++ b/Mathematics/Fundamentals/HackerRank/Claude/Easy/Restaurant/Restaurant.md @@ -210,10 +210,7 @@ from __future__ import annotations import math import os -from typing import TYPE_CHECKING -if TYPE_CHECKING: - pass def restaurant(l: int, b: int) -> int: @@ -298,12 +295,12 @@ if __name__ == '__main__': ### 定数倍削減テクニック ```python -# ❌ 非効率: 中間変数の無駄な生成 +# 可読性重視: 中間変数を使った例 area = l * b square_area = g * g result = area // square_area -# ✅ 最適: 1行で計算 +# より簡潔に書ける result = (l * b) // (g * g) ``` diff --git a/calc_sri_fix.sh b/calc_sri_fix.sh old mode 100644 new mode 100755 index f3974247..e71fa62f --- a/calc_sri_fix.sh +++ b/calc_sri_fix.sh @@ -1,9 +1,28 @@ #!/bin/bash +set -euo pipefail + calculate_sri() { url="$1" - hash=$(curl -sL "$url" | openssl dgst -sha384 -binary | openssl base64 -A) + temp_file=$(mktemp) + + # curl options: -f (fail on HTTP error), -S (show error), -s (silent equivalent), -L (follow redirects) + if ! curl -fS -sL "$url" -o "$temp_file"; then + echo "Error downloading $url" >&2 + rm -f "$temp_file" + return 1 + fi + + # Check for empty response + if [ ! -s "$temp_file" ]; then + echo "Error: Empty response from $url" >&2 + rm -f "$temp_file" + return 1 + fi + + hash=$(openssl dgst -sha384 -binary < "$temp_file" | openssl base64 -A) echo "$url sha384-$hash" + rm -f "$temp_file" } calculate_sri "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.js"