<?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"><channel><title><![CDATA[Bits, Bytes, and Insights]]></title><description><![CDATA[Bits, Bytes, and Insights]]></description><link>https://hasnode.msjahid.me</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 10:05:02 GMT</lastBuildDate><atom:link href="https://hasnode.msjahid.me/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Running PostgreSQL in Jupyter Notebook
]]></title><description><![CDATA[🐘 PostgreSQL in Jupyter Notebook

A complete setup guide — from conda install to writing SQL queries directly in your notebook.


📦 Step 1 — Install PostgreSQL via Conda
conda install anaconda::post]]></description><link>https://hasnode.msjahid.me/running-postgresql-in-jupyter-notebook</link><guid isPermaLink="true">https://hasnode.msjahid.me/running-postgresql-in-jupyter-notebook</guid><category><![CDATA[SQL]]></category><category><![CDATA[SQL Server]]></category><category><![CDATA[PostgreSQL]]></category><category><![CDATA[Conda ]]></category><category><![CDATA[Jupyter Notebook ]]></category><category><![CDATA[jupyter]]></category><category><![CDATA[sqlalchemy]]></category><category><![CDATA[SQLite]]></category><category><![CDATA[MySQL]]></category><dc:creator><![CDATA[Jahid Hasan]]></dc:creator><pubDate>Mon, 16 Mar 2026 16:47:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/674737ae9826a65f6fd7cc76/d975b10c-80c7-4756-bd27-c9395a15d640.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>🐘 PostgreSQL in Jupyter Notebook</h1>
<blockquote>
<p>A complete setup guide — from <code>conda install</code> to writing SQL queries directly in your notebook.</p>
</blockquote>
<hr />
<h2>📦 Step 1 — Install PostgreSQL via Conda</h2>
<pre><code class="language-bash">conda install anaconda::postgresql
</code></pre>
<blockquote>
<p><strong>Note:</strong> If you have both Anaconda and local Python installed and want to use your local Python, deactivate conda first:</p>
<pre><code class="language-bash">conda deactivate
pip install ipython-sql --break-system-packages
</code></pre>
</blockquote>
<hr />
<h2>🔧 Step 2 — Install Required Python Packages</h2>
<pre><code class="language-bash">pip install ipython-sql
pip install psycopg2
pip install SQLAlchemy
</code></pre>
<hr />
<h2>🚀 Step 3 — Initialize &amp; Start the Server</h2>
<pre><code class="language-bash"># Create the data directory
mkdir ~/pgdata

# If it already exists, remove and recreate
rm -rf ~/pgdata

# Initialize the cluster
initdb -D ~/pgdata

# Start the server
pg_ctl -D ~/pgdata -l ~/pgdata/logfile start
</code></pre>
<p><strong>Port conflict?</strong> If you get <code>pg_ctl: could not start server</code>, your system PostgreSQL is occupying port 5432:</p>
<pre><code class="language-bash"># Stop system postgres
sudo systemctl stop postgresql

# Now start your conda postgres
pg_ctl -D ~/pgdata -l ~/pgdata/logfile start
</code></pre>
<hr />
<h2>👤 Step 4 — Create a User &amp; Database</h2>
<pre><code class="language-bash"># Create a user (prompted for password)
createuser --interactive --pwprompt myuser

# Create a database owned by that user
createdb --owner myuser mydb
</code></pre>
<p>When prompted:</p>
<pre><code>Enter password for new role: ****
Enter it again: ****
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
</code></pre>
<hr />
<h2>🪐 Step 5 — Connect in Jupyter Notebook</h2>
<pre><code class="language-python"># Load the ipython-sql extension
%load_ext sql

# Fix PrettyTable KeyError (version compatibility issue)
%config SqlMagic.style = '_DEPRECATED_DEFAULT'

# Connect to your database
try:
    %sql postgresql://myuser:1234@localhost/mydb
    print("✅ Connected to mydb successfully!")
except Exception as e:
    print(f"❌ Connection failed: {e}")
</code></pre>
<pre><code>✅ Connected to mydb successfully!
</code></pre>
<hr />
<h2>📝 Step 6 — Working with SQL Magic</h2>
<table>
<thead>
<tr>
<th>Magic</th>
<th>Use case</th>
</tr>
</thead>
<tbody><tr>
<td><code>%sql</code></td>
<td>Single-line query</td>
</tr>
<tr>
<td><code>%%sql</code></td>
<td>Multi-line query (entire cell)</td>
</tr>
</tbody></table>
<h3>Check tables</h3>
<pre><code class="language-python">%sql \dt
</code></pre>
<h3>Create a table</h3>
<pre><code class="language-python">%%sql
CREATE TABLE student_info (
    id      SERIAL PRIMARY KEY,
    name    VARCHAR(100),
    cgpa    DECIMAL(3,2)
);
</code></pre>
<h3>Insert values</h3>
<pre><code class="language-python">%%sql
INSERT INTO student_info (name, cgpa) VALUES
    ('Hassan', 4.00),
    ('Zaki',   3.85),
    ('Tina',   3.72),
    ('Sara',   3.90),
    ('John',   3.65);
</code></pre>
<h3>View data</h3>
<pre><code class="language-python">%%sql
SELECT * FROM student_info;
</code></pre>
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>cgpa</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>Hassan</td>
<td>4.00</td>
</tr>
<tr>
<td>2</td>
<td>Zaki</td>
<td>3.85</td>
</tr>
<tr>
<td>3</td>
<td>Tina</td>
<td>3.72</td>
</tr>
<tr>
<td>4</td>
<td>Sara</td>
<td>3.90</td>
</tr>
<tr>
<td>5</td>
<td>John</td>
<td>3.65</td>
</tr>
</tbody></table>
<hr />
<h2>💻 Step 7 — Access from Terminal</h2>
<pre><code class="language-bash"># Using psql
psql -U myuser -d mydb

# Using pgcli (host flag required)
pgcli -U myuser -h localhost -d mydb
</code></pre>
<h3>Useful psql / pgcli commands</h3>
<table>
<thead>
<tr>
<th>Command</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td><code>\l</code></td>
<td>List all databases</td>
</tr>
<tr>
<td><code>\dt</code></td>
<td>List all tables</td>
</tr>
<tr>
<td><code>\d tablename</code></td>
<td>Describe table structure</td>
</tr>
<tr>
<td><code>\c dbname</code></td>
<td>Switch to another database</td>
</tr>
<tr>
<td><code>\q</code></td>
<td>Quit</td>
</tr>
</tbody></table>
<hr />
<h2>♻️ Every Reboot Reminder</h2>
<pre><code class="language-bash"># System postgres may auto-start again after reboot
sudo systemctl stop postgresql

# Start your conda postgres
pg_ctl -D ~/pgdata -l ~/pgdata/logfile start
</code></pre>
<hr />
<h2>🔭 What's Next?</h2>
<p>The same workflow applies to <strong>MySQL / MariaDB</strong>, <strong>SQLite</strong>, and NoSQL databases like <strong>MongoDB</strong> and <strong>Redis</strong> — just swap the connection string and driver. Next post will cover NoSQL databases in Jupyter.</p>
<hr />
<div>

<p>Made by <a href="https://msjahid.me">Hassan</a>  ·  <a href="https://github.com/msjahid">GitHub</a>  ·  <a href="mailto:msjahid.ai@gmail.com">msjahid.ai@gmail.com</a></p>
</div>]]></content:encoded></item><item><title><![CDATA[🌟 ɪɴᴛʀᴏᴅᴜᴄɪɴɢ ᴛʜᴇ ʀᴏꜱᴇ ᴘɪɴᴇ ᴛʜᴇᴍᴇ ꜰᴏʀ ʀ: ᴇɴʜᴀɴᴄɪɴɢ ɢɢᴘʟᴏᴛ2 ᴠɪꜱᴜᴀʟɪᴢᴀᴛɪᴏɴꜱ ᴡɪᴛʜ ᴇʟᴇɢᴀɴᴛ ᴍɪɴɪᴍᴀʟɪꜱᴍ 🌟]]></title><description><![CDATA[🚀 I’m thrilled to present the Rose Pine Theme for R, a custom aesthetic for ggplot2 that blends modern minimalism with the serene elegance of the Rose Pine design philosophy. Drawing inspiration from its Python counterpart, this R-specific implement...]]></description><link>https://hasnode.msjahid.me/2</link><guid isPermaLink="true">https://hasnode.msjahid.me/2</guid><category><![CDATA[R Language]]></category><category><![CDATA[R Programming]]></category><category><![CDATA[R]]></category><category><![CDATA[ggplot2]]></category><category><![CDATA[#RStudio]]></category><category><![CDATA[data visualization]]></category><dc:creator><![CDATA[Jahid Hasan]]></dc:creator><pubDate>Thu, 28 Nov 2024 04:01:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1732765343016/2c87705d-91cb-49e3-8a35-ab7bcd62016e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>🚀 I’m thrilled to present the Rose Pine Theme for R, a custom aesthetic for ggplot2 that blends modern minimalism with the serene elegance of the Rose Pine design philosophy. Drawing inspiration from its Python counterpart, this R-specific implementation has been refined to align with ggplot2’s unique functionality.  </p>
<p>Python Link: [https://lnkd.in/ehjKM3mB  </p>
<p>](https://lnkd.in/ehjKM3mB￼￼🎨)🎨 Key Features<br />Sophisticated Aesthetic: Offers a calm, polished appearance, perfect for professional and academic visualizations.<br />Rich Color Palette: Integrates the signature Rose Pine color scheme, complemented by customizable accent tones to suit diverse datasets.<br />Seamless Integration: Designed to effortlessly fit into standard ggplot2 workflows, saving you time while enhancing your plots.  </p>
<p>📚 How to Use<br />Installing and applying the Rose Pine Theme is straightforward, and the result is a visually striking output tailored for high-impact presentations or publications. Here’s a glimpse of the theme in action, showcasing its versatility across different types of data.  </p>
<p>🔗 <a target="_blank" href="https://lnkd.in/ekTNmS7d"><mark>Documentation and Examples</mark></a>  </p>
<p>Comprehensive documentation, including implementation guidelines, is available in the GitHub Repository. Check it out to explore usage tips and visual examples.[  </p>
<p>](https://lnkd.in/ekTNmS7d￼￼￼💡)💡 Collaborate with Me</p>
<p>Feedback and contributions are highly encouraged! Whether you have suggestions for enhancements or want to contribute directly to the project, feel free to submit a pull request or open an issue on GitHub. Collaboration is the key to growth!  </p>
<p>📩 Get in Touch<br />For any questions, feedback, or collaborative ideas, reach out via my <a target="_blank" href="https://msjahid.me/">portfolio website</a> or connect with me on GitHub.</p>
<p>🔗 GitHub Repository: <a target="_blank" href="https://lnkd.in/eEYU6QR8">Explore the Rose Pine Theme for R</a><a target="_blank" href="https://lnkd.in/eEYU6QR8￼￼￼hashtag#DataVisualization">  
</a></p>
<p><img src="https://raw.githubusercontent.com/msjahid/msjahid.github.io/refs/heads/master/packages/rosepine-markdown/images/Rplot06.png" alt="Beautiful Data Visualization" /></p>
<p><img src="https://raw.githubusercontent.com/msjahid/msjahid.github.io/refs/heads/master/packages/rosepine-markdown/images/polar_plot.png" alt="Polar Plot" /></p>
<p><img src="https://raw.githubusercontent.com/msjahid/msjahid.github.io/refs/heads/master/packages/rosepine-markdown/images/Rplot04.png" alt="Rplot04" /></p>
<p><img src="https://raw.githubusercontent.com/msjahid/msjahid.github.io/refs/heads/master/packages/rosepine-markdown/images/Rplot03.png" alt="Rplot03" /></p>
<p><img src="https://raw.githubusercontent.com/msjahid/msjahid.github.io/refs/heads/master/packages/rosepine-markdown/images/Rplot02.png" alt="Rplot02" /></p>
<p><img src="https://raw.githubusercontent.com/msjahid/msjahid.github.io/refs/heads/master/packages/rosepine-markdown/images/map.png" alt="Map Visualization" /></p>
<p><img src="https://raw.githubusercontent.com/msjahid/msjahid.github.io/refs/heads/master/packages/rosepine-markdown/images/Rplot01.png" alt="Rplot01" /></p>
<p>📌 ᴀʀᴇ ʏᴏᴜ ɪɴᴛᴏ ᴅᴀᴛᴀ ꜱᴄɪᴇɴᴄᴇ, ᴀɴᴀʟʏᴛɪᴄꜱ, ᴏʀ ᴠɪꜱᴜᴀʟɪᴢᴀᴛɪᴏɴ? ʟᴇᴛ’ꜱ ᴄᴏɴɴᴇᴄᴛ—ɪ’ᴅ ʟᴏᴠᴇ ᴛᴏ ᴄʜᴀᴛ ᴍᴏʀᴇ ᴀʙᴏᴜᴛ ɪᴛ!</p>
]]></content:encoded></item></channel></rss>