<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sayem Hoque</title>
    <description>The latest articles on DEV Community by Sayem Hoque (@sayemmh).</description>
    <link>https://dev.to/sayemmh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F913000%2Febbc26f6-50fa-44d4-bcf6-62baf96f0db8.jpeg</url>
      <title>DEV Community: Sayem Hoque</title>
      <link>https://dev.to/sayemmh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sayemmh"/>
    <language>en</language>
    <item>
      <title>Setup Django Application Form to send emails to your Gmail Inbox</title>
      <dc:creator>Sayem Hoque</dc:creator>
      <pubDate>Mon, 16 Sep 2024 02:28:39 +0000</pubDate>
      <link>https://dev.to/sayemmh/setup-django-application-form-to-send-emails-to-your-gmail-inbox-133b</link>
      <guid>https://dev.to/sayemmh/setup-django-application-form-to-send-emails-to-your-gmail-inbox-133b</guid>
      <description>&lt;p&gt;For September 2024 none of the guides I found online were up to date and comprehensive for this so just writing the steps to make it work here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://myaccount.google.com/" rel="noopener noreferrer"&gt;https://myaccount.google.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Under "Recent Security Activity" make sure 2FA is on&lt;/li&gt;
&lt;li&gt;Go to the search bar above, and search "App Passwords"&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You'll be prompted as such - "To create a new app specific password, type a name for it below..."&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Name it something like "my-django-site-form"&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It will generate a password you can use in your application. Store this securely somewhere. This can be used in your Django settings, but I opt for saving as an .env variable.&lt;/p&gt;

&lt;p&gt;To test to make sure this setup is working, you can run the following code in the Django shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.core.mail import send_mail
send_mail(
    'Test Email',
    'This is a test email.',
    'sender@email.com',
    ['recipient@example.com'],
    fail_silently=False,
)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the two emails, and you should see an email sent to &lt;a href="mailto:recipient@example.com"&gt;recipient@example.com&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Python One-Liners #1: Create dictionary from csv file</title>
      <dc:creator>Sayem Hoque</dc:creator>
      <pubDate>Wed, 15 Feb 2023 19:30:17 +0000</pubDate>
      <link>https://dev.to/sayemmh/python-one-liners-1-33eg</link>
      <guid>https://dev.to/sayemmh/python-one-liners-1-33eg</guid>
      <description>&lt;p&gt;Turn two columns of any csv file into a dictionary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;col1_col2_map = pd.read_csv("cur.csv", dtype=str)[["col1", "col2"]].set_index("col1").to_dict()["col2"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ai</category>
      <category>chatgpt</category>
    </item>
    <item>
      <title>End to end - host a static site using firebase and a Google domain</title>
      <dc:creator>Sayem Hoque</dc:creator>
      <pubDate>Thu, 09 Feb 2023 01:46:30 +0000</pubDate>
      <link>https://dev.to/sayemmh/end-to-end-host-a-static-site-using-firebase-and-a-google-domain-1k8e</link>
      <guid>https://dev.to/sayemmh/end-to-end-host-a-static-site-using-firebase-and-a-google-domain-1k8e</guid>
      <description>&lt;p&gt;There are a million ways to host a static website. One of my favorites is via firebase hosting, because the spark plan is free and lets you experiment a good amount before you have to pay stacks. I've hosted personal sites, my development agency landing page &lt;a href="https://www.flexbone.dev"&gt;https://www.flexbone.dev&lt;/a&gt;, and my reading highlighter extension page &lt;a href="https://www.readwme.app"&gt;https://www.readwme.app&lt;/a&gt; via this method. &lt;/p&gt;

&lt;p&gt;The only accounts you need are a Firebase account, and a domain you purchased via Google domains. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://firebase.google.com/"&gt;https://firebase.google.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://domains.google.com/"&gt;https://domains.google.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that you have those two, create a new Firebase project with the &lt;code&gt;+ Add project&lt;/code&gt; widget. &lt;/p&gt;

&lt;p&gt;To setup your static site, use any static html website you want to host and put it in a directory on your machine. &lt;code&gt;cd&lt;/code&gt; into that directory and enter the following commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g firebase-tools
firebase login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Log into your firebase account in the web and your terminal should give you a success message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The firebase cli will have you select the project you created in the firebase console above. Choose the project you created before.&lt;/p&gt;

&lt;p&gt;Now your directory should have a &lt;code&gt;firebase.json&lt;/code&gt; as well as a &lt;code&gt;public&lt;/code&gt; directory. Copy your &lt;code&gt;index.html&lt;/code&gt; or your entire static site files into this directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy your website.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your website should be live at &lt;code&gt;something.firebaseapp.com&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Redirect your website to your custom domain
&lt;/h1&gt;

&lt;p&gt;This part always annoys me because it's poorly documented and different hosting domains call the records different names etc. So for firebase hosting and google domains, hopefully this explanation works.&lt;/p&gt;

&lt;p&gt;Open up the console and look at the left side of the screen, you should see a drop down called Build, which has a link to the Hosting section.&lt;/p&gt;

&lt;p&gt;You'll see a dashboard like this below that has the domains associated with your project. Before you add your custom domains, you won't have the two at the bottom here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4QP498hb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6w30pdxdzfuf4wonqi4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4QP498hb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6w30pdxdzfuf4wonqi4.png" alt="Image description" width="880" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add both &lt;a href="http://www.yourgoogledomain.com"&gt;www.yourgoogledomain.com&lt;/a&gt; and yourgoogledomain.com as custom domains in this section of the dashboard. The great part here is if the domain was purchased from google, it should skip through the verify ownership part of the domain and confirm it is yours. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x9ikjGvk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1b0uvlaalj0is2v9kx38.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x9ikjGvk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1b0uvlaalj0is2v9kx38.png" alt="Image description" width="880" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you add a custom domain, you'll see this above. You need to enter this data on the domains site. Go to domains.google.com and go to your domain you added to your firebase project. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click DNS&lt;/li&gt;
&lt;li&gt;Manage custom records&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Create a first record where the values are as follows:&lt;br&gt;
Host name - empty&lt;br&gt;
Type of record - A&lt;br&gt;
TTL - 3600 (default is fine)&lt;br&gt;
Data - The IP address from firebase we saw above. Isn't it annoying that firebase called it "Value" and domains calls it "Data". Enter it here.&lt;/p&gt;

&lt;p&gt;Create a second record that is the exact same as the above, except with the Host name filled in as &lt;code&gt;www&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Host name - www&lt;br&gt;
Type of record - A&lt;br&gt;
TTL - 3600 (default is fine)&lt;br&gt;
Data - Same IP address as above&lt;/p&gt;

&lt;p&gt;Now, when you go back into the dashboard on firebase, your custom domain should have a &lt;code&gt;pending&lt;/code&gt; status. You should be able to navigate to your custom domain and see your site right now, but until the pending goes away, you won't have &lt;code&gt;https://&lt;/code&gt; access, so you'll see an unsecure version of your site. Give it an hour and it should be fine. That's all&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Dot products, cosine similarity, text vectors</title>
      <dc:creator>Sayem Hoque</dc:creator>
      <pubDate>Thu, 20 Oct 2022 22:39:51 +0000</pubDate>
      <link>https://dev.to/sayemmh/dot-products-cosine-similarity-text-vectors-2lo4</link>
      <guid>https://dev.to/sayemmh/dot-products-cosine-similarity-text-vectors-2lo4</guid>
      <description>&lt;p&gt;Cosine similarity is a measure between two single dimensional vectors that gives us a value ranging 0-1 to inform of the similarity between the vectors. The formula is below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cosine Similarity = (A . B) / (||A||.||B||) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where (A . B) is the dot product between vector A and B. A dot product is the sum of the element-by-element product between A and B. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A = [1, 2, 3]
B = [4, 5, 6]


A . B
&amp;gt;&amp;gt; 32
# (1 * 4) + (2 * 5) + (3 * 6) = 32
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Meanwhile, &lt;code&gt;||A||&lt;/code&gt; is the notation used to denote the L2 Norm of a vector. The L2 norm is a method to calculate the length of a vector in Euclidean space. Think of this as the length of a vector of length N as a "line" if the vector was drawn out on a N-dimensional graph. You sum the squares of the values in each dimension, and take the square root of the sum.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A = [1, 2, 3]

norm(A)

&amp;gt;&amp;gt; 3.7416573
# (1^2 + 2^2 + 3^2)^0.5 = 3.7416573
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Numpy has a bunch of helpers so we don't need to run all of these calculations manually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
from numpy.linalg import norm

# define two lists or array
A = np.array([1,2,3,4])
B = np.array([1,2,3,5])

# cosine similarity
cosine = np.dot(A, B) / (norm(A) * norm(B))
print("cosine similarity:", cosine)

&amp;gt;&amp;gt; 0.9939990885479664
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A cosine similarity score near 1 means the vectors are very close to one another if they were projected. 0 means they are very dissimilar.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Descriptive stats + percentiles in numpy and scipy.stats</title>
      <dc:creator>Sayem Hoque</dc:creator>
      <pubDate>Thu, 13 Oct 2022 04:55:51 +0000</pubDate>
      <link>https://dev.to/sayemmh/descriptive-stats-percentiles-in-numpy-and-scipystats-59a7</link>
      <guid>https://dev.to/sayemmh/descriptive-stats-percentiles-in-numpy-and-scipystats-59a7</guid>
      <description>&lt;p&gt;To get the measures of central tendency in a pandas df, we can use the built in functions to calculate mean, median, mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
import numpy as np


# Load the data
df = pd.read_csv("data.csv")

df.mean()
df.median()
df.mode()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To measure dispersion, we can use built-in functions to calculate std. deviation, variance, interquartile range, and skewness.&lt;/p&gt;

&lt;p&gt;A low std. deviation means the data tends to be closer bunched around the mean, and vice versa if the std. deviation is high. The iqr is the difference between the 75th and 25th percentile. To calculate this, scipy.stats is used. Skew refers to how symmetric a distribution is about its' mean. A perfectly symmetric distribution would have equivalent mean, median, and mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from scipy.stats import iqr

df.std()
iqr(df['column1'])
df.skew()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from scipy import stats

stats.percentileofscore([1, 2, 3, 4], 3)
&amp;gt;&amp;gt; 75.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of the percentileofscore function is the percentage of values within a distribution that are equal to or below the target. In this case, [1, 2, 3] are &amp;lt;= to 3, so 3/4 are below.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;numpy.percentile&lt;/code&gt; is actually not the inverse of &lt;code&gt;stats.percentileofscore&lt;/code&gt;. numpy.percentile takes in a parameter q to return the q-th percentile in an array of elements. The function sorts the original array of elements, and computes the difference between the max and minimum element. Once that range is calculated, the percentile is computed by finding the nearest two neighbors q/100 away from the minimum. A list of input functions can be used to control the numerical method applied to interpolate the two nearest neighbors. The default method is linear interpolation, taking the average of the nearest two neighbors.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arr = [0,1,2,3,4,5,6,7,8,9,10]
print("50th percentile of arr : ",
       np.percentile(arr, 50))
print("25th percentile of arr : ",
       np.percentile(arr, 25))
print("75th percentile of arr : ",
       np.percentile(arr, 75))

&amp;gt;&amp;gt;&amp;gt; 50th percentile of arr :  5
&amp;gt;&amp;gt;&amp;gt; 25th percentile of arr :  2.5
&amp;gt;&amp;gt;&amp;gt; 75th percentile of arr :  7.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, using &lt;code&gt;scipy.stats&lt;/code&gt;, we can compute the percentile at which a particular value is within a distribution of values. In this example, we are trying to see the percentile score for &lt;code&gt;cur&lt;/code&gt; within the non-null values in the column &lt;code&gt;ep_30&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;non_nan = features[~features['ep_30'].isnull()]['ep_30']
cur = features['ep_30'][-1]

print(f'''Cur is at the {round(stats.percentileofscore(non_nan, cur, kind='mean'), 2)}th percentile of the distribution.''')

&amp;gt;&amp;gt;&amp;gt; This is at the 7.27th percentile of the distribution.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Transactions in Postgres</title>
      <dc:creator>Sayem Hoque</dc:creator>
      <pubDate>Tue, 30 Aug 2022 23:01:52 +0000</pubDate>
      <link>https://dev.to/sayemmh/transactions-in-postgres-3hlg</link>
      <guid>https://dev.to/sayemmh/transactions-in-postgres-3hlg</guid>
      <description>&lt;p&gt;In databases, a transaction is a single unit of logic -- they can potentially consist of multiple operations. An example is transferring a balance from a bank account to another. The transaction needs an amount removed from the first account and then added to the other. You wouldn't want an amount removed from the account and a program failing and the amount not ever adding to the second account. This is referred to as atomicity in databases. &lt;/p&gt;

&lt;p&gt;In Postgres, implicit to every single statement is the idea that the statement occurs in a transaction. If we write two simple UPDATE statements, they might look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPDATE table1 SET column1 = 100.00
    WHERE id = 3;

UPDATE table1 SET column1 = 100.00
    WHERE id = 4;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, when any statement such as these &lt;code&gt;UPDATE&lt;/code&gt; statements occur, you can think of it happening within a transaction like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BEGIN;
UPDATE table1 SET column1 = 100.00
    WHERE id = 3;
COMMIT;

BEGIN;
UPDATE table1 SET column1 = 100.00
    WHERE id = 4;
COMMIT;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A transaction "block" is the set of queries executed between the &lt;code&gt;BEGIN&lt;/code&gt; and &lt;code&gt;COMMIT&lt;/code&gt; commands. When you don't specify either of these commands, they implicitly surround &lt;em&gt;every&lt;/em&gt; command.&lt;/p&gt;

&lt;p&gt;We can override this default behavior to specify different transaction blocks using the &lt;code&gt;BEGIN&lt;/code&gt; and &lt;code&gt;COMMIT&lt;/code&gt; commands. The idea is that we can perform multiple operations on a database all at once. This is useful for times where if any intermediate operations might fail, we don't want the subsequent commands to execute. The entire "transaction" will not occur.&lt;/p&gt;

&lt;p&gt;Below, you can see here we actually specified a &lt;code&gt;BEGIN&lt;/code&gt; and &lt;code&gt;COMMIT&lt;/code&gt; in this script. As a transaction block now, these two will be "committed" to the database and visible at the same time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BEGIN;
    UPDATE table1 SET column1 = 100.00
        WHERE id = 3;

    UPDATE table1 SET column1 = 50.00
        WHERE id = 4;
COMMIT;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can also be useful if an API or other service happens to request data in between the first and second &lt;code&gt;UPDATE&lt;/code&gt; statement, and we don't want data to be accessed until all of the data is updated. Obviously the latency is really slow for simple &lt;code&gt;UPDATE&lt;/code&gt; statements, but for a longer complicated process, this becomes increasingly important.&lt;/p&gt;

&lt;p&gt;Another example: if a table is dropped but you don't want the table unviewable until it's repopulated completely:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BEGIN;
    CREATE TABLE table2 (
       column1 datatype(length) column_contraint,
       column2 datatype(length) column_contraint,
    );
    // add some data into table2

    DROP table table1;

    SELECT * INTO table1 FROM table2;

COMMIT;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rollbacks
&lt;/h3&gt;

&lt;p&gt;To roll back or undo the change of the last transaction block, you can use the &lt;code&gt;ROLLBACK&lt;/code&gt; command. This can be extremely useful because it might be really difficult to traverse individual statements and figure out how you modified your tables. Wrapping up everything in a transaction block and then rolling back makes it easy to just undo everything that was in the block.&lt;/p&gt;

</description>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>How to use GNU screen to run processes</title>
      <dc:creator>Sayem Hoque</dc:creator>
      <pubDate>Fri, 26 Aug 2022 23:33:00 +0000</pubDate>
      <link>https://dev.to/sayemmh/how-to-use-gnu-screen-to-run-processes-2c8c</link>
      <guid>https://dev.to/sayemmh/how-to-use-gnu-screen-to-run-processes-2c8c</guid>
      <description>&lt;p&gt;Screen is an ancient but still useful software on the GNU operating system that's available on most linux distros and on Macs. &lt;/p&gt;

&lt;p&gt;For example, if you need to SSH to a remote server and need to run a long process that and can't worry about whether the connection will terminate, running the process in a screen will run your process in the background such that even if a connection is lost, it'll keep operating. When you reconnect to the screen, the state of the session will be as-is when you exited.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;screen&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh@SH-MacBook-Pro tutorial % screen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you should see a start message here, which you can just press enter to get past.&lt;/p&gt;

&lt;p&gt;You're now 'attached' to the screen session. To see that you're attached, you can see a list of screens and their statuses by running &lt;code&gt;screen -ls&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh@SH-MacBook-Pro tutorial % screen -ls
There are screens on:
        69475.ttys010.SH-MacBook-Pro      (Attached)
1 Socket in /var/folders/vw/865hm_fd2pj87qtwf_5n329m0000gn/T/.screen.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While you're attached, you can run a script and have it start processing whatever it is that you're doing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh@SH-MacBook-Pro tutorial % python somescript.py
             &amp;gt;&amp;gt; This is some logging being produced by
             &amp;gt;&amp;gt; a script that you're running
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As your process is producing output, instead of hitting &lt;code&gt;Ctrl+c&lt;/code&gt;, you can hit &lt;code&gt;Ctrl + a + d&lt;/code&gt; to "detach" from the screen. The process will keep running in your still-attached screen session. You'll now be back in your normal terminal, and see a log that says you just detached from a screen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[detached]
sh@SH-MacBook-Pro tutorial %
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run &lt;code&gt;screen -ls&lt;/code&gt; again here, you'll see that there is an active screen that you're detached from.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh@SH-MacBook-Pro tutorial % screen -ls
There is a screen on:
    68979.ttys002.SH-MacBook-Pro    (Detached)
1 Socket in /var/folders/vw/865hm_fd2pj87qtwf_5n329m0000gn/T/.screen.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To reconnect to your screen, you can run &lt;code&gt;screen -r&lt;/code&gt;. If you only have one active screen, you can just run &lt;code&gt;screen -r&lt;/code&gt;. If you have multiple active screens to choose from, run &lt;code&gt;screen -r&lt;/code&gt; with the screen id (68979 in this case).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh@SH-MacBook-Pro tutorial % screen -r 68979
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will take you to your screen session that you created before.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh@SH-MacBook-Pro tutorial % python somescript.py
             &amp;gt;&amp;gt; This is some logging being produced by
             &amp;gt;&amp;gt; a script that you're running
             &amp;gt;&amp;gt; More stuff was logged since we last checked
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To exit a screen, &lt;code&gt;Ctrl + d&lt;/code&gt; will exit the session. This kills the current screen session, and you won't be able to re-attach to it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scrolling
&lt;/h3&gt;

&lt;p&gt;Within a screen session, scrolling up the terminal window with the mouse will not work as usual. &lt;/p&gt;

&lt;p&gt;Scroll up a screen you're attached to by entering "scrollback" mode. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Ctrl + a + Escape&lt;/code&gt; will enter you into scrollback mode. Once you're in here, arrow keys will allow you to actually go up the screen log history. Mouse still won't work sorry.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>bash</category>
    </item>
  </channel>
</rss>
