搜尋

搜尋結果

百年三尺土,萬古一堆麈
宗教玄學
熊神進・2020-06-20

人的壽命是有限度的,秦始皇吃了「長生藥」,仍然要上西天,按八字來說,我們只編排八個十運,每個大運管十年,八個大運是八十年,再加天地大運,一個人的壽齡也不超過三位歲數。三世書說,人的一生是「前有億萬年,後有億萬世,中間一百年,做得幾何事;又況人之壽,幾人能百歲。」當人沒去行善,沒去積福,大概只有幾十年的光陰;如果行善,學佛,努力做利人利己的功德,一生才是有意思。 Napoleacute;on Bonaparte 率領大軍去攻打敵人,在凱旋歸來的時候,經過一條小橋,軍隊慢慢地渡過,這時候,Napoleon 站在樹下看着士兵一個一個從橋上走過,這位大將軍沉思很久,旁邊的副官非常詫異,就問他說:ldquo;這是我們凱旋歸來,大將軍哦,為什麼你如此傷感?rdquo; Nepoleon回答說:rdquo;你看他們每一個人都是身強力健的軍人,今天帶着笑臉不可一世回國,然而再過幾十年之後,恐怕他們被新一批士兵取代了,歷史只是一個小小的點綴,有什麼了不起呢?rdquo;讀者啊,從占卜算命來說,人的生命是可以計量的,我們多活了一天生命就少了一天。百年三尺土,萬古一堆麈,前不見古人,後不見來者,念天地之悠悠,誰能不愴然而涕下。人身而得,佛法難求,我們要知道肉體雖然不能夠久存,環境的苦樂,也是暫時的事。主宰肉體和環境的真我,是永久長存的,並不隨着肉體而毁滅的。我們不應該對人生抱有消極頹廢的觀念,我們可以積極去修煉。湼槃經有一句話「若常愁苦,愁逐增長。如人喜眠,眠則滋多」當我們明白人生無常,世事如幻,就不會為名利而智昏,為小愛而痛苦。

光飛航十週年誌慶優惠:答Facebook問題或凡於「10日」生日的旅客可獲享船票折扣推廣
激安優惠
LifeMag Editor・2017-09-07

把握機會在金光飛航週年誌慶期間享受折扣優惠 金光飛航提供往來香港澳門豪華高速渡輪服務,為慶祝11月30日的十週年誌慶,將推出一系列慶祝優惠活動。推廣包括於Facebook參與問答遊戲,即有機會以折扣優惠購買金光飛航頭等艙船票。另外,凡於任何一個月份的「10日」生日的乘客,可以港幣澳門幣100元購買標準艙來回船票。 答中金光飛航Facebook問題 贏取船票優惠 你到底有多了解金光飛航呢?由即日起至10月27日期間,逢星期五早上11時30分至晚上6時正,在金光飛航的Facebook專頁正確回答三個簡單的問題,即可以港幣澳門幣100元的優惠價格購買金光飛航頭等艙成人單程船票。此優惠適用於2017年9月1日至11月30日的航班。 更多相關詳情,請瀏覽httpswww.cotaiwaterjet.comferrypromotion10thannifbgamehk.html。 生日來回船票優惠 即日起至11月30日期間,於任何一個月份的「10日」生日之乘客,即可以港幣澳門幣100元購買金光飛航標準艙來回船票。每位乘客在7天內可最多購買兩套來回船票(必須包括「10日」生日之乘客及隨行乘客一位)。 更多相關詳情,請瀏覽httpswww.cotaiwaterjet.comferrypromotion10thannibdayon10thhk.html。 金光飛航帶來最新的優惠,為旅客提供優質服務的同時回饋一直給予支持的尊貴顧客,讓他們盡享無懈可擊的旅遊體驗的承諾之一。金光飛航每天早上7時至凌晨1時提供服務;由早上7時至晚上11時30分期間之航班為每30分鐘一班,旅客可於2017年全天候享受金光飛航的優質服務以及各項獨家優惠。 更多有關金光飛航的優惠及詳情,查詢班次以及網上訂購船票請瀏覽httphk.cotaiwaterjet.comferrypromotionhk.html 或訂閱金光飛航官方Facebook httpswww.facebook.comcotaijetferry

GoPro 的「Omni」VR 拍攝套件搶先看
科技新知
LifeMag Editor・2016-04-16

說到 GoPro 的 VR 拍攝套件,你首先想到的,可能是他們跟 Google 聯手打造的「大殺器」Odyssey。但其實在那之前,這家公司就已經確定了自產裝置的開發計畫。去年年中時,這款後來被命名為「Omni」的產品,就已經跟空拍機一起,得到了 GoPro CEO Nick Woodman 的親口證實。在那以後,我們陸續見過幾款 Omni 的原型機,但直到今天,廠方才終於公開了成品的外觀設計,並且拿出了實拍樣本與大家分享。 跟裝載 16 台 GoPro 相機、總價 US$15,000 還不是人人能買到的 Odyssey 相比,「只」需要 6 台 Black(大概價值 US$3,000)的 Omni,門檻無疑要低了不少。而且對許多專業用戶或 Prosumer 來說,可能目前擁有的裝置數量就已經達到了要求。不過,Omni 跟 Odyssey 有一處明顯的不同是,它並不會以 3D 形式來拍攝內容。但 GoPro 聲稱自己能在相機之間實現「畫素級別」的同步效果,而且整套系統也可搭配 Kolor 合成軟體(去年四月被 GoPro 收購)無縫使用。值得一提的是,在新發佈的產品圖中,Omni 內部看起來似乎無法容下相機的防水外殼,這跟之前流出的照片不太一樣,看來還有待官方進一步的確認。 實際上,類似的第三方 VR 拍攝組目前在市面上也有不少(你甚至可以用很低的成本去 3D 列印一個出來),但在相機調配、影片合成等方面,總不如原廠方案來得到位、省心。而 Omni 就是至今為止第一款完全由相機廠商自己開發出來的套件,照理來說,在使用上的優勢應該還是非常明顯的。當然囉,其價格多半也會更貴一點,雖然具體的數字現在還沒確定,但在即將舉行的 NAB 大展上,GoPro 應該會告訴我們更多的發售細節吧。 轉載自:Engadget

Google無人駕駛車公路實測
汽車
Benjamin・2015-06-30

Google無人駕駛車車場實測 Google無人駕駛車公路實測 Google無人駕駛車舊款設計 Google無人駕駛車新版 相信大家一定有聽過Google Car,它是由Google研發的無人駕駛車,而Google一直致力發展嶄新科技,以及不斷進行測試,而且他們早前已於實驗場地進行測試。而今天,他們更邁向了一個新里程碑,因 Google 無人駕駛車已經正式開始在美國加州的路面上實地測試,可見距離實際應用又行前了一大步。 其實上月 Google 就曾經表示過將會在今年夏天,在美國加州 Mountain View 附近的路面上實際進行測試,而有關測試終於在今日起正式實行。雖然那台是無人車,而且的確會由電腦系統控制,自動進行駕駛,不過今次與早前邀請市民試搭不同,路面測試時將會有合資格的司機在車上監測整個駕駛情況,而且車廂內亦會設有軚盤及腳踏,以防有任何問題,便可以立即切換手動控制。 另外,Google 同時亦在網上開設了一個特別的網頁,如任何人在路面上發現 Google 無人駕駛車,可以在網站上分享自己的感想,例如覺得好棒、很奇怪,甚至很害怕等都可以,Google 將會根據這些評價去進行改善。此外,為盡量確保Google SelfCar 不會在公路上發生意外,因此無人駕駛車的時速將會被限制在 40 公里以下,而不會瞬間消失的。 Google SelfCar 相關影片: youtu.beCqSDWoAhvLU Google SelfCar 特設網頁: www.google.comselfdrivingcar

Spring Boot 05 - 為 http json api 加入登入要求
科技新知
MacauYeah・2024-07-02

本節,我們將為之前的http服務,加入認證機制,只有在資料庫現存的用戶可以登入及訪問我們的json api。 下戴模版 慣例,我們用Spring Initializr Maven 下載模版,Dependency主要選擇 Spring Web Spring Boot DevTools Spring Security Controller 跟上節一樣,我們起一個Controller,為簡化測試,我們只做http GET api。 由於本blog對於Source Code的顯示不太友好,有需要看source code的,請到Github查看 srcmainjavaiogithubmacauyeahspringboottutorialspringbootwebapidatacontrollerHomeController.java import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMappingquot;apiquot; public class HomeController @GetMappingquot;someRecorduuidquot; public Map readSomeRecord@PathVariable String uuid return Map.ofquot;retquot;, quot;your uuidquot; uuid; 準備我們的test case,但這次我們預期它應該要出現登入失敗的結果。 srctestjavaiogithubmacauyeahspringboottutorialspringbootwebapidatacontrollerHomeControllerTest.java @SpringBootTest @AutoConfigureMockMvc public class HomeControllerTest @Autowired private MockMvc mockMvc; @Test void testNoLogin throws Exception RequestBuilder requestBuilder = MockMvcRequestBuilders.getquot;apisomeRecord1234quot; .contentTypeMediaType.APPLICATION_JSON; this.mockMvc.performrequestBuilder .andExpectMockMvcResultMatchers.status.is4xxClientError .andExpectMockMvcResultMatchers.jsonPathquot;$.retquot;.doesNotExist .andDoMockMvcResultHandlers.print; 在我們執行上述的測試,test case 成功過了。我們的基本設定跟上一節其實沒有多大改動,為何現在http api會回傳狀態 401? 那是因為我們在依賴中加了,Spring Security,它配合了Spring Web,就會自動為所有api加入權限檢測。我們的測試中,沒有任何用戶登入,當然會出現 http 401。為了讓我們可以好好管理誰可以使用api,我們就來設定一定Security。 我們加一個WebSecurityConfig.java,暫時指定所有的訪問路徑都必需有USER權限,並且用 http basic的方式登入。 srcmainjavaiogithubmacauyeahspringboottutorialspringbootwebapidataconfigWebSecurityConfig.java import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.web.SecurityFilterChain; @Configuration @EnableWebSecurity public class WebSecurityConfig @Bean SecurityFilterChain securityFilterChainHttpSecurity http throws Exception http.authorizeHttpRequestsauthorizeHttpRequests gt; authorizeHttpRequests.requestMatchersquot;quot;.hasRolequot;USERquot;; 所有的訪問路徑都必需有USER權限 ; http.httpBasicCustomizer.withDefaults; 使用http basic作為登入認證的方式 return http.build; 上述例子,只是擋了沒有權限的人,我們還需要讓有登入身份的用戶可以成得取限User權限。 我們繼續修改,WebSecurityConfig,加入只在記憶體有效的InMemoryUser import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.provisioning.InMemoryUserDetailsManager; public class WebSecurityConfig .. @Bean public PasswordEncoder passwordEncoder return new BCryptPasswordEncoder; 我們的密碼不應該明文儲,比較保險,我們使用BCrypt演算法,為密碼做單向加密。 @Bean public UserDetailsService userDetailsService UserDetails user = User.withUsernamequot;adminquot; .passwordpasswordEncoder.encodequot;passquot; .rolesquot;USERquot;.build; 我們在記憶中體,加入一個測試用的User,它的名字為admin,密碼為pass,權限為User return new InMemoryUserDetailsManageruser; 然後加入新的測試,直接模擬Role。結果是通過的。 srctestjavaiogithubmacauyeahspringboottutorialspringbootwebapidatacontrollerHomeControllerTest.java @Test void testLoginWithRoles throws Exception RequestBuilder requestBuilder = MockMvcRequestBuilders.getquot;apisomeRecord1234quot; .contentTypeMediaType.APPLICATION_JSON.with SecurityMockMvcRequestPostProcessors.userquot;someonequot; .rolesquot;USERquot;, quot;ADMINquot;; 沒有使用密碼,只使用Role this.mockMvc.performrequestBuilder .andExpectMockMvcResultMatchers.status.is2xxSuccessful .andExpectMockMvcResultMatchers.jsonPathquot;$.retquot;.valuequot;your uuid1234quot; .andDoMockMvcResultHandlers.print; 再來一個測試,改用密碼登入,分別輸入錯的和正確的密碼。 @Test void testLoginWithWrongPasswordAndNoRole throws Exception RequestBuilder requestBuilder = MockMvcRequestBuilders.getquot;apisomeRecord1234quot; .headerquot;Authorizationquot;, quot;Basic randompassquot; 輸入錯的密碼,應該回傳http 401 Unauthorized .contentTypeMediaType.APPLICATION_JSON; this.mockMvc.performrequestBuilder .andExpectMockMvcResultMatchers.status.is4xxClientError .andDoMockMvcResultHandlers.print; @Test void testLoginWithPassword throws Exception RequestBuilder requestBuilder = MockMvcRequestBuilders.getquot;apisomeRecord1234quot; .headerquot;Authorizationquot;, quot;Basic YWRtaW46cGFzcw==quot; http basic 就是把 adminpass 轉成base64 .contentTypeMediaType.APPLICATION_JSON; this.mockMvc.performrequestBuilder .andExpectMockMvcResultMatchers.status.is2xxSuccessful .andExpectMockMvcResultMatchers.jsonPathquot;$.retquot;.valuequot;your uuid1234quot; .andDoMockMvcResultHandlers.print; 最後,當然是正確的密碼才能通過。若果大家還是半信半疑,我們可以跑起真的正服務(IDE RUN或mvn springbootrun),然後用curl去試。 curl httplocalhost8080apisomeRecord1234 failed with 401 curl u quot;adminpassquot; httplocalhost8080apisomeRecord1234 successed 使用SQL Database讀取用戶登入資訊 一般而言,我們不可能把所有用戶登資訊打在InMemoryUser中,通常背後有一個資料庫儲存所有的用戶資訊,我們在登入時,讀取它來做對比檢證。 為此,我們在maven中,加入 Spring Data JPA h2 database (或任何你的資料庫,如mysql 、 sql server) 最後一步,我們把InMemoryUser去掉,改為從資料庫讀取。因為原始碼太多,就不全部貼上。最主要的是WebSecurityConfig.java要關掉之前的UserDetailsService,改為提供一個UserServiceImpl類,它會實現UserDetailsService的功能。 @Configuration @EnableWebSecurity public class WebSecurityConfig 把原來的Bean先變成註解,其他不變 @Bean public UserDetailsService userDetailsService UserDetails user = User.withUsernamequot;adminquot; .passwordpasswordEncoder.encodequot;passquot; .rolesquot;USERquot;.build; return new InMemoryUserDetailsManageruser; springboottutorialspringbootwebapidatasrcmainjavaiogithubmacauyeahspringboottutorialspringbootwebapidataconfigUserServiceImpl.java other import import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.password.PasswordEncoder; @Service public class UserServiceImpl implements UserDetailsService @Autowired PasswordEncoder passwordEncoder; @Autowired UserRepo userRepo; @Override public UserDetails loadUserByUsernameString username throws UsernameNotFoundException 因為我們資料庫沒有資料,為了方便測試密碼的加密,我們在java code上直接插入一筆資料。 UserEntity defaultUser = new UserEntity; defaultUser.setUsernamequot;adminquot;; defaultUser.setPasswordpasswordEncoder.encodequot;passquot;; defaultUser.setRolequot;USERquot;; defaultUser.setUuidUUID.randomUUID.toString; userRepo.savedefaultUser; 上述為測試用插入資料,不應該出現在正式使用環境中。 UserEntity user = userRepo.findOneByUsernameusername .orElseThrow gt; new UsernameNotFoundExceptionusername quot; not foundquot;; 找找資料庫有沒有正在登入的該名使用者username List authorities = List.ofnew SimpleGrantedAuthorityquot;ROLE_quot; user.getRole; LOG.debugquot;got user uuid, username, role from databasequot;, user.getUuid, username, user.getRole; 如果前面的 findOneByUsername 有結果回傳,我們就給它一個ROLE_XXX的權限。 return new Userusername, user.getPassword, authorities; 這裏從沒有檢查過密碼是否有匹配,全部交給Spring Security去做 springboottutorialspringbootwebapidatasrcmainjavaiogithubmacauyeahspringboottutorialspringbootwebapidataentityUserEntity.java springboottutorialspringbootwebapidatasrcmainjavaiogithubmacauyeahspringboottutorialspringbootwebapidatarepoUserRepo.java 上述段落中,筆者省略了UserEntity和UserRepo,它們只是一般的springdatajpa概念,有需要可以經文末的連結查看完全原始碼。最需要注意的,是UserEntity的password欄位,在資料庫中是以加密的方式儲存。我們在配匹登入者與資料庫記錄時,也沒有自行檢驗密碼的需要。我們只是在加密過的密碼回傳給Spring Security,Spring框架會自行把登入者輸入的密碼與加密了的密碼作比較。