<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ star wars - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ star wars - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 10:50:27 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/star-wars/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ React Props/State Explained Through Darth Vader’s Hunt for the Rebels ]]>
                </title>
                <description>
                    <![CDATA[ By Kevin Kononenko If you’ve seen Star Wars, then you can understand props and state. Props and state are essential to writing readable React code. But they’re hard concepts to grasp, because they’re based around an entirely different paradigm than A... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/react-props-state-explained-through-darth-vaders-hunt-for-the-rebels-8ee486576492/</link>
                <guid isPermaLink="false">66c35d7856e6b06442afd855</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ star wars ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 04 Oct 2016 05:26:17 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*i4gLjg40GYrR12oVI5NsZw.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Kevin Kononenko</p>
<h4 id="heading-if-youve-seen-star-wars-then-you-can-understand-props-and-state">If you’ve seen Star Wars, then you can understand props and state.</h4>
<p>Props and state are essential to writing readable React code. But they’re hard concepts to grasp, because they’re based around an entirely different paradigm than Angular or jQuery (if you have used either of those).</p>
<p>But don’t worry — I’m going to clear everything up with a Star Wars analogy.</p>
<p>That’s right. If you’ve seen the original Star Wars series, you can understand props and state.</p>
<p>Here’s a spoiler-free refresher of the basic premise of episodes 4–6:</p>
<ol>
<li>Darth Vader hunts the rebels relentlessly, as they are the last resistance against the Galactic Empire.</li>
<li>The rebels, led by Princess Leia and Luke Skywalker, must fight back and exploit vulnerabilities within the Empire.</li>
<li>Darth Vader uses a variety of tactics to try and discover the movements of the rebels, including an army of Stormtroopers, a fleet of starships, and a variety of scouts.</li>
</ol>
<p>The entire plan for the Empire’s resources depends upon Vader’s leadership.</p>
<p>If you are used to using jQuery, you may think about creating one event handler (like a click() handler), then explicitly changing different parts of the user interface line-by-line.</p>
<p>But in React, the idea is that when <strong>state</strong> is modified, the changes will <strong>automatically trickle down</strong> to all child components via <strong>props</strong>. So you only need to write the code to change one thing — the <strong>state</strong> — and watch as your UI updates.</p>
<p>This is similar to the way that Darth Vader commands the three wings of his army. Once word gets back to him of the rebel location, his resources will automatically mobilize to launch an attack.</p>
<p>Let’s get into it. This tutorial will require a basic knowledge of JSX, which you can learn more about <a target="_blank" href="https://facebook.github.io/react/docs/thinking-in-react.html">here</a>.</p>
<h3 id="heading-a-summary-of-the-galactic-empire">A Summary of The Galactic Empire</h3>
<p>Here are the three wings of the Galactic Empire.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*NBQvDruVqf4qCPT-BDuADA.png" alt="Image" width="341" height="366" loading="lazy"></p>
<p><strong>The Imperial Army</strong> is composed of Stormtroopers, AT-ATs, AT-STs and others.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*0CHW4ZMIqxwVBIou8vnXkA.png" alt="Image" width="334" height="300" loading="lazy"></p>
<p><strong>The Imperial Navy</strong> is composed of star destroyers, TIE fighters and others.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*pJpvQ3IJjJZEIAHSgOPx6w.png" alt="Image" width="251" height="358" loading="lazy"></p>
<p><strong>Military Intelligence</strong> is composed of bounty hunters like Boba Fett, probe droids, and any other specialized scouts.</p>
<p>Here is a quick org chart that will give some direction on how we will write our components.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Wb5PjkC4-AY-K8J494S4ng.png" alt="Image" width="626" height="387" loading="lazy"></p>
<p>A reminder: Vader’s first goal is to find the location of the rebels. Those at the bottom of the org chart are the actual functional units that can accomplish this. If one of them finds a rebel base, their instructions would be to return to Vader so that he could execute his battle plans.</p>
<p>React is all about <strong>dynamic user interface</strong>. When a user completes a specific action, how does <strong>state</strong> change? In this case, Darth Vader would have a <strong>state</strong> called <em>rebelLocation</em>. Since that is the key dynamic variable, the three wings of the Empire would mobilize due to a change in the <em>rebelLocation</em> <strong>state</strong>.</p>
<p>Stormtrooper encounters rebel base → Return to Darth Vader with location</p>
<p>User clicks certain element → Update the state of some parent component</p>
<p>Here are the basics in code, which follows the org chart above:</p>
<h3 id="heading-state-explained">State Explained</h3>
<p><strong>State</strong> allows you to dynamically change many elements at once based on one variable. <strong>State</strong> encompasses the key parts of your UI that change basic on user input.</p>
<p>With less things to keep track of in state, you will be able to write components with more clarity and fewer opportunities for bugs. When state changes, many components may change in accordance based on the one variable.</p>
<p>jQuery approaches this by asking you to write one line for every element that must be changed. It is not explicitly based on the parent-child relationship like <strong>state</strong> is.</p>
<p>Let’s say Stormtroopers encounter the rebels. Vader has ordered them to report to him as soon as possible. Once they return with a rebel location, Vader can carry out the rest of his orders, which were contingent on the rebel location. Here is a modified diagram that charts the path through the components listed above.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*go7yyXmlbrzVJg7QDRJmjQ.png" alt="Image" width="732" height="387" loading="lazy"></p>
<p>Orders are already passed down to every member at the bottom of the chart. Once they run into rebels, they know to return to Lord Vader. The <em>rebelLocation</em> state will then be updated with the planet, be it “Endor”, “Hoth”, or somewhere else.</p>
<p>This is the same concept as receiving user input then updating state in a parent component. Many React practitioners choose to write components with a singular function, so the component that actually listens for the user input will almost always be different than the component that holds state.</p>
<p><strong>Above:</strong> Stormtrooper nested within ImperialArmy nested within vadersEmpire</p>
<p><strong>In a real app:</strong> User input nested within parent div nested within parent div</p>
<h4 id="heading-what-happens-when-state-changes">What happens when state changes?</h4>
<p>This is the beauty of React. Rather than writing complicated event handlers (like in jQuery), everything is contingent upon changes in state. You can clearly trace changes in the UI to these state changes.</p>
<p>In this case, once the <em>rebelLocation</em> is discovered, the <strong>state</strong> would change to that planet. But that is only half the story. Darth Vader would have plans in mind to mobilize different assets based on this state change. He can prepare them in advance for this possibility. As in, “When we find their planet, travel there immediately and prepare for an assault!”</p>
<p>Once state changes, the changes are automatically shared with all 3 wings of the Empire. Similarly, when the state of a parent component changes, the child components automatically inherit the new state.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*3-O1sL-whbHAa8prrqeCDQ.png" alt="Image" width="626" height="387" loading="lazy"></p>
<p>Every component can also have its own state. For example, the <em>ImperialArmy</em> component might have a <em>troopsCount</em> state which counts the members of the army. We will not modify that in this example, but you can imagine that a battle might affect <em>troopsCount</em>.</p>
<p>Notice how this state does not depend on <em>rebelLocation</em>. If it did, we would not want to explicitly declare another state. We would want it to automatically update based on a change in <em>rebelLocation</em> state.</p>
<p>Since it is independent, here is what the code looks like:</p>
<p>Wait, so how does this state get communicated between the different components? That brings us to… props!</p>
<h3 id="heading-props-explained">Props Explained</h3>
<p>With our Darth Vader case, we actually need two sets of instructions when it comes to commanding the Stormtroopers and other units on the bottom of our chart.</p>
<p><strong>Question 1:</strong> What should the Stormtroopers do if they encounter the rebels?</p>
<p><strong>Answer:</strong> Report back to Darth Vader.</p>
<p><strong>Question 2:</strong> Where should the Stormtroopers travel?</p>
<p><strong>Answer:</strong> <em>if</em> the rebels have not been found, search the galaxy at random. <em>Else</em>, go to the rebel location to attack them.</p>
<p><strong>Props</strong> allow us to continuously monitor the <em>rebelLocation</em> state, and order a troop movement if the state changes. <em>rebelLocation</em> is a string. But what about the orders that must happen when they initially find the rebels?</p>
<p>We can actually pass a function as <strong>props</strong> as well! That means that we can pass a callback down to each Stormtrooper that will execute if that trooper discovers the target. In the following picture, you can follow the path outlined by “Orders” to trace the <strong>props</strong>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*go7yyXmlbrzVJg7QDRJmjQ.png" alt="Image" width="732" height="387" loading="lazy"></p>
<p>In a typical user interface, let’s say that a user clicks a button, and you want to update the state of a parent component. You must also pass a callback from that parent component that will be triggered on the user’s click. That callback can then update the state <strong>because it originated with the same parent that set the state</strong>.</p>
<p>This is important, so let’s explore this code line-by-line:</p>
<p><strong>Line 8:</strong> We create the command for the Stormtroopers that they should return with the rebel location immediately when they find it.</p>
<p><strong>Line 19</strong>: We pass the command to the entire army via the updateLocation <strong>props</strong>.</p>
<p><strong>Line 32</strong>: The Imperial Army passes this command to every Stormtrooper with an identical updateLocation <strong>props</strong>.</p>
<p><strong>Line 42</strong>: We create a discoverLocation function so we can pass the value of the input into the updateLocation() callback when it is triggered.</p>
<p><strong>Line 53</strong>: When a Stormtrooper finds the location, it triggers the discoverLocation() function so we can return the location via updateLocation(). This updates the <strong>state</strong> in the <em>vadersArmy</em> parent component.</p>
<p><strong>Other Notes:</strong> We passed the rebelLocation all the way down to each Stormtrooper as well. In this tutorial, we will not do anything with that information, but in the future, you can imagine that might be used to shift the location of all troopers towards the rebel base.</p>
<h3 id="heading-a-final-recap">A Final Recap</h3>
<ol>
<li>Darth Vader gives every member of the Galactic Empire an order: If you find the rebels, report back to me immediately. In code, this is a function in the parent <em>vadersArmy</em> component that is then passed to every child via <strong>props</strong>.</li>
<li>The Army, Navy and Military Intel (three divisions of the Empire) pass this instruction to every single troop, again via <strong>props</strong>.</li>
<li>Each member of the Empire has the instructions. When they encounter the rebels, they will use a callback to pass the location all the way back up to Darth Vader, who will update the entire Empire with the news simultaneously and prepare for battle. This simulates a dynamic user input that changes the <strong>state</strong> of the parent component.</li>
</ol>
<p>If you enjoyed this post, you may also enjoy my <a target="_blank" href="https://www.rtfmanual.io/guides/">other explanations</a> of challenging CSS and JavaScript topics, such as positioning, Model-View-Controller, and callbacks.</p>
<p>And if you think this might help other people in the same position as you, give it a “heart”!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Unfundable Slack bots ]]>
                </title>
                <description>
                    <![CDATA[ By Bertrand Fan In December, Slack announced a $80 million fund to invest in software projects that complement its technology. As an early adopter of the Slack API, here are some “bets” that I’ve made on the Slack platform: A bot that plays all of St... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/unfundable-slack-bots-9369a75fdd/</link>
                <guid isPermaLink="false">66c36403b737bb2ce70731fc</guid>
                
                    <category>
                        <![CDATA[ bots ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ humor ]]>
                    </category>
                
                    <category>
                        <![CDATA[ slack ]]>
                    </category>
                
                    <category>
                        <![CDATA[ star wars ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 01 Mar 2016 16:32:06 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*KUlXltNVajILJHiucE6sHg.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Bertrand Fan</p>
<p>In December, Slack announced a $80 million fund to invest in software projects that complement its technology. As an early adopter of the Slack API, here are some “bets” that I’ve made on the Slack platform:</p>
<h4 id="heading-a-bot-that-plays-all-of-star-wars-despecialized-edition-han-shoots-first-one-frame-every-ten-seconds-it-takes-about-20-hours-to-get-through-the-whole-thing">A bot that plays all of Star Wars Despecialized Edition (Han shoots first!) one frame every ten seconds. It takes about 20 hours to get through the whole thing.</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*KUlXltNVajILJHiucE6sHg.png" alt="Image" width="510" height="861" loading="lazy"></p>
<h4 id="heading-a-bot-that-hosts-games-of-the-resistance-optionally-with-the-assassin-module-from-the-hidden-agenda-expansion-secret-voting-is-conducted-via-dm-with-the-bot-while-public-actions-are-done-in-the-channel">A bot that hosts games of The Resistance (optionally with the Assassin Module from the Hidden Agenda expansion). Secret voting is conducted via DM with the bot, while public actions are done in the channel.</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*mrfae1_an3lG1l9BxOBoyA.png" alt="Image" width="542" height="845" loading="lazy"></p>
<h4 id="heading-a-bot-that-lets-you-play-wolfenstein-3d-by-issuing-commands-left-right-up-down-open-and-fire-you-can-optionally-specify-how-many-degrees-to-turn-left-and-right-but-by-default-you-turn-45-degrees-ive-never-successfully-completed-the-first-level-but-i-have-managed-to-kill-several-guards">A bot that lets you play Wolfenstein 3D by issuing commands (left, right, up, down, open, and fire). You can optionally specify how many degrees to turn left and right, but by default you turn 45-degrees. I’ve never successfully completed the first level, but I have managed to kill several guards.</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*ZZSwPJsD1p3xiyHJzP9HMQ.gif" alt="Image" width="457" height="825" loading="lazy"></p>
<p>I’m happy to announce that I’ve completed my latest bot, <a target="_blank" href="https://vandelayindustries.online/">Vandelay Industries</a>. Vandelay Industries is a shameless rip-off of <a target="_blank" href="https://frinkiac.com/">Frinkiac</a> that lets you search for animated gifs from every episode of Seinfeld in Slack. It has every line of dialogue ever spoken in Seinfeld.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*dF_ekpm0NzefyQJBIw07ww.gif" alt="Image" width="457" height="367" loading="lazy"></p>
<p>If you’d like to try it out in your Slack team, just go to <a target="_blank" href="https://vandelayindustries.online">Vandelay Industries</a> and click <strong>Add to Slack</strong>. It will ask you for permission to add a new slash command, /vandelay and once authorized, it should be ready to use immediately within Slack.</p>
<p>If you’re interested in the technical details of how it works, keep on reading! If not, you’ve managed to beat the estimated reading time for this article. Congratulations!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*UHa3mQHcgfao8vYc7MThUw.gif" alt="Image" width="320" height="180" loading="lazy"></p>
<h4 id="heading-processing">Processing</h4>
<p>I initially started with 91G of all nine seasons of Seinfeld in surprisingly high quality 720p. I ultimately ended up with 111G worth of animated GIFs which tells you everything you need to know about the efficiency of that file format. This section is all about how I went from one to the other.</p>
<p>The files were in MKV containers, so I was able to use <a target="_blank" href="https://mkvtoolnix.download/">MKVToolNix</a> to extract the subtitles from them. You can use mkvinfo to list the various segment tracks:</p>
<pre><code>mkvinfo Seinfeld.S01E01.The.Seinfeld.Chronicles.mkv
</code></pre><p>It’s a little hard to read, but the track that we’re interested in is Track number 3, the first subtitles track. After noting the track ID (2), we can extract the subtitles into an SRT file like this:</p>
<pre><code>mkvextract tracks Seinfeld.S01E01.The.Seinfeld.Chronicles.mkv <span class="hljs-number">2</span>:S01E01.srt
</code></pre><p>The SRT format is fairly straightforward. It contains a counter, start time, end time, and the subtitle text. Using a parser like <a target="_blank" href="https://www.npmjs.com/package/subtitles-parser">subtitles-parser</a>, we can easily iterate over the subtitles.</p>
<p>The next step is to loop through each subtitle and extract that time range from the MKV into an animated GIF. There’s an <a target="_blank" href="http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html">excellent article about using ffmpeg to encode high quality GIF</a> but if you don’t want to read that right now, the trick is to extract a specialized palette from the section of the video that you’re interested in and then use that to encode the GIF.</p>
<p>Here’s a script that I adapted for the purposes of this processing step:</p>
<p>320 refers to how many pixels wide the resulting GIF will be. You’ll notice that instead of specifying a start time and an end time, I instead specify a duration. Although ffmpeg claims to support end times, no matter which version I tried I could not get it to properly extract the right range, so I ended up calculating the duration by subtracting the start time from the end time and abusing the unix epoch like this:</p>
<p>After applying the gifenc.sh script, we’re left with a nice animated GIF of the correct extracted range like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*1rukLpm7GTaNxkunKTjiSg.gif" alt="Image" width="320" height="180" loading="lazy"></p>
<p>But I wanted to display the subtitle text at the bottom of the GIF and after digging through the ImageMagick documentation, I came up with this:</p>
<p>It’s not the most elegant solution, but it gets the job done. Our final gif looks like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*ZTBtKosGpleB6sf_VVpvxA.gif" alt="Image" width="320" height="180" loading="lazy"></p>
<p>Now just do that about 104,782 more times and you’re done. Running an entire episode through ffmpeg and ImageMagick took about 30 minutes on my top-of-the-line-in-2011 Macbook Pro. This is the part of the story where I’d like to tell you that I managed to leverage Amazon Elastic Transcoder or made a hadoop job to distribute the load to all the computers in my house, but really what I did was put all of this on my <a target="_blank" href="https://www.soyoustart.com/">reconditioned budget OVH server</a> and let it run for 5 days while I continued to live my life.</p>
<p>Once it was done encoding all the GIFs, I just let Apache serve them statically with a long Expires header and put Cloudflare in front of the whole domain. Only time will tell if that will actually hold up with traffic demands.</p>
<h4 id="heading-searching">Searching</h4>
<p>I installed Elasticsearch and indexed the contents of the SRT files. Here’s where I encountered some non-technical snags: In Season 6, episodes 14 and 15 are an hour-long clip show called Highlights of a Hundred where Jerry Seinfeld shows you a bunch of old clips from previous episodes. And in the final episode of Seinfeld, Season 9, Episode 23, they do a ton of flashbacks to previous episodes. Both of these would routinely get returned in the search results, so I just excluded them from the search query. There’s probably a better way to just lower the quality of those episode scores, but the documentation for doing so in Elasticsearch is about as easy to read as the above mentioned ImageMagick documentation. And at the end of the day, no one wants to see clips from either of those two episodes. Sorry, Larry David, the last episode was terrible.</p>
<h4 id="heading-slash-command">Slash Command</h4>
<p>The final step was just to wrap it all together with a Slack slash command, which is just a simple Express app that acts as a client to the Elasticsearch instance. There’s some OAuth to package the command as a Slack App and handle the Add to Slack button, but I don’t really need to check for authentication when the requests come through so I’m not saving the authorization tokens. The code for the server is available here: <a target="_blank" href="https://github.com/bertrandom/vandelayindustries-slack-server">vandelayindustries-slack-server</a>.</p>
<p>That’s it! I hope this technical writeup helps the next person that wants to extract GIFs from an entire television show for little to no actual reason.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*gQJzoNu5gkQxG9EOBDiF3w.gif" alt="Image" width="320" height="180" loading="lazy"></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
