Summary

Yosef Karo Translation:Shulchan Aruch — Orach Chaim 329…

Paragraph 6 - Regarding non-Jews who besiege Jewish cities: if they come for money, we do not desecrate the Shabbat [to protect ourselves] , but if they came to kill or come with no presented reason, we go out with weapons and desecrate the Shabbat. In a city that is near the border, even if they just come for straw or hay, we desecrate the Shabbat.
Source: Wikisource

Yosef Karo Translation:Shulchan Aruch — Orach Chaim 329…

Paragraph 8 - One who sees a boat with Jews that is endangered at sea or in a flowing river, or an individual being chased by idolaters, it is a commandment to desecrate Shabbat to save them. (And see above at the end of chapter 306 regarding whether one desecrates Shabbat if someone wants to rape him.)
סעיף ח - הרואה ספינה שיש בה ישראל המטרפת בים, וכן נהר שוטף, (וכן) יחיד הנרדף מפני עובד כוכבים, מצוה על כל אדם לחלל עליהם שבת כדי להצילם (ועין לעיל סוף סימן ש"ו, מי שרוצים לאנסו, אם מחללין עליו שבת) .
Source: Wikisource

Get perspective with Kwize: daily news enlightened by great literature