<?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 Software Notebook on Medium]]></title>
        <description><![CDATA[Stories by Software Notebook on Medium]]></description>
        <link>https://medium.com/@softwarenotebook?source=rss-1b9893e0f04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Tto6oeaYu9xlUCaWGOHWFw.png</url>
            <title>Stories by Software Notebook on Medium</title>
            <link>https://medium.com/@softwarenotebook?source=rss-1b9893e0f04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 23:09:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@softwarenotebook/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[How to Use MediaStreams in React]]></title>
            <link>https://softwarenotebook.medium.com/how-to-use-mediastreams-in-react-a2e41b88fd5?source=rss-1b9893e0f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2e41b88fd5</guid>
            <category><![CDATA[input-output]]></category>
            <category><![CDATA[stream]]></category>
            <category><![CDATA[mediastream]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[medium]]></category>
            <dc:creator><![CDATA[Software Notebook]]></dc:creator>
            <pubDate>Tue, 27 Sep 2022 22:37:19 GMT</pubDate>
            <atom:updated>2022-09-27T22:37:19.321Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you need to access the user’s webcam for video chat or the user’s microphone for a recording? In this simple tutorial, I’ll show you how to access and use the computer’s media inputs with React.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PrujcqWcNpo_jgKgkNiWkQ.jpeg" /></figure><p>The <strong>MediaDevices</strong> interface provides access to connected media input devices like cameras and microphones.</p><h4>Get access to user’s media input</h4><p>After getting the user’s permission, the MediaDevices.getUserMedia() method produces a <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaStream"><strong>MediaStream</strong></a>. This stream can have multiple tracks containing the requested types of media. Examples of tracks include video and audio tracks.</p><p>The getUserMedia() method takes in a constraints parameter with two members: <strong>video</strong> and <strong>audio,</strong> describing any configuration settings for the tracks. It returns a Promise that resolves to a MediaStream object. You can set your video element’s src to the stream.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22f271e79942a3f7f6cb342768247146/href">https://medium.com/media/22f271e79942a3f7f6cb342768247146/href</a></iframe><p>Here are some examples of preferences that you can customize in the stream:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30feabe5a2e157450729be92bf23dbb1/href">https://medium.com/media/30feabe5a2e157450729be92bf23dbb1/href</a></iframe><h4>Save user’s media stream in a variable</h4><p>After you get the user’s media stream from .getUserMedia(), you should save the stream in a state variable. This is so that you can manipulate the stream later (to stop it, get a track from it, etc.)</p><p>For example, if you want to stop the stream, get all of the stream’s tracks using the MediaStream.getTracks() method and call the .stop() method on them.</p><p>If you want to access the audio separately, use the MediaStream.getAudioTracks() method. To access video separately, use MediaStream.getVideoTracks().</p><p>You should also have state that controls if media input is on or off. You should use the useRef hook to control the video element in the DOM.</p><p><strong>This is the final code:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96e427c893271fa0caa5888307dbeeea/href">https://medium.com/media/96e427c893271fa0caa5888307dbeeea/href</a></iframe><p>Thank you for reading! If you enjoyed this article, check out my <a href="https://twitter.com/joshbcodes">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2e41b88fd5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LeetCode #125: Valid Palindrome (Solution in Python & Explanation)]]></title>
            <link>https://softwarenotebook.medium.com/leetcode-125-valid-palindrome-solution-in-python-explanation-e2707c82af59?source=rss-1b9893e0f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2707c82af59</guid>
            <category><![CDATA[palindrome]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[solutions]]></category>
            <category><![CDATA[valid-palindrome]]></category>
            <dc:creator><![CDATA[Software Notebook]]></dc:creator>
            <pubDate>Tue, 07 Jun 2022 16:14:22 GMT</pubDate>
            <atom:updated>2022-09-28T17:11:52.473Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*67f7dMvOBkZU-tt4osQjQQ.jpeg" /><figcaption>Dog on the computer</figcaption></figure><p>In this article, I will be explaining how to solve the Valid Palindrome problem on LeetCode. This is an Easy-level problem.</p><h3>The Problem</h3><p>A phrase is a <strong>palindrome</strong> if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.</p><p>Given a string s, return true<em> if it is a </em><strong><em>palindrome</em></strong><em>, or </em>false<em> otherwise</em>.</p><p><strong>Example 1:</strong></p><pre><strong>Input:</strong> s = &quot;A man, a plan, a canal: Panama&quot;<br><strong>Output:</strong> true<br><strong>Explanation:</strong> &quot;amanaplanacanalpanama&quot; is a palindrome.</pre><p><strong>Example 2:</strong></p><pre><strong>Input:</strong> s = &quot;race a car&quot;<br><strong>Output:</strong> false<br><strong>Explanation:</strong> &quot;raceacar&quot; is not a palindrome.</pre><p><strong>Example 3:</strong></p><pre><strong>Input:</strong> s = &quot; &quot;<br><strong>Output:</strong> true<br><strong>Explanation:</strong> s is an empty string &quot;&quot; after removing non-alphanumeric characters. <br>Since an empty string reads the same forward and backward, it is a palindrome.</pre><h3>Solution</h3><p>Alphanumeric characters are the lowercase letters a-z, capital letters A-Z, and integers 0–9.</p><p>So, to solve this, we first want to remove all non-alphanumeric characters, including spaces, punctuation, etc., from the input string. Then, we need to check the new string to see if it’s a palindrome. We have two ways we can do this.</p><h4>Solution #1</h4><p>For this solution, we create a new string which contains all of the alphanumeric characters from the input string (lowercased). Then, we compare this new string to its reversed version. If they are the same, the function returns true. If not, it returns false.</p><p>In order to create the new string, we loop through the characters in the original input string and, if the character is alphanumeric, we append it to the new string.</p><p>Finally, we can check if the string (without any special characters or spaces) is a palindrome by using a boolean expression to equate it to its reverse. We can get the reverse of a string by using str[::-1]</p><pre>def isPalindrome(self, s: str) -&gt; bool: <br>    newStr = &quot;&quot; <br>    for char in s: <br>        if char.isalnum(): <br>            newStr += c.lower() <br>    return newStr == newStr[::-1]</pre><p>This solution has a time complexity of O(n) because we have to loop through the string to remove non-alphanumeric characters. It also has a space complexity of O(n) because we are creating another string, which could be at most the size of the input string.</p><h4>Solution #2</h4><p>For this solution, we will create pointers to the beginning and end of the array which will make sure that the two sides have the same characters in the same order.</p><p>First, create two pointers- one which points to the beginning of the string and the other which points to the end. The two pointers will move inwards, checking each character until the reach the middle or overlap with each other.</p><p>As the pointers loop through the characters, they will skip any characters that are not alphanumeric. To do this, we use while loops that will continue to run until the character at the left/ right index is alphanumeric. We also add a check to make sure that the left/right index is in bounds by checking left &lt; right / right &gt; left</p><p>We must make sure to compare the lowercase versions of the characters to each other. If any character at the left pointer does not match the corresponding character at the right pointer, then we know that it’s not a palindrome and can return False. If the entire loop finishes then that must mean the string is a palindrome and we can return True.</p><pre>def isPalindrome(self, s: str) -&gt; bool: <br>    left, right = 0, len(s) - 1 <br>    while left &lt; right: <br>        while left &lt; right and not s[left].isalnum(): <br>            left +=1 <br>        while right &gt; left and not s[right].isalnum(): <br>            right -= 1 <br>        if s[left].lower() != s[right].lower(): <br>            return False <br>        left, right = left + 1, right - 1 <br>    return True</pre><p>The time complexity for this solution is O(n) because you are still looping through the entire string. The space complexity is O(1) because you are not making a new string.</p><p><em>Originally published at </em><a href="https://softwarenotebook.com/2022/06/07/leetcode-125-valid-palindrome-solution-in-python-explanation/"><em>http://softwarenotebook.com</em></a><em> on June 7, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2707c82af59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Split Pandas DataFrame into Multiple DataFrames by Column Value in Python]]></title>
            <link>https://softwarenotebook.medium.com/how-to-split-pandas-dataframe-into-multiple-dataframes-by-column-value-in-python-cd8c75c2cd25?source=rss-1b9893e0f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd8c75c2cd25</guid>
            <category><![CDATA[pandas-dataframe]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pandas-tutorial]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[dataframes]]></category>
            <dc:creator><![CDATA[Software Notebook]]></dc:creator>
            <pubDate>Sat, 05 Mar 2022 19:29:24 GMT</pubDate>
            <atom:updated>2022-09-27T21:28:45.014Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, I will show you how to create a separate DataFrame for each value for a given column.</p><p>Use the pandas.DataFrame.groupby(column) method to group the DataFrame by the values found in the column named column.</p><pre>grouped_df = df.groupby(&#39;Column&#39;)</pre><p>This method returns a GroupBy object. You can see this yourself by printing the new dataframe by running print grouped_df:</p><pre>&lt;pandas.core.groupby.generic.DataFrameGroupBy object at 0x7efe3ec55670&gt;</pre><p>With the GroupBy object from the previous function, call the DataFrameGroupBy.get_group(group) method on the new dataframe grouped_df.</p><p>This method will return a Dataframe of all the rows that have the value group in the column named column.</p><pre>grouped_df.get_group(&#39;column_value&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/0*7ao7cmDxZpmgOQce" /></figure><p>Alternatively, you can call both methods in one line:</p><pre>value_df = df.groupby(&#39;Column&#39;).get_group(&#39;column_value&#39;)</pre><p><em>Originally published at </em><a href="https://softwarenotebook.com/2022/03/05/how-to-split-pandas-dataframe-into-multiple-dataframes-by-column-value-in-python/"><em>http://softwarenotebook.com</em></a><em> on March 5, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd8c75c2cd25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set Python default version to 3.x on macOS]]></title>
            <link>https://softwarenotebook.medium.com/how-to-set-python-default-version-to-3-x-on-macos-bd6066ca2ba7?source=rss-1b9893e0f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd6066ca2ba7</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[installation]]></category>
            <category><![CDATA[homebrew]]></category>
            <category><![CDATA[python-version]]></category>
            <category><![CDATA[mac]]></category>
            <dc:creator><![CDATA[Software Notebook]]></dc:creator>
            <pubDate>Fri, 14 Jan 2022 14:18:11 GMT</pubDate>
            <atom:updated>2022-09-27T21:37:52.972Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Drpll26RYai02fQmeBcQYw.jpeg" /><figcaption>Python written on a sticky note</figcaption></figure><p>In this tutorial, I’ll show you how to update your Mac’s default version of Python from 2.x to 3.x.</p><p>If Python 3.X is already installed on your system, even if it’s not the default version, then you should be able to run version 3.X using the python3 command in your Terminal. But in this tutorial, I&#39;ll be showing you how you can run version 3.X using the default python command.</p><h3>Step 0: Install Homebrew</h3><p><a href="https://brew.sh/">Homebrew</a> is a very popular package manager for macOS. If you don’t already have it installed, you can install it by running this command:</p><pre>/bin/bash -c &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)&quot;</pre><h3>Step 1: Install Python with Homebrew</h3><p>This command will install Python 3.</p><pre>brew install python</pre><h3>Step 2:</h3><p>Next, we’ll check the symlinks for Python 3.x. A symlink or a Symbolic Link is simply enough a shortcut to another file. Run this command:</p><pre>ls -l /usr/local/bin/python*</pre><p>This should output something like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ErWP3sFTP6Y7IXGI" /></figure><p>Look at the first line. It shows default python being symlinked to the brew installed python3. If it does not show this exactly, then set it as the default python symlink by running this:</p><pre>ln -s -f /usr/local/bin/python3 /usr/local/bin/python</pre><p>You should probably run this command just to be sure. Run ls -l /usr/local/bin/python* again and make sure you have the desired output.</p><h3>Step 3: Verify Python 3.X install</h3><p>Run the following command to see which executable Python binary will launch when you issue a python command to the shell:</p><pre>which python</pre><p>The output should be this: /usr/local/bin/python</p><p>Finally, check if the default Python version has changed:</p><pre>python --version</pre><p>The terminal should output the newest version of Python 3.x. For me, it is Python 3.9.7.</p><p>That’s it! Hope this helps.</p><p><strong>Published</strong></p><p><em>Originally published at </em><a href="https://softwarenotebook.com/2022/01/14/how-to-set-python-default-version-to-3-x-on-macos/"><em>http://softwarenotebook.com</em></a><em> on January 14, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd6066ca2ba7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn Socket.io in 2 Hours]]></title>
            <link>https://softwarenotebook.medium.com/learn-socket-io-in-2-hours-914f2c139ab1?source=rss-1b9893e0f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/914f2c139ab1</guid>
            <category><![CDATA[socketio]]></category>
            <category><![CDATA[sockets]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Software Notebook]]></dc:creator>
            <pubDate>Fri, 20 Aug 2021 09:46:55 GMT</pubDate>
            <atom:updated>2021-08-20T09:46:55.064Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn Socket.io for both the server and client-side</h4><h4>The Purpose of WebSockets</h4><p><strong>WebSocket</strong> is a communication protocol that provides a bidirectional communication channel between a server and client over HTTP through a TCP connection.</p><p>This may be confusing, but all you need to understand is that WebSockets allow the connection between client and server to <em>persist</em>.</p><p>In a regular client-server transaction, the client would get the data they need from the server then close the connection. If the client needs 10 pieces of information they have to make 10 requests.</p><p>With WebSockets, on the other hand, the client can connect to the server and have that connection stay open. So the client can make 10 requests with just 1 connection.</p><p>WebSockets are perfect for applications that require real-time data transfer.</p><h4>What is Socket.io?</h4><p><strong>Socket.io</strong> is a simple-to-use library that uses WebSockets to enable real-time bidirectional communication between client and server.</p><p>Socket.IO is composed of two parts:</p><ul><li>A server that integrates with (or mounts on) the Node.JS HTTP Server</li><li>A client library that loads on the browser side</li></ul><p>First, we’ll set up Socket.io on an Express server</p><h4>Socket.io on the Server</h4><p>First, install the package to use Socket.io (npm install socket.io). In your server file, import Socket.io.</p><pre>const socketio = require(&#39;socket.io&#39;);</pre><p>You’ll also need to import the HTTP module and create an HTTP server:</p><pre>const http = require(&#39;http&#39;);<br>const server = http.createServer(app);</pre><p>http.createServer is used by Express under the hood, but we will need to access it directly to use Socket.io.</p><p>Using the HTTP server, we create an io object:</p><pre>const io = socketio(server);</pre><h4>Socket.io Methods on the Server</h4><p>The io.on(‘connection’, …) method runs every time a client connects to our server. All of the other Socket.io logic goes inside the callback function of this method.</p><pre>io.on(‘connection’, socket =&gt; {<br>   // all socket logic <br>});</pre><p>The first argument socket is the user’s Socket instance.</p><p>socket.on() listens for events from the client. In the parentheses put the specific String name of the event to listen for. The client can optionally pass data which can be accessed the function’s callback. Here’s an example:</p><pre>socket.on(&quot;message&quot;, text =&gt; {<br>   console.log(&quot;New message: {text}&quot;)<br>})</pre><p>In the above example, the string &quot;message&quot; is a custom event emitted from the client whenever a new message is sent. The client sends text data along with the event which can be accessed in the callback function.</p><p>io.emit() sends, or <em>emits</em>, an event to all connected clients, including the sender. The syntax is similar to the previous method we discussed. The server can pass data as an optional parameter in this method.</p><pre>io.emit(&quot;alert&quot;, &#39;some alert data&#39;)</pre><p>socket.broadcast.emit(“message”)sends an event to all connected clients, <em>except</em> the one that sent the message.</p><p>socket.join(room) adds the user’s socket to a room. A room is an arbitrary channel that sockets can join and leave. It can be used to broadcast events to a subset of clients.</p><p>io.in(&#39;game&#39;).emit(&#39;message&#39;, data) sends an event to all clients in game room (channel), including the sender.</p><p>socket.to(id).emit(“message”, data)sends an event to an individual socket by putting their id in the to() method.</p><p>You can also use this method to send an event to a room with multiple sockets (similar toio.in()) by passing the room name/id in the to() method.</p><p>socket.on(‘disconnect’, () =&gt; {}) is fired by the Socket instance upon disconnection.</p><h4>Socket.io on the Client</h4><p>If you are using a frontend framework such as React or Vue, you need to install the Socket.io client library in your project folder (npm install socket.io-client).</p><p>In your working file, import io from the client library:</p><pre>import { io } from &#39;socket.io-client&#39;</pre><p>Then, create a socket on the frontend by calling the io function and passing in the address of your server.</p><pre>const socket = io(&#39;http://localhost:3000&#39;)</pre><p>Use socket.on(&#39;event&#39;, data =&gt; {}) to listen for and handle events from the server:</p><pre>// Receive message from server and output it to screen<br>socket.on(&#39;message&#39;, (message) =&gt; {<br>  outputMessage(message);<br>});</pre><p>Use socket.emit(&#39;event&#39;, data) to send events to the server:</p><pre>socket.emit(&#39;joinRoom&#39;, { username, room });</pre><h4>Example Socket.io Implementation</h4><p>I’m going to give a simple example of a situation where a user can send a message to the server and the server will broadcast the message to all of the users. This is similar to what you would need to do in a chat application.</p><p>On the client, this function sendMessage emits an event called‘sendMessage’ to the server and includes an object with a username and message.</p><pre>const sendMessage = (message) =&gt; {<br>    socket.emit(&#39;sendMessage&#39;, { username, message });<br>}</pre><p>On the server, we are listening for the ‘sendMessage’ event from the client. If the event occurs, we broadcast an event containing the username and message to all connected clients using io.emit().</p><pre>io.on(&#39;connection&#39;, socket =&gt; {</pre><pre>   socket.on(&#39;sendMessage&#39;, ({ username, message }) =&gt; {<br>       io.emit(&#39;newMessage&#39;, { username, message })<br>   });</pre><pre>}</pre><p>On the client, this method is listening for the ‘newMessage’ event from the server. If a message is recieved, it shows the the message on the screen.</p><pre>socket.on(&#39;newMessage&#39;, ({ username, message }) =&gt; {<br>   showMessage(&#39;Message from {username}: {message}&#39;);<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=914f2c139ab1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>