<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gary Yeh on Medium]]></title>
        <description><![CDATA[Stories by Gary Yeh on Medium]]></description>
        <link>https://medium.com/@cashbooktw?source=rss-18d2a0191e28------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5YU0yqUuZaS63gXo.</url>
            <title>Stories by Gary Yeh on Medium</title>
            <link>https://medium.com/@cashbooktw?source=rss-18d2a0191e28------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 07:04:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cashbooktw/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[攝影基礎基本]]></title>
            <link>https://medium.com/@cashbooktw/%E6%94%9D%E5%BD%B1%E5%9F%BA%E7%A4%8E%E5%9F%BA%E6%9C%AC-477f32bc5dfe?source=rss-18d2a0191e28------2</link>
            <guid isPermaLink="false">https://medium.com/p/477f32bc5dfe</guid>
            <category><![CDATA[攝影]]></category>
            <category><![CDATA[photography]]></category>
            <dc:creator><![CDATA[Gary Yeh]]></dc:creator>
            <pubDate>Fri, 13 Oct 2023 03:12:08 GMT</pubDate>
            <atom:updated>2023-10-13T03:12:08.685Z</atom:updated>
            <content:encoded><![CDATA[<h3>攝影基礎基本篇</h3><h3>攝影基本概念</h3><h4>1. 光線和影像</h4><ul><li>光線的角度和方向： 光線的角度和方向影響照片的陰影和亮度，不同的光線可以創造出截然不同的效果。</li><li>自然光和人工光： 自然光來自太陽和天空，而人工光來自燈光等人造光源。攝影師需要了解如何利用這些光源來拍攝照片。</li></ul><h4>2. 曝光三要素</h4><ul><li>光圈（Aperture）： 光圈控制進入相機的光線量。較大的光圈（小數字如f/1.8）使更多光線進入，創造出較模糊的背景（景深較淺）；較小的光圈（大數字如f/16）使較少光線進入，背景較清晰（景深較深）。</li><li>快門速度（Shutter Speed）： 快門速度控制曝光時間，即相機的快門打開多長時間。較短的快門速度（例如1/1000秒）適合拍攝快速運動或避免模糊；較長的快門速度（例如1秒）適合拍攝夜景或捕捉運動的軌跡。</li><li>ISO感光度： ISO值表示相機的感光度，較高的ISO（例如ISO 800）適合低光環境，但可能產生噪點；較低的ISO（例如ISO 100）適合光線充足的場景，影像較清晰。</li></ul><h4>3. 對焦和景深</h4><ul><li>對焦： 確保主題清晰銳利地呈現在照片中，可以使用自動對焦或手動對焦來實現。</li><li>景深（Depth of Field）： 指的是照片中清晰的範圍，受光圈和相機與主題的距離影響。較小的光圈（大景深）可使整個場景保持清晰，而較大的光圈（小景深）使主題清晰，背景模糊。</li></ul><h4>4. 構圖和視覺語言</h4><ul><li>構圖： 是指照片中各個元素的排列和配置，包括主題的位置、比例、角度等。常見的構圖原則包括規則三分法、黃金分割、對角線等。</li><li>視覺語言： 是指攝影師通過照片傳達訊息和情感的方式。這包括選擇適當的主題、色彩、光線、構圖等來打動觀眾，讓照片有更深的意義。</li></ul><h3>攝影器材介紹</h3><h4>1. 相機類型</h4><ul><li>數位單鏡反光相機（DSLR）： DSLR相機具有可更換鏡頭、光學取景器、高畫質傳感器等特點，適合尋求高質量影像的攝影愛好者和專業攝影師。</li><li>無反光鏡相機（Mirrorless）： 無反相機相對輕巧，並且具有高畫質傳感器和可更換鏡頭，是一些攝影師和攝影愛好者的首選。</li><li>單反相機（Point and Shoot）： 简易便攜的相機，適合日常隨身攜帶，但功能和影像質量相對較低。</li></ul><h4>2. 鏡頭類型</h4><ul><li>標準鏡頭： 一般具有固定焦距（例如50mm），適合拍攝各種主題，是新手攝影師的好選擇。</li><li>廣角鏡頭： 適合拍攝廣大的景觀、建筑等，能夠捕捉更多的場景。</li><li>望遠鏡頭： 適合遠距離拍攝，如野生動物、鳥類等，能夠拉近主題。</li><li>微距鏡頭： 專為拍攝微小物體設計，能夠捕捉高度細節，常用於昆蟲、花朵等攝影。</li></ul><h4>3. 其他攝影配件</h4><ul><li>三腳架： 用於固定相機，保證拍攝穩定性，特別適用於夜景、長時間曝光等拍攝。</li><li>過濾器： 例如偏光鏡、減光鏡等，用於調節光線、增加對比度等效果。</li><li>閃光燈： 用於補光，適用於光線不足或需要營造特殊光線效果的場合。</li><li>儲存卡： 選擇高速、大容量的記憶卡，確保能夠儲存大量高質量的照片和視頻。</li></ul><h4>4. 選購攝影器材的注意事項</h4><ul><li>預算： 根據自身預算選擇適合的器材，考慮相機、鏡頭、配件等的價格。</li><li>需求： 根據自身攝影需求，選擇適合的相機類型和鏡頭類型。</li><li>品牌和評價： 選擇知名品牌，並且參考用戶評價和專業評測，了解器材的性能和可靠性。</li></ul><h3>光線和色彩在攝影中的重要性</h3><h4>1. 光線：</h4><ul><li>光線的方向和角度： 光線的角度和方向對於影像的陰影和高光部分有著直接影響。拍攝時間的選擇（早上、傍晚）可以影響光線的柔和度和色溫。</li><li>自然光和人工光： 自然光（陽光、月光）和人工光（燈光、閃光燈）都有獨特的特點，攝影師需要了解如何利用這些光源。</li><li>光線的品質： 軟光（陰天光）產生柔和陰影，硬光（陽光直射）則產生銳利陰影，攝影師需根據主題選擇適合的光線品質。</li></ul><h4>2. 色彩：</h4><ul><li>色彩的心理學作用： 不同的顏色能夠喚起觀眾不同的情緒和反應。例如，紅色可能代表熱情和活力，藍色可能代表冷靜和穩重。</li><li>白平衡： 調整白平衡可以適應不同光源下的色彩溫度，確保影像中的白色看起來真實無誤。</li><li>對比度： 對比度高的照片色彩鮮豔，有層次感，而低對比度則顏色更柔和，更具溫暖感。</li></ul><h3>光線和色彩的重要性：</h3><h4>1. 光線：</h4><ul><li>光線的方向和角度： 光線的角度和方向對於影像的陰影和高光部分有著直接影響。拍攝時間的選擇（早上、傍晚）可以影響光線的柔和度和色溫。</li><li>自然光和人工光： 自然光（陽光、月光）和人工光（燈光、閃光燈）都有獨特的特點，攝影師需要了解如何利用這些光源。</li><li>光線的品質： 軟光（陰天光）產生柔和陰影，硬光（陽光直射）則產生銳利陰影，攝影師需根據主題選擇適合的光線品質。</li></ul><h4>2. 色彩：</h4><ul><li>色彩的心理學作用： 不同的顏色能夠喚起觀眾不同的情緒和反應。例如，紅色可能代表熱情和活力，藍色可能代表冷靜和穩重。</li><li>白平衡： 調整白平衡可以適應不同光源下的色彩溫度，確保影像中的白色看起來真實無誤。</li><li>對比度： 對比度高的照片色彩鮮豔，有層次感，而低對比度則顏色更柔和，更具溫暖感。</li></ul><h3>如何利用光線和色彩拍攝出優秀的照片：</h3><ol><li>熟悉不同光線條件： 學會在不同光線條件下拍攝，早晨和黃昏時分的陽光較柔和，適合人像和風景攝影。陰天光線均勻，適合拍攝細節豐富的主題。</li><li>利用陰影和高光： 充分利用陰影和高光，創造出層次感。避免陽光直射，可以使用遮陽板或等待光線改變的時候拍攝。</li><li>尋找色彩對比： 尋找色彩鮮明對比強烈的場景，這樣的照片通常更吸引人的眼球。</li><li>瞭解白平衡： 根據光源的色溫調整白平衡，確保色彩真實自然。</li><li>色彩搭配和運用： 學習不同色彩的搭配，創造出和諧或對比強烈的視覺效果。</li><li>夜景攝影技巧： 夜間光線獨特，學習長時間曝光、適當的ISO設定和使用三腳架等技巧，拍攝迷人的夜景照片。</li></ol><h3>曝光和快門速度在攝影中的重要性：</h3><h4>1. 曝光：</h4><ul><li>曝光是什麼？ 曝光是指攝影感光元件（如數位相機的感光元件或底片）接收光線的時間。正確的曝光意味著影像中的亮度、對比度和顏色都能夠得到良好的呈現。</li><li>曝光三要素： 曝光量由光圈、快門速度和ISO感光度三要素控制。合適的組合可以確保照片的亮度和細節。</li></ul><h4>2. 快門速度：</h4><ul><li>快門速度是什麼？ 快門速度（Shutter Speed）是指快門打開的時間長短。較短的快門速度（例如1/1000秒）表示快門打開的時間非常短，適合拍攝運動、避免手持拍攝時的晃動。</li><li>快門速度的應用： 適當的快門速度可以凝結運動、拍攝高速運動，也可以用來拍攝夜景，營造模糊的效果，例如拍攝流水效果或星軌。</li></ul><h3>如何選擇適當的曝光和快門速度：</h3><ol><li>理解曝光三要素： 光圈、快門速度和ISO感光度之間存在著平衡關係。更大的光圈（較小的數字）和較高的ISO值可以配合較短的快門速度，以應對光線不足的環境。</li><li>運動攝影： 如果你拍攝的是快速運動，應選擇較短的快門速度（例如1/500秒或更短），以捕捉運動中的細節，同時保持照片清晰。</li><li>拍攝靜物： 對於拍攝靜物，你可以使用較長的快門速度（例如1/30秒或更長），同時使用三腳架，以確保照片清晰且充滿細節。</li><li>夜景攝影： 在拍攝夜景時，你可以使用較長的快門速度（幾秒甚至數分鐘）來捕捉足夠的光線，這樣可以獲得明亮的夜景照片。</li><li>運用快門速度創造特殊效果： 使用較長的快門速度可以創造出模糊效果，例如捕捉運動物體的運動軌跡，而較短的快門速度則可以凝結快速運動，使被攝物體保持清晰。</li></ol><h3>光圈和景深在攝影中的重要性：</h3><h4>1. 光圈：</h4><ul><li>光圈是什麼？ 光圈（Aperture）是鏡頭內的可調範圍，控制進入相機的光線量。光圈的大小由f值表示，例如f/1.8、f/2.8等。</li><li>光圈和景深的關係： 較大的光圈（較小的f值）允許更多光線進入，創造出較模糊的背景（景深較淺）；較小的光圈（較大的f值）限制光線進入，背景較清晰（景深較深）。</li></ul><h4>2. 景深：</h4><ul><li>景深是什麼？ 景深（Depth of Field）指的是照片中清晰的範圍，即在照片中前景和背景的範圍內哪些部分是清晰的。</li><li>景深和光圈的關係： 光圈越大，景深越淺，只有很小一部分畫面是清晰的。光圈越小，景深越深，更多的前景和背景都會保持清晰。</li></ul><h3>如何選擇適當的光圈和景深：</h3><ol><li>人像攝影： 如果你想將人物突出，使背景模糊，可以選擇較大的光圈（小f值）以及較淺的景深。這樣可以將焦點放在人物上，背景就會自然模糊，突出主題。</li><li>風景攝影： 在風景攝影中，通常需要較大的景深來確保整個風景都保持清晰。因此，選擇較小的光圈（大f值）是常見的做法。這樣可以使前景、中景和背景都能夠清晰呈現。</li><li>微距攝影： 在拍攝微距照片時，較小的光圈（大f值）是必需的，以確保被攝物體的細節清晰可見。這樣的情況下，景深通常非常淺，只有非常小的範圍是清晰的。</li><li>創意攝影： 有時，你可能希望在照片中創造出特殊的效果，例如模糊的背景或者前景。這就需要根據你的創意選擇適當的光圈和景深，可能需要實際測試不同的設定以找到最合適的效果。</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=477f32bc5dfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to OOP and C++ Basics]]></title>
            <link>https://medium.com/@cashbooktw/introduction-to-oop-and-c-basics-6b6ed5c0f9c9?source=rss-18d2a0191e28------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b6ed5c0f9c9</guid>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[oop]]></category>
            <dc:creator><![CDATA[Gary Yeh]]></dc:creator>
            <pubDate>Wed, 30 Aug 2023 02:18:44 GMT</pubDate>
            <atom:updated>2023-08-30T02:18:44.378Z</atom:updated>
            <content:encoded><![CDATA[<h3>Brief introduction to OOP concepts (Abstraction, Encapsulation, Inheritance, Polymorphism)</h3><p>Object-Oriented Programming (OOP) is a programming paradigm that structures code around the concept of “objects.” Objects are instances of classes, which are user-defined data types that encapsulate both data (attributes) and functions (methods) that operate on the data. OOP offers a powerful way to design and organize code, making it more modular, reusable, and easier to maintain.</p><p><strong>1. Abstraction:</strong> Abstraction is the process of simplifying complex reality by modeling classes appropriate to the problem. It involves focusing on essential properties and behaviors of an object while ignoring unnecessary details. In OOP, abstraction allows you to create classes that represent real-world entities and their core characteristics, without getting bogged down in the intricacies.</p><p><strong>2. Encapsulation:</strong> Encapsulation involves bundling data (attributes) and the methods (functions) that operate on that data into a single unit called a class. The data is hidden from outside access, and only the methods provided by the class can manipulate it. This concept helps in achieving data security and prevents unintended interference with an object’s internal state.</p><p><strong>3. Inheritance:</strong> Inheritance is a mechanism that allows a new class (subclass or derived class) to inherit properties and behaviors (attributes and methods) from an existing class (superclass or base class). It promotes code reusability and establishes a hierarchical relationship between classes. Subclasses can add new features or modify existing ones inherited from the base class.</p><p><strong>4. Polymorphism:</strong> Polymorphism refers to the ability of different classes to be treated as instances of the same base class through a common interface. It allows you to write code that can work with objects of various classes without needing to know the specific class at compile time. Polymorphism is achieved through method overriding and interfaces, enabling dynamic binding of methods at runtime.</p><h3>Introduction to C++ as an OOP language</h3><p>C++ is a versatile programming language that fully supports Object-Oriented Programming (OOP) concepts, making it a powerful tool for designing and implementing complex software systems. It seamlessly integrates the features of procedural programming with those of OOP, allowing developers to create efficient, modular, and reusable code.</p><p><strong>1. Classes and Objects:</strong> C++ allows you to define your own data types using classes. A class is a blueprint that defines the attributes (data members) and methods (functions) that an object of that class will have. An object is an instance of a class, and it encapsulates data and behavior related to a specific concept or entity.</p><p><strong>2. Encapsulation and Access Control:</strong> C++ supports encapsulation by allowing you to specify access control levels for class members. Members can be marked as public, private, or protected. Private members are only accessible within the class, protecting the internal state of an object. Public members can be accessed from outside the class, providing an interface to interact with the object.</p><p><strong>3. Inheritance:</strong> C++ facilitates inheritance, enabling you to create new classes based on existing ones. The derived class inherits the attributes and methods of the base class. This allows for code reuse and the creation of class hierarchies that reflect real-world relationships. You can specify different types of inheritance, such as public, protected, and private inheritance.</p><p><strong>4. Polymorphism:</strong> C++ supports polymorphism through virtual functions and function overriding. A base class can have virtual functions, which are overridden in derived classes. This enables dynamic binding of functions at runtime, allowing different objects to respond differently to the same method call.</p><p><strong>5. Constructors and Destructors:</strong> C++ introduces constructors and destructors. A constructor is a special member function that is called when an object is created, allowing you to initialize its data members. A destructor is called when an object goes out of scope, providing an opportunity to perform cleanup tasks.</p><p><strong>6. Operator Overloading:</strong> C++ lets you redefine operators for user-defined classes, allowing you to customize their behavior. This enhances the naturalness and readability of code when working with user-defined types.</p><p><strong>7. Templates and Generic Programming:</strong> Templates enable generic programming by allowing you to create functions and classes that work with different data types. This enhances code reusability and flexibility.</p><p><strong>8. Standard Template Library (STL):</strong> C++ comes with a rich Standard Template Library (STL) that provides containers (like vectors, lists, maps) and algorithms (like sorting, searching) to simplify common programming tasks.</p><h3>Setting up a C++ development environment (IDEs, compilers)</h3><p>A well-configured development environment is crucial for efficient and effective C++ programming. This environment includes an Integrated Development Environment (IDE) for writing, editing, debugging, and managing code, as well as a compiler to convert your C++ code into executable programs.</p><p><strong>1. Integrated Development Environments (IDEs):</strong></p><p>An IDE is a software application that provides a comprehensive set of tools for software development. It streamlines the development process by combining code editing, debugging, project management, and other features into a single interface. Here are a few popular C++ IDEs:</p><ul><li><strong>Visual Studio:</strong> A widely-used IDE developed by Microsoft. It offers a powerful set of features, including code analysis, debugging tools, and integration with version control systems.</li><li><strong>Code::Blocks:</strong> An open-source, cross-platform IDE with a user-friendly interface. It supports multiple compilers and offers code completion, syntax highlighting, and a built-in debugger.</li><li><strong>Eclipse:</strong> Originally designed for Java, Eclipse has C/C++ development tools (CDT) that provide an IDE experience for C++ programmers. It supports multiple build systems and version control integration.</li><li><strong>CLion:</strong> Developed by JetBrains, CLion is a dedicated C++ IDE with advanced coding assistance, smart code completion, and powerful refactoring tools.</li></ul><p><strong>2. Compilers:</strong></p><p>A compiler is a program that translates human-readable C++ code into machine-readable executable files. Different compilers may have varying levels of optimization and adherence to language standards. Here are a few commonly used C++ compilers:</p><ul><li><strong>GNU Compiler Collection (GCC):</strong> A widely-used compiler suite that supports many programming languages, including C++. It’s known for its robustness and adherence to language standards.</li><li><strong>Clang:</strong> Part of the LLVM project, Clang is another popular compiler known for its fast compilation speed and excellent diagnostics.</li><li><strong>Microsoft Visual C++ Compiler:</strong> Included with Visual Studio, this compiler is optimized for Windows development and provides good integration with the Visual Studio IDE.</li></ul><p><strong>Setting Up Your Environment:</strong></p><ol><li><strong>Choose an IDE:</strong> Select an IDE that suits your preferences and needs. Download and install the chosen IDE on your system.</li><li><strong>Install a Compiler:</strong> Depending on your IDE, you may need to install a compiler separately. Some IDEs come with a bundled compiler, while others may require you to configure an external compiler.</li><li><strong>Configure the IDE:</strong> After installation, configure your IDE to work with the chosen compiler. Specify the compiler’s location and other settings.</li><li><strong>Create a Project:</strong> Create a new C++ project in your IDE. This helps organize your code, manage dependencies, and streamline the development process.</li><li><strong>Write and Run Code:</strong> Start writing your C++ code in the IDE’s code editor. Use the IDE’s features for code completion, syntax highlighting, and debugging. Compile and run your code from within the IDE.</li></ol><h3>Writing and running a simple “Hello World” program in C++</h3><p>The “Hello World” program is a traditional starting point when learning a new programming language. It’s a simple program that displays the text “Hello, World!” on the screen. Let’s walk through the steps of writing and running a “Hello World” program in C++.</p><p><strong>Step 1: Setting Up the Development Environment:</strong> Before you begin, ensure that you have a C++ development environment set up. This includes an Integrated Development Environment (IDE) and a compiler. Follow the instructions provided in your chosen IDE to create a new C++ project.</p><p><strong>Step 2: Writing the Code:</strong></p><ol><li>Open your IDE and create a new C++ source file within your project.</li><li>In the source file, type the following code:</li></ol><pre>#include &lt;iostream&gt;<br>int main() {<br>    std::cout &lt;&lt; &quot;Hello, World!&quot; &lt;&lt; std::endl;<br>    return 0;<br>}</pre><p><strong>Step 3: Understanding the Code:</strong></p><ul><li><strong>#include &lt;iostream&gt;</strong>: This line includes the <strong>&lt;iostream&gt;</strong> header, which provides input and output stream functionality.</li><li><strong>int main()</strong>: This is the main function, the entry point for your program.</li><li><strong>std::cout &lt;&lt; &quot;Hello, World!&quot; &lt;&lt; std::endl;</strong>: This line uses the <strong>std::cout</strong> stream (standard output) to print &quot;Hello, World!&quot; to the console. The <strong>&lt;&lt;</strong> operator is used for output.</li><li><strong>return 0;</strong>: This line indicates that the program has completed successfully and returns an exit status of 0 to the operating system.</li></ul><p><strong>Step 4: Compiling and Running the Program:</strong></p><ol><li>Save the source file.</li><li>Use your IDE’s build or compile command to compile the program. The IDE will invoke the compiler and generate an executable file.</li><li>Once the compilation is successful, you’ll find an executable file (usually with the same name as your project) in the project’s output or bin directory.</li><li>Run the executable by either double-clicking it or using the command line.</li></ol><p><strong>Step 5: Viewing the Output:</strong></p><p>After running the executable, you’ll see the output:</p><pre>Hello, World!</pre><p>Congratulations! You’ve successfully written and executed your first C++ program. This simple example demonstrates the basic structure of a C++ program, including including headers, defining functions, and using standard I/O.</p><h3>Basic syntax: variables, data types, input/output</h3><p>Understanding the fundamental building blocks of C++ programming is essential for creating functional and meaningful applications. This section covers variables, data types, and basic input/output operations in C++.</p><p><strong>1. Variables and Data Types:</strong></p><p><strong>Variables:</strong> A variable is a named memory location used to store data. You can think of it as a container for holding values. Before using a variable, you need to declare its type and give it a name.</p><p><strong>Data Types:</strong> Data types define the kind of data a variable can hold. C++ has several built-in data types:</p><ul><li><strong>int:</strong> Represents integer values, e.g., <strong>int age = 25;</strong></li><li><strong>float:</strong> Represents floating-point numbers with decimal places, e.g., <strong>float pi = 3.14;</strong></li><li><strong>double:</strong> Similar to <strong>float</strong> but with higher precision, e.g., <strong>double distance = 123.456;</strong></li><li><strong>char:</strong> Represents a single character, e.g., <strong>char grade = &#39;A&#39;;</strong></li><li><strong>bool:</strong> Represents Boolean values (<strong>true</strong> or <strong>false</strong>), e.g., <strong>bool isStudent = true;</strong></li></ul><p><strong>2. Input and Output (I/O):</strong></p><p>C++ provides the <strong>iostream</strong> library for input and output operations. The main components are <strong>cin</strong> for input and <strong>cout</strong> for output.</p><p><strong>Input (cin):</strong> Use <strong>cin</strong> to receive input from the user. It waits for the user to enter data and press Enter.</p><pre>#include &lt;iostream&gt;<br>int main() {<br>    int age;<br>    std::cout &lt;&lt; &quot;Enter your age: &quot;;<br>    std::cin &gt;&gt; age;<br>    std::cout &lt;&lt; &quot;You are &quot; &lt;&lt; age &lt;&lt; &quot; years old.&quot; &lt;&lt; std::endl;<br>    return 0;<br>}</pre><p><strong>Output (cout):</strong> Use <strong>cout</strong> to display output on the screen. The <strong>&lt;&lt;</strong> operator is used to insert data into the output stream.</p><pre>#include &lt;iostream&gt;<br>int main() {<br>    std::cout &lt;&lt; &quot;Hello, World!&quot; &lt;&lt; std::endl;<br>    return 0;<br>}</pre><p><strong>3. Comments:</strong></p><p>Comments are not executed by the compiler but provide explanations in your code for yourself and others.</p><pre>// This is a single-line comment</pre><pre>/*<br>    This is a multi-line comment.<br>    It can span multiple lines.<br>*/</pre><pre>int main() {<br>    // Code here<br>    return 0;<br>}</pre><h3>Functions and control structures (if-else, loops)</h3><p>In C++, functions are blocks of code that perform specific tasks. Control structures, such as if-else statements and loops, allow you to control the flow of your program based on conditions and repeat tasks multiple times. Let’s explore these concepts in detail.</p><p><strong>1. Functions:</strong></p><p>A function is a self-contained block of code that performs a specific task. It helps modularize code and make it more organized and readable. Functions can take parameters as input and return values as output.</p><pre>#include &lt;iostream&gt;// Function declaration<br>int add(int a, int b) {<br>    return a + b;<br>}</pre><pre>int main() {<br>    int result = add(5, 7);  // Calling the function<br>    std::cout &lt;&lt; &quot;Sum: &quot; &lt;&lt; result &lt;&lt; std::endl;<br>    return 0;<br>}</pre><p><strong>2. Control Structures:</strong></p><p><strong>if-else Statements:</strong> if-else statements allow you to execute different code blocks based on conditions.</p><pre>#include &lt;iostream&gt;<br>int main() {<br>    int age;<br>    std::cout &lt;&lt; &quot;Enter your age: &quot;;<br>    std::cin &gt;&gt; age;</pre><pre>    if (age &gt;= 18) {<br>        std::cout &lt;&lt; &quot;You are an adult.&quot; &lt;&lt; std::endl;<br>    } else {<br>        std::cout &lt;&lt; &quot;You are a minor.&quot; &lt;&lt; std::endl;<br>    }</pre><pre>    return 0;<br>}</pre><p><strong>Loops:</strong></p><p><strong>a. while Loop:</strong> A <strong>while</strong> loop repeatedly executes a block of code as long as a condition is true.</p><pre>#include &lt;iostream&gt;<br>int main() {<br>    int count = 1;<br>    while (count &lt;= 5) {<br>        std::cout &lt;&lt; &quot;Count: &quot; &lt;&lt; count &lt;&lt; std::endl;<br>        count++;<br>    }<br>    return 0;<br>}</pre><p><strong>b. for Loop:</strong> A <strong>for</strong> loop is often used to iterate a specific number of times.</p><pre>#include &lt;iostream&gt;<br>int main() {<br>    for (int i = 1; i &lt;= 5; i++) {<br>        std::cout &lt;&lt; &quot;Iteration: &quot; &lt;&lt; i &lt;&lt; std::endl;<br>    }<br>    return 0;<br>}</pre><p><strong>c. do-while Loop:</strong> A <strong>do-while</strong> loop ensures that the code block is executed at least once, even if the condition is initially false.</p><pre>#include &lt;iostream&gt;<br>int main() {<br>    int choice;<br>    do {<br>        std::cout &lt;&lt; &quot;Menu: &quot; &lt;&lt; std::endl;<br>        std::cout &lt;&lt; &quot;1. Print&quot; &lt;&lt; std::endl;<br>        std::cout &lt;&lt; &quot;2. Exit&quot; &lt;&lt; std::endl;<br>        std::cout &lt;&lt; &quot;Enter your choice: &quot;;<br>        std::cin &gt;&gt; choice;<br>    } while (choice != 2);<br>    return 0;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b6ed5c0f9c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用 Kodi 打造家庭娛樂中心]]></title>
            <link>https://medium.com/@cashbooktw/%E4%BD%BF%E7%94%A8-kodi-%E6%89%93%E9%80%A0%E5%AE%B6%E5%BA%AD%E5%A8%9B%E6%A8%82%E4%B8%AD%E5%BF%83-e35e4d02c202?source=rss-18d2a0191e28------2</link>
            <guid isPermaLink="false">https://medium.com/p/e35e4d02c202</guid>
            <category><![CDATA[kodi]]></category>
            <dc:creator><![CDATA[Gary Yeh]]></dc:creator>
            <pubDate>Mon, 09 Mar 2020 13:21:50 GMT</pubDate>
            <atom:updated>2020-03-09T14:39:48.854Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ld0tPnrE58hrgk_4ir-NcA.jpeg" /><figcaption>source: Kodi</figcaption></figure><p><strong>Kodi</strong>，一個強大的媒體播放器，不僅支援各種平台，也可以連接網路上的資料庫，足夠的資訊讓本地端的媒體有更好的管理。各式各樣的 Addons 讓 Kodi 的功能更加豐富，還可以透過安裝類似 Exodus Redux 之類的 Addons 觀看網路串流影片。</p><p>這邊我希望可以做出一個類似 NAS 兼 媒體播放器(使用 Kodi)的平台，影片從 PC 複製到平台上後，可以直接在平台上透過 HDMI 輸出影像到電視上。這邊簡單介紹一下我在各個平台安裝的經驗。<br><strong>Raspberry Pi 4 (Raspbian, LibreELEC)<br>筆電 (Ubuntu)<br>OTT Box (Android)</strong></p><h3>Raspberry Pi 4 (Raspbian, LibreELEC)</h3><p>作業系統是 <a href="https://www.raspberrypi.org/downloads/raspbian/">Raspbian</a>。透過 USB 3.0外接硬碟當主要媒體儲存空間，用 CIFS 掛載 PC 上的資料夾，再用手動或排程的方式把 PC 上的資料複製到硬碟上。另外安裝 Kodi 拿來當 Media player。</p><p>失敗。</p><p>主要原因是因為在播放影片時，不管是用 Kodi 或是 VLC，都會掉 frame，甚至會有 coredump 出現，有可能是因為硬體效能不夠好，但 Raspberry Pi 宣稱能播 4K video，硬體規格也比家中的數位機上盒好，應該不是因為這個原因。比較有可能是因為作業系統或是應用程式支援不足導致的(沒有啟用硬體解碼加速)。</p><p>雖然使用 Raspbian 失敗，不過還是紀錄一下安裝過程。</p><ol><li>在 PC 上用 <a href="https://www.sdcard.org/downloads/formatter/">SD Card Formatter</a> 把 micro SD 卡格式化</li><li>下載 <a href="https://www.raspberrypi.org/downloads/raspbian/">Raspbain</a> 作業系統。</li><li>用 <a href="https://www.balena.io/etcher/">balenaEtcher</a> 把 image 寫到 micro SD 卡。</li><li>先在 PC 上面開資料夾的分享。到控制台-&gt;網路和共用中心-&gt;變更進階共用設定，將來賓或公用的網路探索，與檔案及印表機共用開啟。然後在要分享的資料夾按右鍵 -&gt; 內容 -&gt; 共用 -&gt; 共用。</li><li>樹莓派裝上 micro SD 卡後開機，調整一些基本設定。</li><li>安裝 Kodi，開 terminal 鍵入<br>sudo apt-get update<br>sudo apt-get install kodi</li><li>再來掛載 PC 上的資料夾，建立本地的資料夾後，將 PC 的資料夾掛載進來。<br>mkdir windows_shared<br>sudo mount -t cifs -o username=”[username]”,password=”[password]” <a href="https://192.168.1.100/Media">//</a>[PC 的 IP]/[/[PC分享資料夾的名稱]/home/cashbook/windows_shared<br>[ ]內要填入自己的設定。</li><li>開啟 Kodi，載入媒體後就可以播放了。</li></ol><p>既然懷疑是作業系統的問題，那就換一個吧。改用 <a href="https://libreelec.tv/">LibreELEC</a>，一個專為 Kodi 打造的作業系統。安裝相當簡單，直接下載執行檔就可以直接把 image image 寫進 micro SD 卡了。開機後，哇！好順暢，之前遇到的問題都不見了呢。如果想看 Netflix 或是 Youtube，也可以安裝相關的Addons。</p><h3>筆電 (Ubuntu 18.04)</h3><p>接下來拿筆電來試試看。<br>CPU: Intel Core i7–4712MQ<br>顯卡: NVIDIA GeForce 840M</p><p>因為跟 Raspbain 都是 Linux base 的作業系統，安裝上也差不多，但如果直接安裝，Kodi 的版本會是17而不是最新的18。因此command要改成如下：<br>sudo apt-get install software-properties-common<br>sudo add-apt-repository ppa:team-xbmc/ppa<br>sudo apt-get update<br>sudo apt-get install kodi<br>版本17到18的差異很大，建議還是用最新的版本。其實 Kodi 本身就具有掛載並播放遠端伺服器的檔案的功能，不一定要用剛才提到的 CIFS 的方式，但剛才提到的其中一個版本功能差異，就是使用的SMB版本不同。Kodi 版本17以前用的是 SMBv1，而版本18之後用的是SMBv2，而 Windows 預設是不採用 SMBv1 的，如果一定要用版本17，Windows 要先做設定：控制台 -&gt; 程式和功能 -&gt; 開啟或關閉 Windows 功能，將 SMB1.0打開。但是由於<a href="https://zh.wikipedia.org/wiki/WannaCry">安全性的問題</a>，還是不建議使用 SMBv1。</p><p>除了直接用檔案分享，另外一個方式就是可以架設 Media server，這可以透過 <a href="https://emby.media/download.html">Emby</a> 來實現。Emby 是 server-client 的架構，需要有一台不關機的平台安裝 Server，Client 端則是安裝 Kodi 後再加入 <a href="https://github.com/MediaBrowser/plugin.video.emby/wiki">Emby addons</a>。好處是不限於區域網路內，在外也可以連線播放。</p><p>測試的結果是，在筆電上播放沒有問題，但透過 HDMI 輸出到電視畫面就會掉 frame，我想大概是頻寬不夠吧。</p><h3>OTT Box (Android 7)</h3><p>最後是採用的 BANDOTT，鴻海的智慧電視盒。<br>CPU: Cortex-A53 四核 64-bit １.5GHz<br>GPU：Penta-cores Mali-450 up to 750MHz</p><p>安裝的方式就直接到 Play商店下載 Kodi。原本用 X-plore 這個 APP 來掛載 PC 的資料夾，但是 Kodi 抓不到位置，後來就改成直接用 Kodi 內部掛載檔案的方式。</p><p>這邊介紹怎麼設定 Kodi：</p><p>首先到 Settings -&gt; Interface -&gt; Skin -&gt; Fonts 選擇 Arial based</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXGLi_Fhl0Sq75qlPtwFUw.png" /><figcaption>Fonts</figcaption></figure><p>一樣在 Interface -&gt; Regional 選擇 Chinese Traditional</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CrXndA1qw1JnKHUZHSV4Kw.png" /><figcaption>Languages</figcaption></figure><p>如果不先改字型再改語言會有亂碼出現，介面就看不懂囉。</p><p>接著到最外層的介面，選擇類別，例如電影，然後選擇進入檔案區。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nMeTEH8nOTfg_NivFHIjRA.png" /><figcaption>進入檔案區</figcaption></figure><p>新增 -&gt; 瀏覽 -&gt; 新增網路位置</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*exn5uxF0BgqMPTvoRXs9mQ.png" /><figcaption>新增網路位置</figcaption></figure><p>填上個人的設定。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BX1WHUmJ_f6z9s-i9evRqw.png" /><figcaption>設定網路位置</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*_DhUeQpvS0e_CtIt-QcOLw.png" /><figcaption>增加影片來源</figcaption></figure><p>設定完之後，就可以選取剛才設定的這個網路位置當成影片來源。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dhyQAj0b5ay22_hs7ASqYw.png" /><figcaption>設定內容</figcaption></figure><p>如果是電影，就選擇資訊提供者 The Movie DB；如果是電視劇，就選擇 TVDB。雖然 The Movie DB 裡面也有電視劇的資訊，但有些是錯誤的。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-n10yhbq16XUaSwHD8DFNQ.png" /><figcaption>系統設定</figcaption></figure><p>設定完之後就會開始更新資料庫，就可以看到媒體資訊了，大概像這樣子：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QVE0dCNKrcP5knr5BclTQA.png" /><figcaption>Kodi Movies</figcaption></figure><p>因為有一些繁中的 metadata 如果沒抓到，就會使用簡中，不喜歡的人可以把語言設定成英文就可以了。甚至如果有些資訊錯誤的話，也可以直接在這些開放的 Database網站註冊會員，直接到源頭去修改。</p><p>至於 Media server 要架設在哪邊，如果你的 PC 都不重開機，可以選擇在 PC 上，或是把樹莓派+外接硬碟當成是 NAS。我的選擇是，把外接硬碟接在家用路由器上，直接使用路由器提供的 File Server 功能。近幾年比較新的家用路由器已經有提供外接 USB 硬碟，可以提供 UPNP、SAMBA、FTP等等的服務了，相當方便。我用的是 ASUS 的 RT-AC66U+路由器，老實說功能並不理想，因為 SAMBA 只支援 SMBv1，FTP 也不支援 TLS，安全性堪憂啊。</p><p>所以最後的架構變成：<br><strong>路由器</strong> USB3.0 <strong>外接硬碟</strong>，架起 SAMBA Server 與 FTP Server。<br><strong>PC</strong> 經由 FTP client 把檔案傳輸到外接硬碟上。<br><strong>OTT Box</strong> 執行 Kodi，SAMBA client 取得檔案後播放。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e35e4d02c202" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[為什麼要用 Notion.so 這個筆記軟體？]]></title>
            <link>https://medium.com/@cashbooktw/%E7%82%BA%E4%BB%80%E9%BA%BC%E8%A6%81%E7%94%A8-notion-so-%E9%80%99%E5%80%8B%E7%AD%86%E8%A8%98%E8%BB%9F%E9%AB%94-624c023cb5a4?source=rss-18d2a0191e28------2</link>
            <guid isPermaLink="false">https://medium.com/p/624c023cb5a4</guid>
            <category><![CDATA[notion]]></category>
            <category><![CDATA[notes]]></category>
            <dc:creator><![CDATA[Gary Yeh]]></dc:creator>
            <pubDate>Wed, 01 Jan 2020 13:13:08 GMT</pubDate>
            <atom:updated>2020-01-01T13:43:22.588Z</atom:updated>
            <content:encoded><![CDATA[<h4>免費的無限雲端儲存空間使用一年，好 Notion，不用嗎？</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XnW7HeXGa0Yzki9Drr4JWA.png" /><figcaption>Source: Notion.so</figcaption></figure><p>市面上的筆記軟體有很多，從前面那張圖就可以看到目前熱門的筆記軟體有哪些，我自己用過的有 Google Docs、Quip、Evernote、Trello、Dropbox Paper。Google Docs 基本上只要你有使用 Google 的服務，大概是離不開的，跨平台編輯，分享快速，除了空間限制之外沒有什麼太大的缺點；Evernote 以前試用時對介面沒有愛，便沒有繼續用；Quip 之前在籌辦婚禮的時候用過，完整的線上編輯文件功能，介面像是在使用原生的檔案系統，但是 unlimited space 需要月費10鎂，太貴放棄；Dropbox 則是在規劃居家空間的時候使用，結合 Dropbox 雲端空間好用；Trello 則是我原先使用 GTD 時間管理術時在用，免費的方案只有一個 power-up，進階版也是一樣要月費10鎂。後來看到這篇：<a href="https://medium.com/as-a-product-designer/%E7%9F%BD%E8%B0%B7%E5%A4%A7%E5%8F%97%E6%AD%A1%E8%BF%8E%E7%9A%84%E7%AD%86%E8%A8%98%E8%BB%9F%E9%AB%94-notion-so-718194b44f6c?">矽谷大受歡迎的筆記軟體：Notion.so</a>，轉為 Notion.so 的使用者，到現在已經有半年了。這邊以我使用的角度來介紹這個軟體：<br>1. <a href="#a300">什麼樣的人需要使用 Notion？</a><br>2. <a href="#5cf1">Notion 的優缺點。</a><br>3. <a href="#81db">使用 Notion 的一些小訣竅。</a></p><h3>什麼樣的人需要使用 Notion？</h3><h4>1. 你是學生或是教師</h4><p>Notion 在今年推出了教育方案，只要使用教育信箱認證後，便可以免費升級，內容跟付費的個人方案差不多，有著無限的使用空間與30天的歷史紀錄復原。也就是說你只要開始使用 Notion，每個月現賺4鎂呀！即便是沒有使用筆記軟體的習慣，把 Notion 當成一個跨平台的記事本或是雲端備份空間也是很好用的，免費的就是讚。</p><h4>2. 你最近有共同編輯文件的需求</h4><p>這邊考慮一個情境：你臨時有專案的需求(例如規劃婚禮跟蜜月)，需要多人協作，又希望能有大量的雲端儲存空間，但是專案差不多持續半年，你不想花太多錢在上面，該怎麼辦呢？考慮到幾個知名的服務：</p><blockquote>Google One: 2TB，月繳 330 NTD<br>OneDrive + Office365: 1TB，月繳 219 NTD<br>Dropbox: 2TB，月繳 10 USD<br>Notion.so: 無限儲存空間，月繳 5 USD</blockquote><p>比較起來發現，Notion 根本大勝。而且 Notion 內建 Earn Credit 的任務，完成後至少可以讓你免費用升級半年！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*f30R4OVlQvOr9FgEI41xqQ.png" /></figure><p>這些任務有：</p><ul><li>在瀏覽器上登入</li><li>在桌面應用程式上登入</li><li>在行動裝置的 APP 上登入</li><li>從 Evernote 上 import 資料進來</li><li>使用 Chrome 的 <a href="https://chrome.google.com/webstore/detail/notion-web-clipper/knheggckgoiihginacbkhaalnibhilkk">Notion Web Clipper</a> 這個 Extension</li><li>使用行動裝置上的 APP 裡面的分享功能</li></ul><p>你會發現這些任務相當簡單，一下子就能完成，便可以拿到26鎂的credit。若一開始使用別人給的推薦連結註冊，還能拿到10鎂的credit，總共36鎂，可以讓你免費使用升級7個月！如果你也推薦別人，而對方也註冊成功的話，你可以拿到5鎂的credit。Notion 的年費特價48鎂，也就是如果成功推薦3個人，你等於可以免費使用升級整整1年！有興趣的話可以透過<a href="https://www.notion.so/?r=9738772f52554aab971513d5fc430ebd">我的推薦連結</a>去註冊。</p><h4>3. 你想要很潮的筆記軟體</h4><p>就是 Notion ，而不是那些大廠的筆記軟體，獨樹一格，使用者穩定成長中。今年七月獲得天使輪融資1000萬鎂，九月宣布教育方案，軟體功能越來越完整。介面是當下最流行的扁平化設計，行動裝置的 RWD 體驗良好，想要 Dark mode 嗎？沒問題，Settings &amp; Members 裡面有選項可以調，潮。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*AXuT4wprQJ4QusntEkw2Gg.gif" /><figcaption>Source: Notion</figcaption></figure><h3>Notion 的優缺點</h3><h4>優點</h4><ul><li>跨平台。由於是以 Web App下去開發，各個平台的使用介面差不多。</li><li>介面整潔好看，使用上滿直覺的，可以用拖拉的方式調整順序。</li><li>多樣且實用的功能。可以創建多個 Pages 跟 Sub-pages 達到階層的功能，創造出文件樹；可以利用 Link to Page 建立跳轉的捷徑；可以使用 Reminder 設置時間提醒，取代使用 Google calendar；還有強大的資料庫，善用 Table、Board、Gallery 以及 Sort 跟 Filter 的功能，讓你整理資料有條理又省力；另外還可以在文件中嵌入各種媒體，例如 PDF、YouTube、Spotify，在同一頁就可以直接寫筆記。(別忘了這是筆記軟體呀！)</li><li>有很多基本的 Templates 可以使用。還在那邊苦惱怎麼排版嗎？從官方提供的 Templates 庫裡面就有相當多的應用情境，網路上也可以找到別人自己做的 Templates，你也可以分享給別人喔！</li><li>無痛從 Evernote 轉移。這個看網路上別人說的啦，我自己是沒有驗證過。</li><li>免費用升級至少半年，這個就是前面提到的。即使不完成任務，想要試用也是可以的，只是限制最多創造1000個 blocks，檔案上限 5MB，我自己用不到一個月就已經達上限了。</li><li>無限的儲存空間。每月4鎂就有無限的雲端儲存空間，我還不存爆。自身測試單一檔案上限是5GB，超過就會傳失敗，網路上也有人反應這個情況，但官方說法是沒有限制，都是 they 的問題。</li><li>協作權限設定完整。可以選擇不同的頁面，給予不同人權限，包含 Read、Comment、Edit、Share等，相當的彈性。</li></ul><h4>缺點</h4><ul><li>開啟速度慢。由於不是 Native App，開啟 APP 需要一點 Loading 時間，但也不會太誇張啦。</li><li>英文介面。這對一些人，例如我來說不算是缺點，而且常用的選項就那些，花些時間便可以上手(以前日文版的神奇寶貝還不是照玩XD)。</li><li>還沒有 API ，聽說是 coming sooooon。有了 API 可以應用的範圍一定會更廣，看看 Trello 那些強大的 power-ups。</li><li>新創公司，很怕他倒掉XD。希望他能做起來，不然被大型科技公司收購也可以。</li><li>單一檔案最大限制5GB，雖然官方表示沒有這個限制，但滿多人反應這個問題的。</li></ul><h3>使用 Notion 的一些小訣竅</h3><h4>1. 使用 Filter 功能代替封存(Archived)</h4><p>前面有提到，原本是用 Trello 來使用 GTD 時間管理術，而 Trello 有封存卡片的功能，並不是將卡片刪除，而是隱藏起來，實際上還存在 Board 裡面。而 Notion 並沒有這個功能，取而代之的是可以用 Filter 的功能，將你的 Table 做整理。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66oXfZnVXq0w3l4cC6rdzw.png" /></figure><p>這邊我把任務加上 Status 的屬性，Status 的值可以是無(未分派任務)、In Progress(進行中)、Completed(已完成)、Archived(已封存)。在整理看板時，便可以將 Completed 裡面的任務移至 Archived，並且使用 Filter 隱藏起來。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*8XA9HdKI8Td7pVYPURscrQ.png" /></figure><p>這邊就是 Notion 資料庫的強大之處了，利用基本的邏輯指令可以快速整理並建構出你想要的資料格式。上圖的 Status Is Not Archived 的 Filter 功能，就是把除了 Archived 這個屬性的所有任務列出來，那麼屬於 Archived 的任務自然就被隱藏起來囉。</p><h4>2. 在行動裝置上利用分享的功能儲存文章</h4><p>我們已經知道在 Chrome 上可以使用 Notion Web Clipper 來把網路文章存進 Notion 裡，那麼行動裝置呢？其實相當簡單，按下手機瀏覽器右上角的 Kebab Menu 後，再按下分享，選擇 Notion，就可以將文章內容存到你指定的 Notion 頁面了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*z-jQVbpbUIIi4mHxIBuMnw.jpeg" /></figure><h4>3. 建立 Toggle List 加速頁面載入速度</h4><p>有時候我們建立的頁面內容很多，導致在開啟時會需要一點 loading 時間。這時可以善用 Toggle list，將內容放在裡面。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*G5RQYGHOCJOgNfh6B389AQ.png" /></figure><p>圖中的三角形符號就是 Toggle list，在這一頁開啟時只會載入最上層的標題，想要看更多資訊就點一下三角形符號，將 Toggle list 展開。這麼做能加速頁面開啟的原因是因為，在這個頁面載入時並不會載入 Toggle list 裡面的內容，而是當你將 Toggle list 展開時，才會去要資料，如此一來，你只要載入你想看的資料內容就好，而不需要把全部的內容一併載入。</p><h4>4. 使用 icon 與 cover image</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZFCorjToiMR06EXBHe080g.png" /></figure><p>你可以為你的頁面加上 icon 與 cover image，雖然說只使用簡單的標題也行，但是由於比起文字，人對於圖像的辨識是更加敏感的。用久了之後，一看到這個 icon 馬上就知道這頁是什麼，而且這也有助於情感連結，讓你更有動力完成任務。Cover image 除了可以自己上傳，也支援直接從 Unsplash 搜尋，相當方便。</p><h4>5. 用自己上傳的 icon</h4><p>Notion 內建的 emoji 並不多，使用者可以自行上傳 icon。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*QOYRptF_z-zWadtQM3SGUw.png" /></figure><p>這邊有我之前看到的生產力 <a href="https://www.notion.so/Notion-Icon-set-production-8f7267b2709b405a904608b51c400e55">icon set</a>，還不錯。</p><h4>6. 套用不同字型在單頁上</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*tGZ55RP-QO6ad5NN2vloug.png" /></figure><p>在右上的 Meatballs menu，可以改變單頁的字型。預設無襯線的字型適合用在標題上；Serif 適合用在閱讀文章，或是比較正式的發佈版本上；Mono 適合自己編輯文章或是看程式碼。這邊還可以調整字體大小與文章的版面寬度。</p><h4>7. 將 Board 的 Table view 轉換成 Date view</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*uUfh3YrtZ8-DNmiR85DN6g.png" /></figure><p>每一個任務都可以加上 Due date，Table view 就可以轉成 Date view， 讓你的清楚知道待辦清單的先後順序。這邊有個小缺點是，只能照著 Due dates 排列而不能照著 End dates 排，解決辦法是，要新增另外一個 Deadline dates 的屬性，再選擇用這個屬性列出 Calendar。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n12JH5vUUy6QZDrGodehLw.png" /><figcaption>Source: Notion</figcaption></figure><h3>總結</h3><p>Notion 是一套主打作筆記、文件、任務、專案與資料庫的軟體，並不是說使用了這個軟體，事情就馬上變得井然有序。工具的功能再怎麼完備，還是要看使用者怎麼去操作，關於筆記方法、專案管理與時間管理，網路上很多人分享，這邊就不多撰述。這邊提供幾個可以深入研究 Notion 使用方法的網頁：<br><a href="https://www.notion.so/Help-Support-e040febf70a94950b8620e6f00005004">Notion Help &amp; Support</a><br><a href="https://twitter.com/notionhq">Notion Twitter</a><br><a href="https://www.reddit.com/r/NotionSo/">Notion Reddit</a></p><p>最後再放一下<a href="https://www.notion.so/?r=9738772f52554aab971513d5fc430ebd">我的推薦連結</a>，利益揭露，透過我的連結註冊，我大概可以多用免費升級1個月，註冊者則可以免費使用升級2個月。祝大家實現新年新希望啦！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=624c023cb5a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[大阪難波站前日和飯店(HIYORI HOTEL OSAKA NAMBA )住宿心得]]></title>
            <link>https://medium.com/@cashbooktw/%E5%A4%A7%E9%98%AA%E9%9B%A3%E6%B3%A2%E7%AB%99%E5%89%8D%E6%97%A5%E5%92%8C%E9%A3%AF%E5%BA%97-hiyori-hotel-osaka-namba-%E4%BD%8F%E5%AE%BF%E5%BF%83%E5%BE%97-251275a3f552?source=rss-18d2a0191e28------2</link>
            <guid isPermaLink="false">https://medium.com/p/251275a3f552</guid>
            <category><![CDATA[osaka]]></category>
            <category><![CDATA[japan]]></category>
            <category><![CDATA[hotel]]></category>
            <category><![CDATA[travel]]></category>
            <dc:creator><![CDATA[Gary Yeh]]></dc:creator>
            <pubDate>Tue, 24 Dec 2019 14:15:10 GMT</pubDate>
            <atom:updated>2019-12-24T14:15:10.446Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8a4Oy3IUQuvoppxvB4d46w.jpeg" /><figcaption>HIYORI HOTEL</figcaption></figure><p>這次到大阪旅遊選擇了這間大阪難波站前日和飯店，抵達關西機場後，出關到2樓南海電鐵購票，搭空港急行約45分鐘，票價是920元，抵達難波站後，步行約3分鐘即可抵達飯店。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vb50whyL-7PyGBFJX1e7EQ.jpeg" /></figure><p>從南海電鐵難波站出來往西走，左邊是難波Parks，右邊是難波SkyO，利用移動的空閒時間可以逛逛。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ZW5BYCiFAfAjf1LzfBWWg.jpeg" /></figure><p>從複合商場出來走下電扶梯，馬路對面就是信長書局(嘿嘿)跟全家便利商店，要回飯店時買宵夜很方便。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HE_Au_UxOhlpwB9DRCAGsQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qNOJjgHHh561gymxctfdng.jpeg" /></figure><p>走過一個大路口，要過兩次馬路，就可以抵達飯店。飯店的對面是麥當勞，不知道早餐吃什麼可以來買。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w_06P3c7fsRi32H5g8_a6w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e8mRCnT_za6zKG9DJ6iteA.jpeg" /></figure><p>Check in的櫃台。這邊的櫃台服務人員是日文流利的外國人，用英文溝通完全沒有問題。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4x_yrF_TxouOpv6gQjE4TQ.jpeg" /></figure><p>由於我們旅遊日期是十月底，飯店內充滿著萬聖節的氣息，有背板跟小道具可以拍照。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z6wDOcB2og2kEwa1EICIIA.jpeg" /></figure><p>自助 Check in 服務。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YEg6up7PXw9GFwbCiPUIOA.jpeg" /></figure><p>入住囉，房間位於8樓。個人覺得處在鬧區的飯店，這樣的走廊算滿寬的。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TnWsckzNckrerjGFPZE_ew.jpeg" /></figure><p>進門的樣子，左手邊是廁所，右手邊是洗手台。地板是塌塌米地貼。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KLnTq4ublpxjdOR8La__cA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Lgu17R17UFX8QcuypIDnQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c6Qd15BjmxItRGDf1MLAWg.jpeg" /></figure><p>洗手台備有各式各樣的消耗品、洗手乳、擦手巾、小垃圾桶。可以看到檯面非常乾淨。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0jnYHRsVoz2801xRnN6gKA.jpeg" /></figure><p>浴室的浴缸相當大而且乾淨，跟淋浴區大概是1比1，我每天都丟泡澡錠進去泡澡。這邊附有一個小椅子跟水勺。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tz4F9CTFZ5scqwN--Hdxsw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eEVyYCmi176ECWX5CtdZgQ.jpeg" /></figure><p>一張椅子跟小桌子，吃宵夜可用。把桌子移走的話，地上勉強可以攤開兩個行李箱。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7XxuCfKSGtRtCFveYuf-uQ.jpeg" /></figure><p>窗外便是大馬路。原本以為住離地鐵站近，會不會受到地鐵站的噪音影響，但其實不會，反而是深夜會聽到呼嘯而過的車聲。我自己覺得室內外隔音還可以，至少晚上都睡的不錯(也可能是走太累)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q83cW5MEQOPTvxOdcykS2w.jpeg" /></figure><p>室內電器附有加濕空氣清淨機與腳底按摩器，這台每天晚上回來都用，腳實在太痠了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Fa0tXGJDon47QEAzbixMw.jpeg" /></figure><p>吹風機與電棒燙。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CLvwUmUi6_RG4WsPTBapCg.jpeg" /></figure><p>鞋刷與襪子烘乾器。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9-azvIz9Ls-wPhiU4_HzGg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RPVdmlF1aDlQPfG-XS7bcA.jpeg" /></figure><p>電視地上波大概10台，由於關東大雨成災，那幾天電視都是關東淹水的報導。水每天會補到兩瓶，底下有冰箱、電熱水瓶跟茶具，晚上可以吃泡麵當宵夜。桌上的平板是拿來選擇一些客房服務用的，我研究了一下發現內部作業系統的介面是簡體中文的，大概是跟中國廠商買的吧。總之因為平板有 camera，我都用紙把 camera 蓋起來。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8dXxz6t3JP0kA-eFatnCmg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9CEC54vseJYYNeN5qbWSfw.jpeg" /></figure><p>直接支援兩孔充電與 USB 充電。另外書桌上也有充電孔，還附有手機充電孔轉接器。</p><p>介紹完房間，接著來看飯店其他設施。5樓有吸菸室，6樓有販賣機、製冰機與微波爐，7樓有自助洗衣機。沒有什麼時間，所以沒去拍照。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qjcgczKXwD5Ngz6ys790QQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aXIsTufa5WRt4s6wRBi4dQ.jpeg" /></figure><p>早餐我們當初買的價格是1人1500日圓，日和飯店兩棟都有用餐的地方，可以選一邊去吃。個人覺得早餐品項不多且有點貴，但還算好吃，可以體驗看看。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MQdmkq7vStiEWeIbmFj89A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZDysrEeW0bcxtUWyGBnAQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVIkIZrofNJVPtFI9uPiPw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G1pKxb2BYaQkM9Aw9bzi-w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*deqXekVn6VsnN5LAUjB12A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dv22P4j13LVaJCFRkaygFA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ux5PFDrTpnPZ4Lk4Zk53-A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tX3UtDz4eIqwLqTJwwbylA.jpeg" /></figure><p>早上出門時，大廳有免費咖啡。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FLK5CkB_yOzWJE7D-v4zdg.jpeg" /></figure><p>晚上回來時有免費冰淇淋，要注意時間是8點到9點供應而已(其實不太好吃)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*c5Y_O28FkbtMpPwA9T35kQ.png" /></figure><p>從地圖上可以看到往南可到通天閣、阿倍野；往北可到心齋橋、梅田；往東北有天守閣；往西南可抵達關西機場。附近還有一個難波八坂神社可以看看。如果只在大阪內逛的話，住在難波是一個很好的選擇。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xaPpY5gQIJnxcIB0Ubfj8A.jpeg" /></figure><p>在網路上看到有對於飯店打掃人員的抱怨，這邊提一下我的經驗。我們早上出門時都會把東西全部收到行李箱跟袋子裡，並集中放在一起，以方便打掃人員清潔。有一天我的手機充電線忘記收，插在床頭的插座上，晚上回來發現被掃到地板上。另外我出國時為了減輕行李重量，會在國外買內褲，原本的破舊內褲就丟掉。這次大阪旅遊也是一樣裝在袋子內丟到垃圾桶。但打掃人員大概認為這是我的個人物品，又從垃圾桶內撿回來放在旁邊XD，丟了第二次才成功丟棄。其他就沒有遇到什麼問題，我覺得打掃乾淨，東西沒有失竊我就謝天謝地了。</p><p>這次的住宿體驗還不錯，是我會推薦住宿的地點。</p><blockquote>住宿資訊<br>地址：3 Chome-1–2 Nanbanaka, Naniwa Ward, Osaka, 556–0011日本<br>電話：+81 6–6643–5280<br>入住：15:00<br>退房：Check out 11:00<br>日期：2019-10-24 ~ 2019-10-28<br>價格：4晚 17500 NTD<br>房型：Moderate Double Room [Sakura Building] <br>房間大小：18m²</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=251275a3f552" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C 語言的字串複製]]></title>
            <link>https://medium.com/@cashbooktw/c-%E8%AA%9E%E8%A8%80%E7%9A%84%E5%AD%97%E4%B8%B2%E8%A4%87%E8%A3%BD-94da3884dc6e?source=rss-18d2a0191e28------2</link>
            <guid isPermaLink="false">https://medium.com/p/94da3884dc6e</guid>
            <category><![CDATA[c]]></category>
            <dc:creator><![CDATA[Gary Yeh]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 10:23:17 GMT</pubDate>
            <atom:updated>2019-10-07T10:23:17.403Z</atom:updated>
            <content:encoded><![CDATA[<p>首先先看在 C 當中要怎麼宣告字串。可以用字元陣列並且做陣列的初始化︰</p><pre>char foo[10] = {&#39;h&#39;, &#39;e&#39;, &#39;l&#39;, &#39;l&#39;, &#39;o&#39;, &#39;\0&#39;};<br>char foo_2[] = {&#39;h&#39;, &#39;e&#39;, &#39;l&#39;, &#39;l&#39;, &#39;o&#39;, &#39;\0&#39;}; //由編譯器決定大小<br>char bar[10] = &quot;hello&quot;; // 使用常量<br>char *bar_2 = &quot;hello&quot;; //使用指標<br>printf(&quot;strlen: %d,%d,%d,%d\n&quot;, strlen(foo), strlen(foo_2),<br>       strlen(bar), strlen(bar_2)); //5, 5, 5, 5<br>printf(&quot;size: %d,%d,%d,%d\n&quot;, sizeof(foo), sizeof(foo_2),<br>       sizeof(bar), sizeof(bar_2)); //10, 6, 10, 8</pre><blockquote>使用字串常量，編譯器會自動幫你補空字元在字串尾。</blockquote><p>可以從前面的範例看到 strlen 是回傳由前往後數，直到遇到空字元的字元個數(不包含空字元本身)；而 size則是看你宣告的空間有多大。</p><p>接下來看 strcpy</p><pre>char * strcpy ( char * destination, const char * source );</pre><p>從來源字串複製到目的字串，回傳值是指向目的字串的位址。使用這個函式要注意的是，萬一來源字串長度是否比目的字串所使用的空間還大，便會發生存取非法記憶體空間的問題。</p><p>為了解決這個問題，可以使用 strncpy，第三個參數可以指定最多複製字元的個數。</p><pre>char * strncpy ( char * destination, const char * source, <br>                 size_t num );</pre><p>雖然解決越界寫入的問題，但考慮以下情況︰</p><pre>char foo[10] = {0};<br>char bar[] = &quot;hellohello&quot;;<br><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strncpy.html">strncpy</a>(foo, bar, sizeof(foo));</pre><p>此時來源字串的空字元並沒有寫到目的字串，讀取目的字串的值時便會發生錯誤。所以通常使用 strncpy 時，可以搭配以下寫法︰</p><pre>#define FOO_MAX = 10<br>char foo[FOO_MAX] = {0};<br>char bar[] = &quot;hellohello&quot;;<br>//method1<br>memset(foo, &#39;\0&#39;, FOO_MAX); //確定空間都清成0<br><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strncpy.html">strncpy</a>(foo, bar, FOO_MAX-1); //複製最大個數減1</pre><pre>//method2<br>strncpy(foo, bar, FOO_MAX);<br>foo[FOO_MAX-1] = {0}; //強制把最後一位清成0</pre><p>接下來看sprintf</p><pre>int sprintf(char *str, const char *format, ...)</pre><p>sprintf 可以格式化來源字串，輸出到目的字串，回傳值是寫入的字元總數，不包含空字元。但缺點跟 strcpy 一樣，會有寫入溢出的問題。</p><p>snprintf 跟 strncpy類似，可以指定最多複製字元的個數。</p><pre>int snprintf ( char * s, size_t n, const char * format, ... );</pre><p>但是跟 strncpy 不同的是，複製字元的個數是 n-1，第 n 個字元則是空字元。</p><p>程式設計者應該要根據程式的情況來選擇要使用的 API，並且避免寫法隱含的風險。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94da3884dc6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C++ STL - basic_string]]></title>
            <link>https://medium.com/@cashbooktw/cpp-stl-basic-string-8506d907a9b8?source=rss-18d2a0191e28------2</link>
            <guid isPermaLink="false">https://medium.com/p/8506d907a9b8</guid>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Gary Yeh]]></dc:creator>
            <pubDate>Fri, 26 Jul 2019 14:17:29 GMT</pubDate>
            <atom:updated>2019-07-26T14:17:29.233Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QqqOOE4uRFGWNHRi" /><figcaption>.Photo by <a href="https://unsplash.com/@joaovictorxavier?utm_source=medium&amp;utm_medium=referral">João Victor Xavier</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>這邊整理介紹關於 string 的 member function</p><ul><li>建構函數與解構函數</li><li>字串長度</li><li>字串元素</li><li>字串比較</li><li>字串修改</li><li>字串尋找</li></ul><h3>建構函數與解構函數</h3><p>先從建構函數開始說起，要初始化一個 String，一般常見的有這幾種用法：</p><pre>string(); <br>string(const string&amp; str);<br>string(const string&amp; str, size_t pos, size_t len = npos);<br>string(const char* s);<br>string(const char* s, size_t n);<br>string(size_t n, char c);<br>string(InputIterator first, InputIterator last);</pre><p>舉例來說：</p><pre>string s; //宣告一個空的字串<br>string t(s); //宣告字串t，值為複製字串 s<br>string t(s, 0, 5); //值為複製字串 s，從索引位置0開始，指定複製的長度5<br>string t(cstr); //值為複製 C-String cstr<br>string t(cstr, 5); //值為複製 C-String cstr，從索引位置0開始，複製長度5<br>string t(5, &#39;c&#39;); //值為5個字元 c<br>string t(s.begin(), s.end()) //值為複製字串 s，參數為Iterator的開始至結束(包含InputIterator first所指的字元至InputIterator last所指的前一個字元)</pre><p>這邊的 C-String 是指以 null 結束的字元陣列。如果要將 string 轉成 C-String，可以使用 c_str()。</p><pre>string s = &quot;stringsvalue&quot;;<br>char c_arr[s.length() + 1];<br>strcpy(c_arr, s.c_str());</pre><p>如果要宣告一個只含一個字元的字串：</p><pre>string s(&#39;c&#39;);</pre><p>這樣是錯誤的，因為引數的型態並不是 string，也不是 C-String。</p><p>可以使用下面的形式：</p><pre>string s(1, &#39;x&#39;); //method 1<br>string s(&quot;x&quot;); //method 2</pre><p>解構函數使用：</p><pre>~string();</pre><h3>字串長度</h3><p>跟長度有關的 member function 常見的有以下幾個：</p><ul><li>size()</li><li>length()</li><li>max_size()</li><li>capacity()</li><li>reserve(size_t n = 0)</li><li>resize(size_t n), resize (size_t n, char c)</li><li>shrink_to_fit()</li></ul><p>size() 跟 length() 都是回傳 string 的長度，兩個方法基本上是完全一樣，差別只在於在英文文法上，在形容字或句子的長度時，會使用 length。另外在其他的 STL containers，例如 vector 或 map，也是使用 size() 來取得長度。要使用哪一個方法就由大家自己選擇囉。</p><p>max_size() 會回傳 string 可以容納的最大長度。要注意的是，如果你宣告了合法的長度，也是有可能會因為 memory allocate 錯誤而無法使用。</p><p>capacity() 會回傳已經 allocated 的空間。</p><p>reserve(size_t n = 0) 則是分配空間給字串，例如：</p><pre>string s;<br>s.reserve(100); //預先分配長度100的空間<br>s.size(); //0<br>s.capacity(); //100或大於100</pre><p>若 reserve 的參數 n 比目前字串的 capacity 還要大，則呼叫 reserve 後，字串的 capacity 會大於或等於 n，視系統實作而定；若 reserve 的參數n 比目前字串的 capacity 還要小，則呼叫 reserve 後，會發出 shrink 的請求，將 capacity 減少至 size 大小。這邊的請求是一個 non-binding request，也就是雖然你想將多餘的空間還回去，但系統不一定會照做；若 reserve 的參數 n 比 max_size 還要大，則會拋出 length_error 的異常。</p><p>resize(size_t n) 是將字串的長度直接改變，與 reserve 改變 capacity 不同。若n 小於目前字串的長度，則會將字串截斷，取前 n 個字元；若 n 大於目前字串的長度，則多出來的空間會填入 value-initialized characters(也就是 null characters)。resize (size_t n, char c)可以傳入第二個引數，多出來的空間都會填入你指定的字元 c。</p><p>shrink_to_fit()從c++11開始加入，將 capacity 減少至 size 大小，如同前面提到的一樣，是一個 non-binding request。</p><h3>字串元素</h3><p>有兩個方式可以得到字串元素，一個是使用運算子[]，另外一個是使用 at() 函數。使用運算子[]的情況，不會檢查索引的有效性。當索引小於或等於字串的長度，是有效的；當索引大於字串長度時，則為未定義行為。當使用 at() 函數時，會檢查傳入的引數，若大於或等於字串長度時，會拋出 out_of_range 的異常。</p><pre>string s(&quot;test&quot;);<br>cout &lt;&lt; s[1]; //output: e<br>cout &lt;&lt; s.at(4);  //out_of_range exception</pre><h3>字串比較</h3><p>字串提供了 compare 函數，可以用來比較兩個字串是否相同，或是其字典順序。函數原型如下：</p><pre>int compare(const string&amp; str) const;</pre><p>可以傳入參數 string str。</p><pre>int compare(size_t pos, size_t len, const string&amp; str) const;<br>int compare(size_t pos, size_t len, const string&amp; str, <br>size_t subpos, size_t sublen) const;</pre><p>可以指定被比較字串的起始位置與長度，也可以再傳入比較字串的起始位置與長度。</p><pre>int compare(const char* s) const;<br>int compare(size_t pos, size_t len, const char* s) const;</pre><p>可以傳入參數 C-String，也可以指定被比較字串的起始位置與長度。</p><pre>int compare(size_t pos, size_t len, const char* s, size_t n) const;</pre><p>可以傳入字元陣列，因為有指定長度 n，所以不需要 null-terminated。</p><p>回傳值如果是0，表示兩者比較結果是相同的；如果回傳值是負數，表示被比較字串的字典順序要在前面，或是所有比較字元都相同，但是被比較字串的長度較短；如果回傳值是正數，表示被比較字串的字典順序要在後面，但是被比較字串的長度較長。例如：</p><pre>string s = “abc”;<br>string t = “abcd”;<br>cout &lt;&lt; s.compare(0, 3, t, 0, 3) &lt;&lt; endl; // 0<br>cout &lt;&lt; s.compare(0, 3, t, 0, 2) &lt;&lt; endl; // 1<br>cout &lt;&lt; s.compare(0, 3, t, 0, 4) &lt;&lt; endl; // -1</pre><p>除了 compare 函數之外，也可以用關係運算子 ==、!=、&lt;、&lt;=、&gt;、&gt;=。大小就是字典順序，在前者為小。若是要比較字元陣列，則必須是 null-terminated，否則為未定義行為。</p><h3>字串修改</h3><p>字串修改常用的方法有很多，例如 assign、operator=、swap、erase、insert、append、replace。</p><ul><li>assign 常用的用法有這些：</li></ul><pre>assign(const basic_string&amp; str);<br>assign(const basic_string&amp; str, size_type subpos, size_type sublen = npos);<br>assign(const charT* s);<br>assign(const charT* s, size_type n);<br>assign(size_type n, charT c);<br>assign(InputIterator first, InputIterator last);</pre><p>可以看到跟建構函式的參數型態一樣，這邊就不多撰述。使用 assign 會直接把原本的字串替換掉，就是重新賦值的意思。</p><ul><li>operator= 跟 assign 一樣是重新賦值的功能。</li><li>swap 可以交換兩個字串，就是彼此替換的意思。</li></ul><pre>string s = &quot;foo&quot;;<br>string t = &quot;bar&quot;;<br>s.swap(t);</pre><ul><li>erase 的用法有這些：</li></ul><pre>erase(size_type pos = 0, size_type len = npos);<br>erase(const_iterator p);<br>erase(const_iterator first, const_iterator last);</pre><p>舉例來說：</p><pre>string str (&quot;The quick brown fox jumps over the lazy dog&quot;);<br>str.erase(10,4); //The quick n fox jumps over the lazy dog<br>//刪除指定位置開始的長度                    <br>str.erase(str.begin()+7);//The quik n fox jumps over the lazy dog<br>//刪除指定位置的字元            <br>str.erase(str.begin()+8, str.end()-9);//The quik lazy dog<br>//刪除指定位置開始至結束</pre><ul><li>insert的用法有這些：</li></ul><pre>insert(size_type pos, const basic_string&amp; str);<br>insert(size_type pos, const basic_string&amp; str,<br>        size_type subpos, size_type sublen = npos);<br>insert(size_type pos, const charT* s);<br>insert(size_type pos, const charT* s, size_type n);<br>insert(size_type pos, size_type n, charT c);<br>insert(const_iterator p, size_type n, charT c);<br>insert(const_iterator p, charT c);<br>insert(iterator p, InputIterator first, InputIterator last);</pre><p>舉例來說</p><pre>string str = “brown fox”;<br>string str2 = “The “;<br>string str3 = “quick “;<br>string str4 = “the lazy dog”;</pre><pre>str.insert(0, str2);  //The brown fox<br>str.insert(4, str3, 0, 6); //The quick brown fox<br>str.insert(19, “jumps “); //The quick brown foxjumps<br>str.insert(25, “over my dead body”, 4); <br>//The quick brown foxjumps over<br>str.insert(19, 1, ‘ ‘); //The quick brown fox jumps over<br>str.insert(str.end(), 1, ‘ ‘); //The quick brown fox jumps over<br>str.insert(str.end(), ‘t’); //The quick brown fox jumps over t<br>str.insert(str.end(), str4.begin() + 1, str4.end());<br>//The quick brown fox jumps over the lazy dog</pre><ul><li>append 常見的用法有這些：</li></ul><pre>append(const basic_string&amp; str);<br>append(const basic_string&amp; str, size_type subpos, <br>        size_type sublen = npos);<br>append(const charT* s);<br>append(const charT* s, size_type n);<br>append(size_type n, charT c);<br>append(InputIterator first, InputIterator last);</pre><p>可以看成是 insert 在最後面的用法。</p><ul><li>replace 常見的用法有這些：</li></ul><pre>replace(size_type pos, size_type len, const basic_string&amp; str);<br>replace(const_iterator i1, const_iterator i2, <br>         const basic_string&amp; str);<br>replace(size_type pos, size_type len, const basic_string&amp; str,<br>        size_type subpos, size_type sublen = npos);<br>replace(size_type pos, size_type len, const charT* s);<br>replace(const_iterator i1, const_iterator i2, const charT* s);<br>replace(size_type pos, size_type len, const charT* s, size_type n);<br>replace(const_iterator i1, const_iterator i2, <br>        const charT* s, size_type n);<br>replace(size_type pos, size_type len, size_type n, charT c);<br>replace(const_iterator i1, const_iterator i2, size_type n, charT c);<br>replace(const_iterator i1, const_iterator i2,<br>        InputIterator first, InputIterator last);<br>replace(const_iterator i1, const_iterator i2,<br>        initializer_list&lt;charT&gt; il);</pre><p>可以看成是 erase 加上 insert 的用法。</p><h3>字串尋找</h3><p>跟字串有關的函式有 find、rfind、find_first_of、find_first_not_of、find_last_of、find_last_not_of。</p><ul><li>find 可以提供目標字串，在原始字串當中尋找相等於目標字串，若有找到第一個符合的，回傳其在原始字串中的位置；若沒有找到，則回傳 npos。find 的函式原型有這些：</li></ul><pre>size_type find (const basic_string&amp; str, size_type pos = 0) const noexcept;<br>size_type find (const charT* s, size_type pos = 0) const;<br>size_type find (const charT* s, size_type pos, size_type n) const;<br>size_type find (charT c, size_type pos = 0) const noexcept;</pre><p>pos 指的是從哪裡開始尋找。</p><p>當尋找目標是 const charT* s 時，若 n 有指定，則需相等於目標的前 n 個字元；若 n 沒有指定，則 s 必須是 null-terminated。</p><p>舉例來看：</p><pre>string str = “abcdefg”;<br>string t = “cde”;<br>string::size_type found;<br>found = str.find(t, 1); //2<br>found = str.find(“fg”, 1); //5<br>found = str.find(“bcd”, 0, 3); //1<br>found = str.find(‘c’, 0); //2</pre><ul><li>rfind 與 find 相反，是從指定的位置往前尋找(沒有指定則是從原始字串的尾端開始)。可以想成是有一個 sliding window 由前往後與由後往前的差別。</li><li>find_first_of 的用法是尋找原始字串當中，含有任一個目標字串當中的字元時，回傳其位置。與 find 不同，find 需要整個目標字串符合，而find_first_of 只需要其中一個字元符合。</li></ul><pre>string str (“The quick brown fox jumps over the lazy dog”);<br>string::size_type found = str.find_first_of(“aeiou”); //2</pre><ul><li>find_first_not_of 就跟 find_first_of 相反，是尋找第一個沒有含有目標字串當中的字元。</li><li>find_last_of、find_last_not_of 就是往前尋找的用法。</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8506d907a9b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[用 Preorder 與 Inorder traversal 畫出 binary tree]]></title>
            <link>https://medium.com/@cashbooktw/construct-binary-tree-with-preorder-and-inorder-traversal-c50fb945f00f?source=rss-18d2a0191e28------2</link>
            <guid isPermaLink="false">https://medium.com/p/c50fb945f00f</guid>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Gary Yeh]]></dc:creator>
            <pubDate>Tue, 11 Sep 2018 09:05:40 GMT</pubDate>
            <atom:updated>2018-09-11T09:05:40.480Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rs0paX_4j57HKap1VvLM5w.jpeg" /></figure><p>給定一個 binary tree 的 Preorder與 Inorder traversal，證明這組 traversal，只能對應到一個獨特的 binary tree。<br>(前提是每一個 element 都是 unique。)</p><p>在證明之前，我們要先知道 Preorder 跟 Inorder 的特性。<br>Preorder 的 traversal 順序是根、左子樹、右子樹；Inorder 的 traversal 順序是左子樹、根、右子樹。</p><p>因此 Preorder 的第一個 element 會是根。<br>而 Preorder 的問題會是，在後面的 element，不知道有哪些是屬於左子樹，哪些是右子樹。<br>也許全都是左子樹，也可能全部都是右子樹。</p><p>這邊可以藉由 Inorder 來判斷。<br>假設 Preorder 的第一個 element 是 r0，則在 Inorder 中，r0 之前的，就是左子樹；r0 之後的，就是右子樹。<br>跟據左子樹跟右子樹的這些 elements，就可以判斷在 Preorder 當中，哪些屬於左子樹，哪些是右子樹。</p><p>接著，左子樹跟右子樹又可以單獨拿出來看，成為新的樹，找到新的根。<br>然後就可以重複上述的步驟，用 recursive 的方式，找完所有 elements，<br>這時就可以畫出這整個 binary tree 了。</p><p>我們可以用一個例子來看：<br>Preorder: [0, 1, 3, 4, 2, 5]<br>Inorder: [3, 1, 4, 0, 2, 5]</p><p>從 Preorder 得知根是[0]，從 Inorder 得知左子樹的 elements 是[3, 1, 4]，右子樹是[2, 5]。<br>因此 Preorder 這邊的左子樹的 elements 是[1, 3, 4]，右子樹是[2, 5]。</p><p>接著從 Preorder，新的左子樹得到根是[1]，從 Inorder 得知左子樹的 elements 是[3]，右子樹是[4]。<br>新的右子樹得到根是[2]，從 Inorder 得知左子樹是[5]。<br>我們便可以從這些資訊畫出下面的 binary tree。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*jfDpj3fVIMG8zeoTEAnj5g.png" /></figure><p>同理，Postorder 跟 Inorder 也可以畫出獨特的 binary tree，差別就是，根是位在 Postorder 的最後一個 element。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c50fb945f00f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[安裝 Ubuntu 16.04]]></title>
            <link>https://medium.com/@cashbooktw/%E5%AE%89%E8%A3%9D-ubuntu-16-04-6ac20eb8eec1?source=rss-18d2a0191e28------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ac20eb8eec1</guid>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Gary Yeh]]></dc:creator>
            <pubDate>Sat, 17 Jun 2017 08:07:50 GMT</pubDate>
            <atom:updated>2017-06-17T11:27:20.968Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dSAk_3BkF9qibV693bVcjA.png" /><figcaption>Ubuntu 16.04 + mac theme</figcaption></figure><p>由於 windows 被我搞壞了，因此我索性把雙系統(windows 10 + ubuntu 14.04)洗掉，改成單一 Ubuntu 16.04。這邊紀錄一下重灌的過程。</p><h4>第一步，救援並備份 windows檔案</h4><p>從官網下載 ubuntu 16.04 iso檔，用 unetbootin 製作開機隨身碟，在這之前，隨身碟需要先格式化成 FAT32 的檔案格式。用隨身碟開機之後，進到 Ubuntu(Try Utuntu)，掛載原本有windows 資料的硬碟分割區。但問題來了，無法掛載，原因是 windows 10 預設使用快速開機，會存一些 data，造成你沒有權限去使用。網路上的作法是去關閉電源選項中的快速開機，並使用系統管理員權限輸入 powercfg /h off。但因為我進到 windows 後沒多久就會 crash，因此無法使用這個作法。後來是使用 sudo ntfsfix /dev/sdXY ，XY是你的分割槽名稱。之後用指令掛載 sudo mkdir /media/sda1 與 <br>sudo mount /dev/sda1 /media/sda1。</p><h4>第二步，安裝 Ubuntu 16.04</h4><p>這邊要進行分割硬碟，基本上必要的只有4個部份，我大概都分割網路推薦的兩倍大小，反正硬碟很大，可以用得很奢侈。</p><ul><li>EFI — 1G</li><li>SWAP — 16G(你的記憶體的兩倍大小)</li><li>/ — 40G</li><li>/home — 剩下的硬碟空間</li></ul><h4>第三步，安裝中文輸入法</h4><p>因為我一開始選擇英文語系，所以要自己裝中文輸入法。這邊踩了一個雷，我把 ibus 給刪除了，結果系統把 unity-control-center 視為相依性套件一併刪除了(把 ibus 重裝並不會也把 unity-control-center也裝回去)，造成我重新登入後，所有的 application 都叫不出來，也無法登出，最後只能再重灌一次。<br>終於要安裝中文輸入法了，到 language support 更新一下之後， uncomment /etc/locale.gen 檔案中的 zh_TW.UTF8 ，就有新酷音輸入法可以使用了。</p><h4>第四步，安裝 Theme</h4><p>不喜歡預設的 Theme ，所以從網路上選擇了 <a href="http://www.noobslab.com/2016/04/macbuntu-1604-transformation-pack-for.html">MacBuntu 16.04 Transformation Pack For Ubuntu 16.04</a> 來使用。基本上就是照著步驟安裝。小技巧就是安裝 Slingscold 之後，想把 icon 放進 Plank 的 dock 中，要到/usr/share/applications 去把 icon拉進去。另外 Albert 跟 Plank 要放進開機啟動，搜尋 gnome-session-properties 便可以找到初始啟動程式。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ac20eb8eec1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn how to learn]]></title>
            <link>https://medium.com/@cashbooktw/learn-how-to-learn-6ef26be7feab?source=rss-18d2a0191e28------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ef26be7feab</guid>
            <category><![CDATA[learn]]></category>
            <dc:creator><![CDATA[Gary Yeh]]></dc:creator>
            <pubDate>Thu, 01 Jun 2017 15:45:49 GMT</pubDate>
            <atom:updated>2017-06-01T15:45:49.994Z</atom:updated>
            <content:encoded><![CDATA[<p>一門在coursera 的免費課程<br>除了英文之外也有簡體中文<br><a href="https://zh-tw.coursera.org/learn/learning-how-to-learn">https://zh-tw.coursera.org/learn/learning-how-to-learn</a></p><p>節錄重點如下</p><ul><li>專心與分散思考</li></ul><p>專心思考是用於例如像推導公式，而分散思考則是提升聯想力，激發創意的思考方式</p><ul><li>將需要練習的作業分散不同時間做</li></ul><p>十天練習一小時優於一天練習十小時</p><ul><li>充足的睡眠</li><li>拆解學習目標的概念</li></ul><p>因此大綱很重要</p><ul><li>交叉學習不同項目</li></ul><p>有時候不同項目的概念可能類似</p><ul><li>使用番茄鐘(結束時應給自己獎勵)</li><li>設定目標時，重點要放在，花某些時間做事，而不是把事情完成</li></ul><p>把工作設定成「執行半小時」，而不是「把工作完成」</p><ul><li>把一些瑣事寫下來，免得占用腦袋思考空間</li><li>萬事起頭難，告訴自己著手後就不會這麼難了</li><li>使用Mind palace</li></ul><p>例如要回想昨天看的資料，想像自己昨天當下的情況</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ef26be7feab" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>