<?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 Thea Harvey-Brown on Medium]]></title>
        <description><![CDATA[Stories by Thea Harvey-Brown on Medium]]></description>
        <link>https://medium.com/@tharveybrown?source=rss-46b95984a273------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SpxL-P75JmfWF28Y.jpg</url>
            <title>Stories by Thea Harvey-Brown on Medium</title>
            <link>https://medium.com/@tharveybrown?source=rss-46b95984a273------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 13:28:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tharveybrown/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[Deploying a React frontend and Rails backend on Heroku]]></title>
            <link>https://medium.com/@tharveybrown/deploying-a-react-frontend-and-rails-backend-on-heroku-8da9f8bde4af?source=rss-46b95984a273------2</link>
            <guid isPermaLink="false">https://medium.com/p/8da9f8bde4af</guid>
            <dc:creator><![CDATA[Thea Harvey-Brown]]></dc:creator>
            <pubDate>Mon, 06 Jul 2020 20:50:45 GMT</pubDate>
            <atom:updated>2020-07-06T20:50:45.518Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Create the Rails app architecture</h3><p>To get started, run:</p><pre>rails new backend-app --api -T --database=postgresql</pre><p>Heroku is not compatible with sqlite3, so the postgresql flag will set you up nicely for deployment. Add the following to your gem file: gem ‘rack-cord&#39;, :require =&gt; ‘rack/cors&#39; . Create a new file in the config/initializers directory called cors.rb, and add:</p><pre><em>Rails</em>.application.config.middleware.insert_before 0, <em>Rack</em>::Cors do</pre><pre>allow do<br>  origins &#39;http://localhost:3000&#39;, #TODO: add frontend domain<br>  resource &#39;*&#39;,<br>  headers: :any,<br>  methods: [:get, :post, :put, :patch, :delete, :options, :head]<br>end</pre><pre>end</pre><p>This will allow your frontend’s origin(s) to make api requests.</p><p>In your config/puma.rb file, modify the port to 3001: port ENV.fetch(&quot;PORT&quot;) {3001} .</p><p>Now you’re ready to create models, controllers, and routes. I like to use a resource generator, i.e. rails g resource List name status .</p><p>Once your resources are setup, test the server on localhost:3001 with rails s .</p><h3>2. Create the React client</h3><p>We are going to use <a href="https://github.com/facebook/create-react-app">Create React App</a> to create our React frontend. You need <a href="https://nodejs.org/en/">Node.js</a> to install that package. Install create-react-app globally and then create the React project:</p><pre>npm install -g create-react-app<br>create-react-app frontend-app &amp;&amp; cd frontend-app</pre><p>Start the app by running npm start.</p><p>Now we need to tell our React app to use the backend service on a specific port in development mode. Create a .env file in your root directory, and add the following: REACT_APP_API_URL=”http://localhost:3001&quot;</p><p>Once your app is deployed, however, you’ll want to configure this environment to point to your backend root url. Runtime configuration. Supports only <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables">REACT_APP_</a> prefixed variables.</p><p>Install the <a href="https://www.npmjs.com/package/@mars/heroku-js-runtime-env">runtime env npm package</a>:</p><pre>npm install @mars/heroku-js-runtime-env --save</pre><p>In your api requests from the frontend, configure the root url to access this variable, e.g.:</p><pre>const url = runtimeEnv().REACT_APP_API_URL;</pre><h3>3: Deploying Rails Backend</h3><ul><li>Navigate into the directory housing your project’s Rails backend: cd backend-app</li><li><strong>Sign into Heroku:</strong></li></ul><pre>heroku login</pre><ul><li><strong>Create Heroku project</strong></li></ul><pre>heroku create backend-app</pre><ul><li><strong>Initialize heroku git remote</strong></li></ul><pre>git remote add heroku git@heroku.com:backend-app.git</pre><ul><li><strong>Add, commit, and push repository to your Heroku’s remote:</strong></li></ul><pre>git add .git commit -m &quot;first heroku commit&quot; git push heroku master</pre><p>Alternatively, if you’re not working off master:</p><pre>git add .git commit -m &quot;first heroku commit&quot; git push heroku &lt;your-branch-name&gt;:master</pre><ul><li><strong>Migrate your database</strong></li></ul><pre>heroku run rake db:migrate</pre><p>And, you’re done! Run heroku open to check the status, and copy the url.</p><h3>4. Deploying React Frontend</h3><ol><li>Set a config var</li></ol><pre>heroku config:set GITHUB_USERNAME=joesmith</pre><pre>$ heroku config:set GITHUB_USERNAME=joesmith</pre><pre>{ &quot;root&quot;: &quot;build/&quot;, &quot;routes&quot;: { &quot;/**&quot;: &quot;index.html&quot; } }</pre><p><strong>2. Update paths in fetch requests, or any other reference to your Rails api, to the URL of your deployed backend:</strong></p><p>Using my project as an example, this means replacing all references to <a href="http://localhost/">http://localhost</a>:3000 with <a href="https://chatster-app-api.herokuapp.com/">https://chatster-app-api.herokuapp.com</a></p><p><strong>3. Create a Heroku app set to create-react-app-buildpack:</strong></p><pre>heroku create chatster-app --buildpack <a href="https://github.com/mars/create-react-app-buildpack.git">https://github.com/mars/create-react-app-buildpack.git</a></pre><p><strong>4</strong>. <strong>Initialize Heroku remote:</strong></p><pre>git remote add heroku git@heroku.com:chatser-app.git</pre><p><strong>5. Add, commit, and push repo to Heroku remote:</strong></p><pre>git add .<br>git commit -m &quot;Start with create-react-app&quot;<br>git push heroku master</pre><p><strong>6. Open app:</strong></p><pre>heroku open</pre><p>And, voilà! Your project is live!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8da9f8bde4af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bash script to find and kill ports]]></title>
            <link>https://medium.com/@tharveybrown/bash-script-to-find-and-kill-ports-e3dc866e2759?source=rss-46b95984a273------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3dc866e2759</guid>
            <dc:creator><![CDATA[Thea Harvey-Brown]]></dc:creator>
            <pubDate>Mon, 22 Jun 2020 18:55:24 GMT</pubDate>
            <atom:updated>2020-06-22T18:55:24.486Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve probably googled “find and kill ports mac” every time I’ve needed to shut down a process. sudo lsof -i :3000 doesn’t exactly stick to the tongue. What I really wanted was a menu that would show me all the currently open ports, allow me to select which one I wanted to kill, and then kill that process.</p><p>I decided to create my own script and add it to my local environment. First, I needed to create a selectable menu of open ports. To search for processes that listen on a specific port use the lsof or “List Open Files”.</p><p>The <strong>-p </strong>option excludes or selects the listing of files for the processes<br> whose optional process IDentification (PID) numbers are in<br> the comma-separated set. If only TCP and UDP files are to be listed, as controlled by the specified exclusions and inclusions, the <strong>-i </strong>option must<br> be specified, too. For example, to list only network files with TCP state<br> LISTEN, use: -iTCP -sTCP:LISTEN.</p><p>The command I used to execute the search was: lsof -PiTCP -sTCP:LISTEN | awk &#39;${print $9}&#39; | sed -n &#39;1!p&#39; , which prints out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*-zMTKlbxZkGWA9QiqP88LA.png" /></figure><p>Thus, creating the menu is pretty simple:</p><pre>PS3=&#39;Please enter your choice: &#39;</pre><pre>options=$(lsof -PiTCP -sTCP:LISTEN | awk &#39;{print $9}&#39; | sed -n &#39;1!p&#39;)</pre><pre>select port in $options<br>do<br>  echo &quot;Selected character: $port&quot;<br>  echo &quot;Selected number: $REPLY&quot;<br>done</pre><p>This creates a simple selectable menu that lets the user choose a port by entering the corresponding number:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*S01g9OKiRH_OBOLtzTtA2g.png" /></figure><p>Now on to the next step: killing the selected port. To kill all processes listening on a specific port use:</p><pre>lsof -ti tcp:5900 | xargs kill</pre><p>The -t command returns only the PID, exactly for the purpose of piping it somewhere, and the xargs executes kill on each line returned.</p><p>Putting it all together, the bash script becomes:</p><pre>#!/bin/bash<br># file: /usr/local/bin/kill_ports</pre><pre>PS3=&#39;Please enter your choice: &#39;<br>options=$(lsof -PiTCP -sTCP:LISTEN | awk &#39;{print $9}&#39; | sed -n &#39;1!p&#39;)<br>RED=&#39;\033[0;31m&#39;<br>NC=&#39;\033[0m&#39; # No Color</pre><pre>select port in $options<br>do<br>  echo &quot;Selected character: $port&quot;<br>  echo &quot;Selected number: $REPLY&quot;<br>  var2=$(echo $port | cut -f2 -d:)<br>  echo -e &quot;killing ${RED}port $var2 ${NC}!&quot;<br>  echo $(lsof -ti tcp:$var2 | xargs kill)<br>  exit 0<br>done</pre><p>Great, we have the code! The last step is making this script universally accessible. To make the script global, move the file to/usr/local/bin, whcih Mac OS X has in its PATH by default. Make sure to run chmod +x ${your_script_name} to grant you user permissions. Now, within any directory, you can just run ${your_script_name}, e.g. kill_ports to access the menu and kill the selected process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3dc866e2759" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Drawing (and deploying) Sol Lewitt]]></title>
            <link>https://medium.com/swlh/drawing-and-deploying-sol-lewitt-535d89214a91?source=rss-46b95984a273------2</link>
            <guid isPermaLink="false">https://medium.com/p/535d89214a91</guid>
            <category><![CDATA[d3js]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[art]]></category>
            <dc:creator><![CDATA[Thea Harvey-Brown]]></dc:creator>
            <pubDate>Mon, 18 May 2020 18:24:23 GMT</pubDate>
            <atom:updated>2020-05-18T18:26:13.116Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Sol LeWitt (</strong>1928–2007), who helped establish Conceptualism and Minimalism in after WWII, was known for his deceptively simple geometric sculptures and paintings. He focused on concept over construction; form was a means rather than an end.</p><blockquote>In conceptual art the idea or concept is the most important aspect of the work. When an artist uses a conceptual form of art, it means that all of the planning and decisions are made beforehand and the execution is a perfunctory affair. The idea becomes a machine that makes the art.</blockquote><blockquote>— Sol Lewitt</blockquote><p>Over the course of his career, Sol LeWitt produced approximately 1,350 wall drawings, comprising about 3,500 installations at more than 1,200 venues. Each wall drawing began as a specific set of instructions and was often executed by other people (with LeWitt’s oversight).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k3sF92J2KbteOMgjdktnjA.png" /></figure><p>LeWitt’s process made the physical form of art secondary to the idea behind it. Concept art is designed to engage the mind more than the eye. In other forms of art, concept is not immune to execution; execution often informs concept. In Conceptualism, the idea itself is as much a work of art as any finished product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*m9n2HAflzf1PvrYzJ2zA2Q.png" /></figure><p>This approach lends itself well to reproduction. I’ve been obsessed with LeWitt since I first saw his work at SFMOMA. And if I were a better artist, I would have painted one of my walls with a full spread of Wall Drawing <strong>#1183.</strong></p><p>Instead, I decided to reproduce his artwork programmatically. In my first attempt, for <strong>#340</strong>, I worked with <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API">canvas</a>, which is an html element that can be used to add graphics and animation.</p><p>To start “drawing” within the canvas element, you need to use a script to actually generate the graphics.</p><pre>var canvas = document.getElementsByTagName(&#39;canvas&#39;)[0];</pre><pre>var ctx = canvas.getContext(&#39;2d&#39;);</pre><p>The getContext() method returns an object that provides methods and properties for drawing on the canvas. This reference (ctx) now has access to the properties and methods of the getContext(&quot;2d&quot;) object, which can be used to draw text, lines, boxes, circles, and more - on the canvas.</p><p>The instructions for <strong>Wall Drawing #340 </strong>are as follows:</p><blockquote>Six-part drawing. The wall is divided horizontally and vertically into six equal parts. 1st part: On red, blue horizontal parallel lines, and in the center, a circle within which are yellow vertical parallel lines; 2nd part: On yellow, red horizontal parallel lines, and in the center, a square within which are blue vertical parallel lines; 3rd part: On blue, yellow horizontal parallel lines, and in the center, a triangle within which are red vertical parallel lines; 4th part: On red, yellow horizontal parallel lines, and in the center, a rectangle within which are blue vertical parallel lines; 5th part: On yellow, blue horizontal parallel lines, and in the center, a trapezoid within which are red vertical parallel lines; 6th part: On blue, red horizontal parallel lines, and in the center, a parallelogram within which are yellow vertical parallel lines. The horizontal lines do not enter the figures.</blockquote><p>I created a function for each part:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47a659c7ca0b08bae956d222a9268159/href">https://medium.com/media/47a659c7ca0b08bae956d222a9268159/href</a></iframe><p>The shape(shape_type, background_color, foreground_color) function generates the shape within one of the “parts”, and drawShapes() runs on init(), which initializes at load time. Check out the final product <a href="https://sol-lewitt-wall-drawing.netlify.app/340.html">here</a>.</p><p>For the next drawing, <strong>#87</strong>, I used a combination of <a href="https://d3js.org/"><strong>D3.js</strong></a><strong> </strong>and <a href="https://github.com/riccardoscalco/textures"><strong>textures.js</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ROnwIOcxFUMhL2r3x7dJTQ.png" /></figure><p>Textures.js is a handy Javascript library for creating SVG patterns on top of D3. To create the stripes in each quadrant, I wrote the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a178795aff675bd692c7330887d331f0/href">https://medium.com/media/a178795aff675bd692c7330887d331f0/href</a></iframe><p>After completing <strong>#340</strong> and <strong>#87</strong>, I figured the work should probably live outside of Github and my local. I used <a href="https://www.netlify.com/"><strong>Netlify</strong></a> to deploy my project. Since the site only contains HTML, CSS, and JS files, I didn’t need to specify a build command or publish directory. All I had to do was authorize the repository and leave default settings unchanged, which includes auto-deployments on merge to master. Pretty simple!! You can even use Netlify’s drag and drop settings if you don’t want to authorize Netlify to your GitHub repo (or supported version-control tool of choice).</p><p>Check out the deployed project here: <a href="https://sol-lewitt-wall-drawing.netlify.app/">https://sol-lewitt-wall-drawing.netlify.app/.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=535d89214a91" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/drawing-and-deploying-sol-lewitt-535d89214a91">Drawing (and deploying) Sol Lewitt</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Under the hood of Active Record]]></title>
            <link>https://medium.com/swlh/under-the-hood-of-active-record-931f0898084a?source=rss-46b95984a273------2</link>
            <guid isPermaLink="false">https://medium.com/p/931f0898084a</guid>
            <dc:creator><![CDATA[Thea Harvey-Brown]]></dc:creator>
            <pubDate>Mon, 04 May 2020 23:19:50 GMT</pubDate>
            <atom:updated>2020-05-18T21:30:27.799Z</atom:updated>
            <content:encoded><![CDATA[<p>Active Record makes the life of a programmer a whole lot easier. And not just because it insulates you from the need to write SQL. Active Record provides a bundle of convenient methods that make working with databases more intuitive and more resilient to complexity.</p><p>Let’s start by looking at a program that doesn’t use Active Record. Say we want to model a ride-sharing app that has users, rides, and drivers. First, let’s map the relationship.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k-3Wrw-q06iA85zeFycL-Q.png" /></figure><p>The best way to model this is with a has_many_through relationship. Let’s break it down:</p><ul><li>A user has_many :drivers, through: :ride</li><li>A driver has_many :users, through: :ride</li></ul><p>Here, we’re essentially delegating a model relationship to another model, so instead of having to call user.rides.drivers, you can just do user.drivers. Much better. 😌</p><p>In Ruby, a class represents a table and a class object represents a row in that table. We’ll begin with three classes to represent each table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*q6Kty7cQzJScYQhhT3h-0g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*qsWKde2PXTSrrfKgbv5yQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*kT1fsv7PKjf2X8dYwIlUWg.png" /></figure><p>Before we can create our three tables we need to create our database. In our environment.rb file we can establish a connection to our database:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99ebf69c9b859d310069e0934d3281bf/href">https://medium.com/media/99ebf69c9b859d310069e0934d3281bf/href</a></iframe><p>Great! Time to build out our classes. According to the ORM convention, a class is mapped to a database table. <strong>To associate our class to a database table, we will create a table with the same name as our class — but plural — and give that table column names that match the attr_accessors of our class.</strong></p><p>Here we have an attr_accessor for name, address, and rating. In order to “map” this User class to a users database table we need to create our songs table.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38309a77895f8e661944ae1a18323100/href">https://medium.com/media/38309a77895f8e661944ae1a18323100/href</a></iframe><p>Now that we have a link between our database and our class, we can start writing some CRUD operations.</p><p>Let’s say I want to create a new user and save it to my users database. The #new method creates a new instance of the user class, a new Ruby object. The #save method takes the attributes that characterize a given song and saves them in a new row of the songs table in our database.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79c7deff0f729c58da06fb7844972130/href">https://medium.com/media/79c7deff0f729c58da06fb7844972130/href</a></iframe><p>Lastly, let’s perform a simple read operation to find a user by the user id:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c986252864ece45b68af38f351a61c5/href">https://medium.com/media/0c986252864ece45b68af38f351a61c5/href</a></iframe><p>That was a lot of effort to do something fairly simple. And if we built out our methods in the Ride and Driver class, we’d quickly see a lot of duplicate code. You’d have to create methods in each class that perform both general and specific crud operations — .find_by_name, .drop_table, add_column… the list goes on. That’s where the magic of Active Record comes in.</p><h3>What is Active Record?</h3><p>Active Record is a design pattern that maps your objects to a relational database. It’s the <strong>M</strong> in MVC — the model — which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and manipulation of objects whose data requires storage to a database. Once you set up your class to inherit from Active Record, your class now has access to all of the fundamental CRUD operations:</p><pre>class User &lt; ActiveRecord::Base[5.2]<br>end</pre><p>The User class just became two lines of code. That’s simplicity at its best.</p><h3><strong>Create your migration</strong></h3><p>Active Record provides a generator to create migrations. Instead of having to write a .create_table method within your class, you can instead run a Rake task to generate your table schema (make sure to install active-record or sinatra-activerecord if you aren’t working with Rails). To do this, run rake db:create_migration NAME=users. This will automatically generate a migration file where you can define the schema:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a656951c3000d7049aa30476be458d62/href">https://medium.com/media/a656951c3000d7049aa30476be458d62/href</a></iframe><p>After creating a migration file for each table, run rake db:migrate to execute the migration.</p><h3>CRUD with Active Record</h3><p>Remember how complicated our .create method was? First we had to generate a new Object instance, and then we had to save it to the database, first checking to see if that object already exists in the database. Active Record includes all of that functionality in its library, so you can invoke .create, .save and .new without having to write out a line of code.</p><p>Find the documentation <a href="https://guides.rubyonrails.org/active_record_querying.html">here</a> to see all of the operations included with Active Record. Never again will you have to manually build out these methods!</p><p>You can find the code to this project <a href="https://github.com/tharveybrown/sql-to-active-record">here</a>. Checkout the without-active-record branch to view the classes without inheriting Active Record; otherwise, default to master and follow along in the README.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=931f0898084a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/under-the-hood-of-active-record-931f0898084a">Under the hood of Active Record</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>