<?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 Nicole Peng on Medium]]></title>
        <description><![CDATA[Stories by Nicole Peng on Medium]]></description>
        <link>https://medium.com/@nicolepeng99?source=rss-c7e997e83a3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4OAfR18uyom4ftSZtPv5BQ.jpeg</url>
            <title>Stories by Nicole Peng on Medium</title>
            <link>https://medium.com/@nicolepeng99?source=rss-c7e997e83a3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 13:52:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nicolepeng99/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[Comparison sort]]></title>
            <link>https://medium.com/@nicolepeng99/comparison-sort-aea6aea0137f?source=rss-c7e997e83a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/aea6aea0137f</guid>
            <dc:creator><![CDATA[Nicole Peng]]></dc:creator>
            <pubDate>Wed, 29 Jul 2020 20:44:04 GMT</pubDate>
            <atom:updated>2020-07-29T20:44:04.020Z</atom:updated>
            <content:encoded><![CDATA[<p>A <strong>comparison sort</strong> is a type of <a href="https://en.wikipedia.org/wiki/Sorting_algorithm">sorting algorithm</a> that only reads the list elements through a single abstract comparison operation (often a “less than or equal to” operator or a <a href="https://en.wikipedia.org/wiki/Three-way_comparison">three-way comparison</a>) that determines which of two elements should occur first in the final sorted list. — Wikipedia</p><p>Comparison sort algorithms that occur often in interviews include: Bubble Sort, Selection Sort, Insert Sort, Merge Sort, Quick Sort.</p><ul><li>Bubble Sort: compare any two adjacent numbers, if the previous one is bigger than the latter one, switch these two numbers.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*tQVvjE1JvhB3RgG54GNCWw.png" /></figure><p><em>Time complexity: O(n²), </em><strong>stability</strong></p><ul><li>Selection Sort: find the minimum number in each iteration and put it in at first. Starting with the second position for the next iteration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*uSyNKIu_BiJh1BbS3Jv3gA.png" /></figure><p><em>Time complexity: O(n²), un</em><strong>stability</strong></p><ul><li>Insert Sort: on an already sorted array, insert a number each time. Start with the first element of the array for each iteration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*QZvb6XsRAEWpMu39xTv5PQ.png" /></figure><p>Time complexity: best case is O(n), worst case is <em>O(n²),</em> <strong>stability</strong></p><ul><li>Merge Sort: make each subarray sorted first internally and then make the subarrays sorted.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*cufO5XMHTxzkjWpNvwTlKg.png" /></figure><p><em>Time complexity：O(nlogn), </em><strong>stability</strong></p><ul><li>Quick Sort: Pick the number in the mid position as the baseline. Iterate through the array. If a number is less than the baseline, put it on the left of the baseline number. Otherwise, put it on the right. Then recurse on the left and right part.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*4Udk3q37QcxJr8R98rWRQA.png" /></figure><p><em>Time complexity: average O(nlogn),worst O(n²), un</em><strong>stability</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aea6aea0137f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to determine the space complexity of recursion]]></title>
            <link>https://medium.com/@nicolepeng99/how-to-determine-the-space-complexity-of-recursion-1f138ccd56e5?source=rss-c7e997e83a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f138ccd56e5</guid>
            <dc:creator><![CDATA[Nicole Peng]]></dc:creator>
            <pubDate>Tue, 14 Jul 2020 14:56:13 GMT</pubDate>
            <atom:updated>2020-07-14T14:56:13.686Z</atom:updated>
            <content:encoded><![CDATA[<p>The space complexity is determined by the space occupied. For iterative case, it is straightforward to infer the space complexity from the variables being used. However, for recursion case, it is usually not that straightforward.</p><p>We will use Fibonacci sequence as an example to determine the space complexity of recursion.</p><p>Fibonacci sequence：1，1，2，3，5，8，13，21，34……</p><p>That is，F(1) = 1; F(2) = 1; F(n) = F(n-1) + F(n-2) (n≥2).</p><p>If n=5：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*mSQN4pvE8Kg6JQL_4KbwZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*mskwkOBrm_3gQo2-nj833A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*uC3F1S9Qp507t3faGh8azQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TZdmXEziK0fpJJ2RKF0B_Q.png" /></figure><p>Conclusion： space complexity is determined by the layer of recursion.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f138ccd56e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A simple Rails app that allows signing up, signing in, signing out]]></title>
            <link>https://medium.com/@nicolepeng99/a-simple-rails-app-that-allows-signing-up-signing-in-signing-out-8fceed4aa8a6?source=rss-c7e997e83a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fceed4aa8a6</guid>
            <dc:creator><![CDATA[Nicole Peng]]></dc:creator>
            <pubDate>Wed, 27 May 2020 20:53:48 GMT</pubDate>
            <atom:updated>2020-05-27T20:53:48.443Z</atom:updated>
            <content:encoded><![CDATA[<p>We can use Rails’ built-in has_secure_password method to build functionalities for users to sign up, sign in and sign out.</p><p><strong>Build a new project</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*QqEHmSPsd4dGIsXyCPvZzQ.png" /></figure><p><strong>Use bcrypt encryption. In the Gemfile, import gem ‘bcrypt’</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*eOQer6X5HISsztpy7vbGxA.png" /></figure><p>Run ‘bundle install’ command to install the gem package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*Oc8NaNMjEzBTwb86FVzj0w.png" /></figure><p><strong>Create user model</strong></p><p>To manage user information, we need to create table and model to save users</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*1nlt4958eo-DpRsDlV2acQ.png" /></figure><p>password_digest is used to save encrypted password. It cannot be changed.</p><p>Then we add has_secure_password in the user model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*pSqLKbGN5G4txqZKj-E5Iw.png" /></figure><p><strong>Migrate user table:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y8AqfOHDx-_BQdWerwSHDA.png" /></figure><p><em>If there is no password_digest in the user table, run “rails db:migrate”.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hc5DbFSH5oSiI14PufauWA.png" /></figure><p><em>In this situation we can add migration to user table.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jZq7ZfBDv6s13-EGLnGRDQ.png" /></figure><p><em>Then run “rails db:migrate”.</em></p><p><strong>Create sign up functionality</strong></p><p>Create an Applicant controller to deal with user registration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*1MCBsB3I7M6SQKVz2H4gkA.png" /></figure><p>applicants controller provides two methods:</p><p>new: to deal with registration page</p><p>create: to save registration information</p><p>The methods used to create controller above use get request by default. The ‘create’ method to save registration information uses ‘post’ request. So we need to change config/routers.rb as follows:</p><p>post ‘applicants/create’</p><p><strong>Add method in the registration controller:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*2nV6PaiDRJSWxKV8mNoVtQ.png" /></figure><p><strong>Add sign up forms</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*S_ntrkWOTTplEsu_zbU0_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*uq9bZ5dBI7B83Ggyu8Nd3g.png" /></figure><p><em>After signing up, users will return to the sign in page automatically. Users will get a pop-up window asking if the users want to save password.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*JLO3cDcnrRvpKIpIaoXDEQ.png" /></figure><p><strong>Create sign in functionality</strong></p><p>Create a Session Controller to deal with user signing in and out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*nkw448odg2k42GOAEZNUrQ.png" /></figure><p>There are two methods created on the sessions controller by default.</p><ul><li>new: to deal with sign in page</li><li>create: to deal with sign out page</li></ul><p>Same as signing in, we need to change router in config/routers.rb to post as follows:</p><p>post ‘sessions/create’</p><p><strong>Add</strong> <strong>methods to session controller.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*ko8jnwUopfzeYbCEbC9xkA.png" /></figure><p><strong>Add log in forms.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*UlxWNVM1UQwXKzYmPwAPHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*bAg9WeVerXu0qvjioDKGtw.png" /></figure><p><strong>Create display form.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*-ORlfdf4K1HG2af9a-yIZw.png" /></figure><p>After log in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*NZril43I7JKhPkhFDNSb_w.png" /></figure><p>Click logout button, back to login page.</p><p>config/routes.rb</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*cyQ2J5Mn1twCV7Iy9dC7jQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fceed4aa8a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get to learn Rack]]></title>
            <link>https://medium.com/@nicolepeng99/get-to-learn-rack-44b4104c904a?source=rss-c7e997e83a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/44b4104c904a</guid>
            <dc:creator><![CDATA[Nicole Peng]]></dc:creator>
            <pubDate>Mon, 11 May 2020 07:41:44 GMT</pubDate>
            <atom:updated>2020-05-11T07:41:44.870Z</atom:updated>
            <content:encoded><![CDATA[<p>Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.</p><p>Rails is a Rack App, and most Ruby web framework are Rack Apps.</p><p>Here is a list of Ruby web framework from rubyonrails.org</p><ul><li>Camping</li><li>Coset</li><li>Espresso</li><li>Halcyon</li><li>Mack</li><li>Maveric</li><li>Merb</li><li>Racktools::SimpleApplication</li><li>Ramaze</li><li>Ruby on Rails</li><li>Rum</li><li>Sinatra</li><li>Sin</li><li>Vintage</li><li>Waves</li><li>Wee</li></ul><p>Why Rack?</p><p>Without Rack, how do we build a Ruby web app?</p><p>Browsers and servers communicate through HTTP, which is a process that includes requests and responses.</p><p>Request is sent from the client side via browser. It includes a header file which has the address and type of the request (e.g., get/post/put/delete). Then the browser sends a formatted string to the server. At the server side, without Rack, we need to analyze the string from the browser to generate a response using our own program.</p><p>On the other hand, according to the HTTP protocol, Response is a string of the same format as Request. After the browser receives the Response, it will analyze and render it, and then generate the page. Without rack, this Response string will need to be generated by ourselves as well.</p><p>A Ruby web application has three layers:</p><p>Framework (Rails, Sinatra, …）</p><p>Rack</p><p>WebServer (Puma, Passanger, Unicorn…)</p><p>Rack layer is designed for connecting Framework and WebServer. To give a Response, we only need to define an app object in the Framework layer, a call method. Then WebServer can pass the information from the Request to the call method and generate a Response.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44b4104c904a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>