<?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 Mackenzie Frey on Medium]]></title>
        <description><![CDATA[Stories by Mackenzie Frey on Medium]]></description>
        <link>https://medium.com/@mackenziefrey?source=rss-87b90e7ca22b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jFTFSIN4vtUMUkrb</url>
            <title>Stories by Mackenzie Frey on Medium</title>
            <link>https://medium.com/@mackenziefrey?source=rss-87b90e7ca22b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 16:04:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mackenziefrey/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[A Process for Composing ActiveRecord Queries]]></title>
            <link>https://medium.com/@mackenziefrey/a-process-for-composing-activerecord-queries-b61620c8bec3?source=rss-87b90e7ca22b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b61620c8bec3</guid>
            <category><![CDATA[activerecord]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Mackenzie Frey]]></dc:creator>
            <pubDate>Mon, 18 Mar 2019 01:57:44 GMT</pubDate>
            <atom:updated>2020-06-07T00:31:32.334Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Process for Composing Active Record Queries</h3><p>Speaking from experience, the process of generating a Business Intelligence query, utilizing Active Record and SQL, can be a daunting task, especially without a process in place to do such. My growth, in this area, was recently accelerated by implementing a system to produce such a query. The following will document that system.</p><h3>Steps:</h3><p><strong>1.</strong> Do not touch your test nor test data setup yet! Instead, let’s diagram the query first.</p><p><strong>2.</strong> Take out a blank sheet of paper. Write the query to be generated (in English) at the top of the paper.</p><p>For instance, we’ll use “returns the top x items ranked by total revenue generated” for our example.</p><p>* Bonus points for using a multi-colored pen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AfYno4P6WJ_zGCHZlfwgug.jpeg" /><figcaption>Step 2</figcaption></figure><p><strong>3.</strong> Open up your database schema diagram, keep this open on the computer screen in front of you.</p><p>(The schema diagram we will use for this example is pictured below)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W5ZqbYsu-xihnFI35zk6Ow.png" /><figcaption>Step 3</figcaption></figure><p><strong>4.</strong> Brainstorm the tables you’ll need and write the table names horizontally spaced out from each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ARXLSBhpsGkM0De8nlahLA.jpeg" /><figcaption>Step 4</figcaption></figure><p><strong>5.</strong> Link together the column names which connect the tables.</p><p><em>* I prefer to use a different colored ink for the linked column names, red works for me.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PVZNb8n-A-qdgGLR9Sb_gg.jpeg" /><figcaption>Step 5</figcaption></figure><p><strong>6.</strong> Add the additional, unlinked, column names that will be required for completing the query.</p><p>* Preferably with a different colored ink. I like purple for this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVzNOq3E5NuggLwDTMW2gg.jpeg" /><figcaption>Step 6</figcaption></figure><p><strong>7.</strong> Add additional Active Record/SQL language to the diagram.</p><p>It’s 100% okay if you don’t know the exact language for a command, take a guess and write your mish mosh of Active Record/SQL/English on the paper.</p><p><em>* I prefer to use green ink for this.</em></p><p>Step 7 should complete your diagram and (ideally) contain all the concepts you’ll need to compose your query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aS8KdDgPwJFBA4zVMGbJlQ.jpeg" /><figcaption>Step 7</figcaption></figure><p><strong>8.</strong> Write the test, including the test setup.</p><p><em>* Having written the diagram first will likely make it easier to decide what test data is necessary to create.</em></p><p><strong>9.</strong> Run, your test. Watch it fail!</p><p><strong>10.</strong> Take steps to progress the test errors until you reach the model where you will compose your Active Record/SQL query method.</p><p>Define the method name, in the model.</p><p>Run the test again to ensure you’ve placed your method in the correct model and that it is appropriately coded as an instance or class method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*KtfFvGSLDde8vQJMub74Dg.png" /><figcaption>Step 10</figcaption></figure><p><strong>11.</strong> Begin by writing the first part of your query in the text editor. It is common to start with the class that is desired to be returned. Add each piece of the join statement one part at a time.</p><p>For instance, we would like to return instances of items, so we will begin the query with Item. From there, compose the first joinsstatement with the table most directly connected to theitems table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*0CYNxNZtPSuMguXwEkuDaw.png" /></figure><p><strong>12.</strong> Open a new tab in the terminal, ensure you are located in the project’s directory.</p><p>Type rails c.</p><p>Copy and paste the beginning of your query, from your text editor, into the terminal ie Item.joins(:invoice_items).</p><p>Ensure the query properly executes in the terminal.</p><p><em>* The text editor will be used as a location to store and manipulate code, which will then be copied and pasted into the terminal.</em></p><p><em>* For precision, this tutorial will proceed without troubleshooting incorrect queries.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GGyl2prQf3IMojHexWkhdQ.png" /><figcaption>Step 12a</figcaption></figure><p>Once the query works, return to the text editor to add the next part of the joinsstatement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*MmsTw6TjMBW_iQINVjWIsg.png" /><figcaption>Step 12b</figcaption></figure><p>Copy and paste the code into therails c session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_AkhZ-lDtFgfM3yst8KtQA.png" /><figcaption>Step 12c</figcaption></figure><p>Once the query works, return to the text editor. Add the next part of thejoinsstatement to the existing code in the text editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*H4zsmEEZ_9VDfOlOWpvnNw.png" /><figcaption>Step 12d</figcaption></figure><p>Return to the rails c session and paste the new code, from your text editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IImbOJCe6EHbEZ1FPGMnag.png" /><figcaption>Step 12e</figcaption></figure><p>In the text editor, continue to add onto the query, making it one long line. This will make it easier to copy and paste it into rails c. The query will later be reorganized for readability.</p><p>The following series of images, for Step 12, are intended to illustrate the essential aspect of going step-by-step for the query generation. This allows for problems to be more easily isolated to one single source of code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hW0CHdaRjkj4S1KuwoqfMw.png" /><figcaption>Step 12f</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wse3KrV_4m1UI9XGNChpgA.png" /><figcaption>Step 12g</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BQjsxly2l6vlKMlzebYVrA.png" /><figcaption>Step 12h</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tQiZvqa3rYbTF7DKAx-sZQ.png" /><figcaption>Step 12i</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-93xH3o9mf8vNoENJ4XXUg.png" /><figcaption>Step 12j</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2owmQTr4n3-ZlMAQHA2k-A.png" /><figcaption>Step 12k</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XtsZnmZllf_6CgWRe6ZbMg.png" /><figcaption>Step 12l</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iyjBGG2bQMApR8z1u5dpZA.png" /><figcaption>Step 12m</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*upQGNPti2-l9d4g4cKT_hA.png" /><figcaption>Step 12n</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fTmEnWJ35rrSLPRQE5l2uw.png" /><figcaption>Step 12o</figcaption></figure><h3>Query Visualization</h3><p>For query visualization, rails db can be utilized during any part of the process, for a functioning query.</p><p>While still in rails c, add puts to the beginning of the query and .to_sql to the end of the query (shown below in orange).</p><p>Pressreturn.</p><p>Copy the SQL output (shown below in green).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mi-dRj_lTjEvlwGKWa00Ug.png" /></figure><p>In the terminal, open another tab. Ensure you are located in the project’s directory. Type rails db and press return.</p><p>Paste the copied code.</p><p>Add a semicolon(;) to the end of the pasted code (shown below in orange).</p><p>Press return</p><p>Marvel at your tables. Verify the data is accurate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U4KSl0rr80FZZx6vKsrBYQ.png" /></figure><p><strong>13.</strong> Return to the text editor. For readability purposes, reorganize the code by moving it onto multiple lines and reordering the query to follow conventions (beginning withselect and ending with group and limit).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-lr7Wn-gUel8jgLsVnArw.png" /><figcaption>Step 13</figcaption></figure><p><strong>14.</strong> Refer back to the paper with the query sketched out. Re-read the intent of the query, written at the top. Ensure that item (written in green ink) is a part of the query.</p><p>That’s it!</p><p>Long story short, this guide can be utilized to develop or enhance your process for composing queries, but, in my opinion, what’s most important is customizing a system that works for you. Whatever that system is, stick to it! For instance, I’m religious about always using the same colored ink, for each individual step, but that system works great for me.</p><p><em>This article was written utilizing a system created by </em><a href="https://www.linkedin.com/in/joshmejia/"><em>Josh Mejia</em></a><em>. Thank you Josh!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b61620c8bec3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cookies… Not the Yummy Kind]]></title>
            <link>https://medium.com/@mackenziefrey/cookies-not-the-yummy-kind-320a8e1a504?source=rss-87b90e7ca22b------2</link>
            <guid isPermaLink="false">https://medium.com/p/320a8e1a504</guid>
            <category><![CDATA[rails-5]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[cookies]]></category>
            <dc:creator><![CDATA[Mackenzie Frey]]></dc:creator>
            <pubDate>Wed, 12 Dec 2018 18:13:14 GMT</pubDate>
            <atom:updated>2020-06-08T17:18:16.154Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s talk about Internet Browser Cookies and how that can affect user privacy, in regards to the user’s information being shared with third-party advertisers.</p><p>Before we dig into how to prevent your information from being shared with strangers, let’s talk about what Cookies and Sessions are.</p><h4>What‘s a Cookie?</h4><p>A Cookie is a limited amount of data, stored Client-Side (on the user’s computer), and is browser specific. Cookies are domain specific and contain information pertaining to the current user and their activity on that domain. These Cookies can be utilized to uniquely identify and differentiate the current user from other users frequenting the same web application.</p><p>Some Cookies are stored indefinitely on the user’s computer, while others are set with expiration dates. Some expire when the internet browser window is closed, some expire after a set time period, while others expire after a period of inactivity.</p><h4>What’s a Session?</h4><p>Sessions, like Cookies are packets of data, but Sessions are intended to preserve the user’s state from one experience on the site, to the next, via a unique identification number.</p><p>Sessions can be store on the Client or the Server-Side. In some newer web frameworks (ex. Rails 5.2 +) Sessions are stored Client-Side, which makes the experience faster. Other web frameworks store Sessions on the Server-Side, which has the benefit of expanded data storage, but results in a slower user experience.</p><h4>What’s the difference between a Cookie and a Session?</h4><p>A Cookie has a limited amount of data and is always stored Client-Side. Cookies can be edited by the user, since they are store on their local computer. And although both Sessions and Cookies can be encrypted, but only Sessions are encrypted by default.</p><h4>What would it mean to store a user id in a Cookie?</h4><p>Storing a user id within a Cookie gives the user experience of state transfer from one Session within a specific domain to the next Session on that domain. Cookies are unique to each individual domain and cannot be transferred between domains. In the off event that a Cookie is transferred between domains (this has previously occurred with bugs in older Internet Browsers), the user’s security is breached and the user is at risk of being imitated by a different user.</p><h4>When would we want to use a Session over a Cookie?</h4><p>Sessions are best for storing larger chunks or information.</p><h4><strong>Protecting Oneself from Tracking via Cookies</strong></h4><p>Here is a setting that can be changed on Google Chrome in order to disable third-party cookies (utilized by advertisers to track activity) :</p><p>1. In the top right part of the window select the <em>3 dots (or the orange arrow if Chrome is not up to date)</em>.</p><p>2. Select: <em>Settings</em></p><p>3.<em> </em>In the search bar at the top, type in: <em>cookie</em></p><p>4. Scroll down to the bottom and select: <em>Content Settings</em></p><p>5. Select: <em>Cookies</em></p><p>6. Select: <em>Block third party cookies</em></p><p>7. That’s it!</p><p>To see which websites are currently tracking your activity, select: <em>See all cookies and site data. </em>Some browsers, like Mozilla, have third-party cookies disabled by default. However, for some web browsers, like Google Chrome, third-party cookies are enabled by default, as this would otherwise decrease the revenue of Google Ads.</p><p>Good news! Deleting and blocking these cookies increases user privacy and security by making it more difficult for consumer tracking &amp; advertising firms to directly target their advertising to us. Shucks (:</p><p><em>This article was written utilizing a combination of resources. They are listed below in order of descending favoritism… come on, we all have favorites…</em></p><ul><li><em>This excellent </em><a href="https://www.youtube.com/watch?v=64veb6tKTm0&amp;feature=youtu.be"><em>video by Dave Xiang</em></a><em>.</em></li><li><em>A </em><a href="https://www.youtube.com/watch?v=IPQhME1UYQU&amp;feature=youtu.be"><em>video on cookies</em></a></li><li><em>Another </em><a href="https://www.youtube.com/watch?v=xdH9zsW1CK0&amp;feature=youtu.be"><em>video on cookies</em></a><em>, with a more granular focus.</em></li><li><em>An </em><a href="https://www.opentracker.net/article/third-party-cookies-vs-first-party-cookies"><em>article</em></a><em> on first vs. third-party cookies.</em></li></ul><p><em>This article was written in collaboration with </em><a href="https://medium.com/@marygoodhart"><em>Mary Goodhart</em></a><em> and </em><a href="https://medium.com/@annasmolentzov"><em>Anna Smolentzov</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=320a8e1a504" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>