<?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:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[Chris Baily]]></title><description><![CDATA[Autodidact developer focused on single page applications with a full JavaScript stack. Leverages modern patterns and best practices to craft SOLID maintainable software.]]></description><link>http://patterncoder.net/</link><generator>Ghost 0.7</generator><lastBuildDate>Fri, 21 Nov 2025 03:58:35 GMT</lastBuildDate><atom:link href="http://patterncoder.net/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Linux Cheat Sheet]]></title><description><![CDATA[<h3 id="basicdata">Basic Data</h3>

<ul>
<li>Linux kernel version: <code>uname -r</code></li>
<li>Ubuntu version: <code>lsb_release -a</code></li>
</ul>

<h3 id="workingwithfiles">Working with Files</h3>

<ul>
<li>Less: view file one page at a time
<ul><li>Open file and view first page: <code>less [filePath]</code></li>
<li>Navigate by page: Keybrd[PageUp] | Keybrd[PageDwn]</li>
<li>Exit less: Keybrd[q]</li></ul></li>
<li>Vim: view and edit files
<ul><li>enter mode select</li></ul></li></ul>]]></description><link>http://patterncoder.net/linux-cheat-sheet/</link><guid isPermaLink="false">de80bc2e-6c32-48bb-beb6-2b389f0a1618</guid><dc:creator><![CDATA[Christopher Baily]]></dc:creator><pubDate>Sun, 10 Dec 2023 17:37:26 GMT</pubDate><content:encoded><![CDATA[<h3 id="basicdata">Basic Data</h3>

<ul>
<li>Linux kernel version: <code>uname -r</code></li>
<li>Ubuntu version: <code>lsb_release -a</code></li>
</ul>

<h3 id="workingwithfiles">Working with Files</h3>

<ul>
<li>Less: view file one page at a time
<ul><li>Open file and view first page: <code>less [filePath]</code></li>
<li>Navigate by page: Keybrd[PageUp] | Keybrd[PageDwn]</li>
<li>Exit less: Keybrd[q]</li></ul></li>
<li>Vim: view and edit files
<ul><li>enter mode select visually by character: <code>v</code></li>
<li>enter mode select visually by line: <code>V</code></li>
<li>copy selection: <code>y</code></li>
<li>paste at cursor: <code>p</code></li></ul></li>
</ul>

<h3 id="users">Users</h3>

<ul>
<li>list all users: <code>less /etc/passwd</code></li>
<li>switch to different user: <code>su [usernameToSwitchTo]</code></li>
</ul>]]></content:encoded></item><item><title><![CDATA[Ghost Cheatsheet]]></title><description><![CDATA[<h3 id="ghostcli">Ghost CLI</h3>

<ul>
<li>Get ghost version/location/port etc: <code>ghost ls</code></li>
</ul>

<h3 id="restartghost">Restart Ghost</h3>]]></description><link>http://patterncoder.net/ghost-cheatsheet/</link><guid isPermaLink="false">5c88793d-2929-488e-bd3e-39afbd229507</guid><dc:creator><![CDATA[Christopher Baily]]></dc:creator><pubDate>Sun, 10 Dec 2023 17:37:11 GMT</pubDate><content:encoded><![CDATA[<h3 id="ghostcli">Ghost CLI</h3>

<ul>
<li>Get ghost version/location/port etc: <code>ghost ls</code></li>
</ul>

<h3 id="restartghost">Restart Ghost</h3>]]></content:encoded></item><item><title><![CDATA[GIT Cheatsheet]]></title><description><![CDATA[<h3 id="checkout">Checkout</h3>

<ul>
<li><strong>Grab file from another branch:</strong> <code>git checkout [branch-name] -- [file-name]</code></li>
</ul>

<h3 id="tracking">Tracking</h3>

<ul>
<li><strong>Track existing remote branch:</strong> <code>git checkout --track origin/dev</code></li>
<li><strong>Push new branch with tracking:</strong> <code>git push -u origin dev</code></li>
</ul>

<h3 id="undocommits">Undo commits</h3>

<ul>
<li><strong>Undo last commit and put in staging</strong> <code>git reset --soft HEAD~1</code></li>
</ul>

<h3 id="branchactivity">Branch Activity</h3>

<ul>
<li><strong>Branch activity by</strong></li></ul>]]></description><link>http://patterncoder.net/git-cheatsheet/</link><guid isPermaLink="false">670c426e-3a5c-4fa2-897a-e7aa77a0f6c5</guid><dc:creator><![CDATA[Christopher Baily]]></dc:creator><pubDate>Tue, 17 Sep 2019 17:26:28 GMT</pubDate><content:encoded><![CDATA[<h3 id="checkout">Checkout</h3>

<ul>
<li><strong>Grab file from another branch:</strong> <code>git checkout [branch-name] -- [file-name]</code></li>
</ul>

<h3 id="tracking">Tracking</h3>

<ul>
<li><strong>Track existing remote branch:</strong> <code>git checkout --track origin/dev</code></li>
<li><strong>Push new branch with tracking:</strong> <code>git push -u origin dev</code></li>
</ul>

<h3 id="undocommits">Undo commits</h3>

<ul>
<li><strong>Undo last commit and put in staging</strong> <code>git reset --soft HEAD~1</code></li>
</ul>

<h3 id="branchactivity">Branch Activity</h3>

<ul>
<li><strong>Branch activity by date</strong> <code>for k in `git branch | sed s/^..//`; do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k --`\\t"$k";done | sort</code></li>
</ul>

<h3 id="gittagging">Git tagging</h3>

<p>Note: if the tag is part of a build process for versioning, tag locally...push tag to remote...then push branch</p>

<ul>
<li><strong>Create annotated tag</strong> <code>git tag -a v1.0.0 -m "version 1.0.0"</code></li>
<li><strong>Delete a tag</strong> <code>git tag -d v1.0.0</code></li>
<li><strong>Push tag to remote</strong> <code>git push upstream v1.0.0</code></li>
</ul>]]></content:encoded></item><item><title><![CDATA[Docker Cheat Sheet]]></title><description><![CDATA[<h5 id="deletecontainer">Delete Container</h5>

<p>Delete Container <code>docker rm [containerId]</code> <br>
Stop all containers <code>docker stop $(docker ps -a -q)</code> <br>
Delete all containers <code>docker rm $(docker ps -a -q)</code></p>]]></description><link>http://patterncoder.net/docker-cheat-sheet/</link><guid isPermaLink="false">3095f3e3-8691-4c84-9e64-1ead654252bb</guid><dc:creator><![CDATA[Christopher Baily]]></dc:creator><pubDate>Mon, 19 Aug 2019 20:58:52 GMT</pubDate><content:encoded><![CDATA[<h5 id="deletecontainer">Delete Container</h5>

<p>Delete Container <code>docker rm [containerId]</code> <br>
Stop all containers <code>docker stop $(docker ps -a -q)</code> <br>
Delete all containers <code>docker rm $(docker ps -a -q)</code></p>]]></content:encoded></item><item><title><![CDATA[Setting up Digital Ocean Droplet with MongoDb v. 3.4]]></title><description><![CDATA[<h1 id="mongodb34onxenialdigitaloceandroplet">MongoDb 3.4 on Xenial (Digital Ocean Droplet)</h1>

<p>In my spare time I have been developing an application with a free MongoDb instance at MLab.  After getting some more Linux skills in my repetoire I decided I would go for installing on a $5/mo Digital Ocean Droplet.  My goal</p>]]></description><link>http://patterncoder.net/setting-up-digital-ocean-droplet-with-mongodb-v-3-4/</link><guid isPermaLink="false">c138efeb-c4f1-44f0-a789-40afa0d3950f</guid><dc:creator><![CDATA[Christopher Baily]]></dc:creator><pubDate>Sun, 29 Jan 2017 19:56:58 GMT</pubDate><content:encoded><![CDATA[<h1 id="mongodb34onxenialdigitaloceandroplet">MongoDb 3.4 on Xenial (Digital Ocean Droplet)</h1>

<p>In my spare time I have been developing an application with a free MongoDb instance at MLab.  After getting some more Linux skills in my repetoire I decided I would go for installing on a $5/mo Digital Ocean Droplet.  My goal is to spin up the vps, install Mongo and get a simple script in place to backup the db once per day and ship the backup to a remote location.</p>

<hr>

<h2 id="firstdecisions">First Decisions</h2>

<p>My first thought was to install the One Click feature on the Create New Droplet page, however Digital Ocean was offering 3.2 at the time and I wanted to get out in front as far as possible with 3.4.  That made me decide to install a new plain new vps on Xenial (Ubuntu 16.04.1 x32).  I chose the 32 bit version because of my small vps (512 MP/ 1CPU; 20 GB ssd) and a 64 bit version would require more processing power.  </p>

<p>But...guess what...I was wrong!  Mongo required x64 version of Linux.  So I destroyed my droplet and started over with the same specifications as above but selected the x64 Xenial version.</p>

<p>Following the interactive setup on the Digital Ocean site was very easy and took about 2 minutes.  The only thing to note was creating the ssh key...just do the following:</p>

<pre><code>ssh-keygen -t rsa

# and then copy the output of:

cat ~/.ssh/id_rsa.pub  
</code></pre>

<p>Add the cat'ed ssh key to the set up page back on Digital Ocean.  After the vps is installed you can ssh to your machine:</p>

<pre><code>ssh root@your_ip_address  
</code></pre>

<hr>

<h2 id="installingmongodb">Installing MongoDb</h2>

<p>I followed the instructions <a href="https://docs.mongodb.com/master/tutorial/install-mongodb-on-ubuntu/?_ga=1.134923121.1827611328.1485707891">here</a> and below are the commands I used.</p>

<p>First get the key for apt-get  </p>

<pre><code>sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6  
</code></pre>

<p>Add the key to the sources.list  </p>

<pre><code>echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list  
</code></pre>

<p>Update apt-get  </p>

<pre><code>sudo apt-get update  
</code></pre>

<p>Install mongo  </p>

<pre><code>sudo apt-get install -y mongodb-org  
</code></pre>

<p>Start the daemon service  </p>

<pre><code>sudo service mongod start  
</code></pre>

<h2 id="addrootuserformongoandsetupsecurityforremoteaccess">Add root user for mongo and setup security for remote access</h2>

<p>Now that mongo is installed on our vps, we need to allow our application that is hosted elsewhere access to the database(s).  We will modify the default mongo config and add an admin user as well as a database specific user.</p>

<p><strong>Setting Up Root User</strong></p>

<p>First we will set up a root superuser before we lock down the server.  This user will have access to all databases with all privileges.  We will create the user on the admin database and when logging in will authenticate against this database.</p>

<p>Log into mongo:</p>

<pre><code>mongo  
</code></pre>

<p>Run the following commands in the mongo shell: </p>

<pre><code>use admin

db.createUser(  
{
    user: "root",
    pwd: "password",
    roles: [ "root" ]
})
</code></pre>

<p><strong>Setting up security</strong></p>

<p>Got help <a href="https://ianlondon.github.io/blog/mongodb-auth/">here</a> for modifying the mongo config.</p>

<pre><code>sudo vim /etc/mongod.conf  
</code></pre>

<p>We will remove the bindIp from the config to allow access from other IP addresses.  However, when you do this be sure to add the security in the next step.  </p>

<pre><code># network interfaces
net:  
  port: 27017
#  bindIp: 127.0.0.1  &lt;- comment out this line
</code></pre>

<p>Now enable security by uncommenting the security line and adding the authorization enabled line.  </p>

<pre><code>security:  
  authorization: 'enabled'
</code></pre>

<p>Save the changes to the config.</p>

<p><strong>Let's Test</strong></p>

<p>First lets restart the mongo service:</p>

<pre><code>sudo service mongod restart  
</code></pre>

<p>Now try logging in to the mongo client</p>

<pre><code>mongo admin -u root -p  
</code></pre>

<p>This command says login to the admin database with the username of root and prompt me for a password.</p>

<p>Assuming success let's add a new database and a user with much less privileges:</p>

<pre><code>use testDatabase;

db.createUser({user: "dbUsername", pwd: "password", roles: [{role: "readWrite", db: "testDatabase"}]})  
</code></pre>

<p>Logout of mongo and re-login as the newly created user using the password you just created:</p>

<pre><code>mongo testDatabase -u dbUsername -p  
</code></pre>

<hr>

<h2 id="settingupbackupscript">Setting up Backup Script</h2>

<p><strong>Create the Backup</strong></p>

<pre><code>mongodump -d databaseName -o outputDir  
</code></pre>

<p><strong>Restore a Backup</strong></p>

<pre><code>mongorestore pathToBackup  
</code></pre>

<p><strong>Script to Automate Backups</strong></p>

<p>Here is my thought...let's automate the create backup script by executing a cron job once per day.  In this script we can have it keep the last three days of backups.  Here it is:</p>

<pre><code>vim backupMongo  
</code></pre>

<p>Add these commands to the script:</p>

<pre><code>#!/usr/bin/env bash
cp -rf ~/backups/ninjaAPIBackup-1/* ~/backups/ninjaAPIBackup-2  
cp -rf ~/backups/ninjaAPIBackup/* ~/backups/ninjaAPIBackup-1  
rm -rf ~/backups/ninjaAPIBackup  
mongodump -d ninjaAPI -o ~/backups/ninjaAPIBackup -u username -p password  
</code></pre>

<p>We need to make the script executable:</p>

<pre><code>chmod +x backupMongo  
</code></pre>

<p>And let's symlink the file into cron.daily</p>

<pre><code>ln backupMongo /etc/cron.daily/  
</code></pre>]]></content:encoded></item></channel></rss>