code for coffeeThe professional website of James Traver
https://code-for-coffee.github.io/
Sat, 04 Feb 2017 18:18:45 +0000Sat, 04 Feb 2017 18:18:45 +0000Jekyll v3.3.1Introduction to Yarn & Offline Node Module Caching<p>You’ve probably heard about the new <em>hawtness</em> that is Yarn. This is a really cool tool that allows Javascript developers to get their work done quickly and solves a few problems that <code class="highlighter-rouge">npm</code> doesn’t. In this tutorial, you’ll be introduced to the Yarn package manager and how to offline cache yuor commonly/favourite node libraries. This tutorial expects that you have experience using the <strong>bash/*nix</strong> command line and have a basic familiarity with <em>git</em>.</p>
<h4 id="goals">Goals</h4>
<ul>
<li>Learn what Yarn is and why it is useful</li>
<li>Understand what a lockfile is</li>
<li>Create a node project using Yarn</li>
<li>Store your commonly used Javascript libraries for offline use</li>
<li>Test offline caching</li>
</ul>
<h2 id="what-is-yarn">What is Yarn?</h2>
<p>Yarn is a Javascript <strong>package manager</strong> similar to <em>npm</em>. It allows you to create a new project, add dependencies, update your dependencies, and more. If you’ve used npm you may wonder why this is a big deal. Yarn can store common node modules offline so you do not need to re-download them over and over again. These can then be centralized in a single repository. Yarn uses <em>lockfiles</em> to save <strong>specific</strong> versions of packages, similar to Ruby’s <code class="highlighter-rouge">Gemfile.lock</code>. A lockfile <em>locks in</em> a specific version of a node module to be used in a project. This means that if I share a project with you and you install packages, you’ll get the <em>exact same</em> versions that I have (which ultimately leads to no headaches due to version differences). The lockfiles are</p>
<blockquote>
<p><em>Fun Fact</em>: Yarn’s <a href="https://yarnpkg.com/">website</a> art was designed by <a href="http://shittywatercolour.com/">Shitty Watercolour</a>.</p>
</blockquote>
<p>In the first part of this tutorial, you are going to create a project that stores your favourite/commonly used node modules. You’ll then upload this project to a Git repository that you can use locally and share with teammates online. Finally, you’ll learn Yarn as you follow along!</p>
<h4 id="creating-an-offline-cache-for-node-modules">Creating an Offline Cache for Node Modules</h4>
<p>Let’s get started by installing Yarn on your system. Mac users: <code class="highlighter-rouge">brew install yarn</code>; Linux users: <code class="highlighter-rouge">apt install yarn</code> or <code class="highlighter-rouge">yum install yarn</code>.</p>
<p>Now, change to your home directory in your terminal: <code class="highlighter-rouge">cd</code> or <code class="highlighter-rouge">cd ~</code>. Inside, <code class="highlighter-rouge">mkdir yarn-offline-cache</code>. This is where Yarn will save node modules for future use. Then, run <code class="highlighter-rouge">yarn config set yarn-offline-mirror ./yarn-offline-cache</code>. This is where the <code class="highlighter-rouge">*.tar.gz</code> files containing your core Javascript libraries will be saved.</p>
<p><img src="img-yarn-offline.png" alt="Yarn Offline Cache in Terminal" /></p>
<p>Inside of your home (<code class="highlighter-rouge">~</code>) directory, a <code class="highlighter-rouge">.yarnrc</code> will be created. Inside, it looks like the following:</p>
<p><img src="img-yarn-yarnrc.png" alt=".yarnrc" /></p>
<p>For <strong>every project that you want to use the offline cache in</strong>, you <em>must</em> have a copy of this <code class="highlighter-rouge">.yarnrc</code> in your directory. I personally add it to boilerplate projects.</p>
<h4 id="your-first-yarn-project">Your First Yarn Project</h4>
<p>Now, create a directory called <code class="highlighter-rouge">yarn-for-cats</code> or <code class="highlighter-rouge">yarn-boilerplate</code>. Change into it and we’ll get started! First, run <code class="highlighter-rouge">yarn init</code>. This will create a new Javascript project using Yarn. You’ll be asked a few questions to initialize your project.</p>
<p><img src="img-yarn-init.png" alt="Yarn Init" /></p>
<blockquote>
<p><em>Note</em>: You can name your project anything you want; these options are up to you!</p>
</blockquote>
<p>Once this is complete, a <code class="highlighter-rouge">package.json</code> will be created (similar to the <code class="highlighter-rouge">npm init</code> process). It will look like this:</p>
<p><img src="img-yarn-packagejson.png" alt="Yarn Init" /></p>
<p>Now, add your favourite dependencies using yarn. To do so, I’ll demonstrate how I add a few things I depend on in my projects. You should add these and/or add your own favourites.</p>
<p><code class="highlighter-rouge">yarn add webpack</code></p>
<p>The syntax basically starts ‘Hey yarn, add webpack as a dependency of my project’. You can also add multiple projects at once.</p>
<p><code class="highlighter-rouge">yarn add webpack-dev-server babel-core babel-loader babel-preset-es2015</code></p>
<p>This will install Webpack, the Webpack development server, Babel, the Webpack loader for Babel, and ES2015 support for Babel. You could also add React, Angular, Ember, Aurelia, Backbone, jQuery, … One of the cool things about yarn is that it will install dependencies asynchronously, unlike npm.</p>
<p>Here are a few commonly used Yarn commands:</p>
<ul>
<li>Starting a new project: <code class="highlighter-rouge">yarn init</code></li>
<li>Adding a dependency: <code class="highlighter-rouge">yarn add [package]</code>, <code class="highlighter-rouge">yarn add [package]@[version]</code>, or <code class="highlighter-rouge">yarn add [package]@[tag]</code></li>
<li>Upgrading a dependency: <code class="highlighter-rouge">yarn upgrade [package]</code>, <code class="highlighter-rouge">yarn upgrade [package]@[version]</code>, or <code class="highlighter-rouge">yarn upgrade [package]@[tag]</code></li>
<li>Removing a dependency: <code class="highlighter-rouge">yarn remove [package]</code></li>
<li>Installing all the dependencies of project: <code class="highlighter-rouge">yarn</code> or <code class="highlighter-rouge">yarn install</code></li>
</ul>
<blockquote>
<p>Yarn has a <a href="https://yarnpkg.com/docs/usage">usage guide for commands</a>. Check it out and bookmark it for future help!</p>
</blockquote>
<p>Now, remember the <code class="highlighter-rouge">.yarnrc</code> in our home folder from earlier? Let’s add a copy of it to our home directory. Change back into your home <code class="highlighter-rouge">~</code> directory and <code class="highlighter-rouge">cp</code> it to your project directory.</p>
<p>Next, you should initialize a Git project in this repository. You can do so by running <code class="highlighter-rouge">git init</code> in your boilerplate’s directory. Then, run <code class="highlighter-rouge">git status</code> to see what is in your project.</p>
<p><img src="img-yarn-git-init.png" alt="Git Status" /></p>
<blockquote>
<p>You can view what this <a href="https://github.com/code-for-coffee/yarn-boilerplate">project looks like</a> on Github.</p>
</blockquote>
<p>Now, let’s install our packages in our project. This may seem redundant but by doing so, we’ll install our packages into our offline cache folder, too! Let’s do that now.</p>
<p><code class="highlighter-rouge">yarn install</code></p>
<p>This command will install all of your packages. If you clone down a javascript project with a <code class="highlighter-rouge">package.json</code>, Yarn will take care of installing all of the dependencies for you.</p>
<p>Navigate back to your <code class="highlighter-rouge">~/yarn-offline-cache</code> directory. Run <code class="highlighter-rouge">ls</code> or <code class="highlighter-rouge">tree</code> to check out what is in your directory! You’ll notice that every dependency that your project relies on is stored in your offline cache project.</p>
<p><img src="img-yarn-offline-cache.png" alt="Offline Cache" /></p>
<blockquote>
<p>You can view my personal <a href="https://github.com/code-for-coffee/yarn-offline-cache">Yarn offline cache’s repository</a> on Github.</p>
</blockquote>
<h4 id="testing-offline-caching">Testing Offline Caching</h4>
<p>Now, if your internet ever goes down you’ll still be able to install packages in other projects so long as the <code class="highlighter-rouge">.yarnrc</code> is in your project’s folder! Isn’t that awesome?! You can also share your <code class="highlighter-rouge">.yarnrc</code> and offline repository with teammates so that everyone is guaranteed to be on the same versions of each library (which helps resolve versioning conflicts). Awesome, eh?</p>
<p>If you’d like to test this, disconnect your internet connection and create a new project. Add your <code class="highlighter-rouge">.yarnrc</code> over to the project.</p>
<p><img src="img-yarn-offline-init.png" alt="Yarn Offline" /></p>
<p>Next, <code class="highlighter-rouge">yarn add</code> a library in your cache. What are the results? I’ll <code class="highlighter-rouge">yarn add react --offline</code> because I added it earlier to my offline cache. It works! Huzzah!</p>
<p><img src="img-yarn-offline-test.png" alt="Yarn Offline Test" /></p>
<h4 id="conclusion">Conclusion</h4>
<p>In conclusion, you’ve learned what Yarn is - a Javascript package manager. You created a node project using Yarn, stored your favourite libraries for offline use, and verified that this actually works when offline. The next time you find yourself without internet in an airport, waiting on a train, or if your ISP goes down, you can still get work done. Even better - you can share your <code class="highlighter-rouge">.yarnrc</code> and offline repositories with co-workers and teammates for other projects to keep your library versions under control. Be sure to check out the <a href="https://yarnpkg.com/docs/getting-started">Yarn Getting Started Guide</a> if you haven’t already.</p>
Sat, 04 Feb 2017 00:00:00 +0000https://code-for-coffee.github.io/intro-to-yarn-and-offline-module-caching
https://code-for-coffee.github.io/intro-to-yarn-and-offline-module-cachingjavascript,yarn,packages,node,nodemodules,modules,yarninit,yarninstall,yarnadd,yarnoffline,offlinemodules,whatisyarn,yarntutorial,yarnintro,yarnaddInstall Ubuntu Bash, Node, Mongodb, and MySQL on Windows 10<p>This is a setup guide use Ubuntu Bash on Windows and Linux binaries for applications (versus native Windows applications). This guide has been tested on 64-bit Windows on Windows 10. We’re going to use the <em>apt</em> package manager to install a few tools. You might remember using <code class="highlighter-rouge">brew</code> to do this in Mac OS X earlier during the cohort. Because each environment and application is different, we have provided a few scripts in this repository to help make life easier. Everyone will need to follow steps one; however, steps two, three, and four may be used as needed.</p>
<blockquote>
<p><strong>Requirements</strong>: Your computer must be running Windows 10 and have a 64-bit processor. The Ubuntu Bash is not available on any prior versions of Windows.</p>
</blockquote>
<p>After completing this installation, note that Bash has a shortcut to to <code class="highlighter-rouge">C:\Windows\System32\bash.exe</code>. This is actually a symlink to <code class="highlighter-rouge">C:\Windows\WinSxS\amd64_microsoft-windows-lxss-bash_31bf3856ad364e35_10.0.14393.351_none_79648c7a5a883c6f\bash.exe</code> - in case you want to change out the terminal in an IDE (such as WebStorm).</p>
<h2 id="outline">Outline</h2>
<ol>
<li>Set Windows to Developer Mode
<ul>
<li>Turn on Developer Mode</li>
<li>Install Bash</li>
<li>Enable Command Line access</li>
<li>Creating a Bash shortcut</li>
</ul>
</li>
<li>Installing Node.js (LTS v6.0)</li>
<li>Installing MongoDB</li>
<li>Installing MySQL</li>
</ol>
<h2 id="set-windows-to-developer-mode">1. Set Windows to Developer Mode</h2>
<h4 id="turn-on-developer-mode">Turn on Developer Mode</h4>
<ul>
<li>Open the <strong>Settings</strong> application. Note: select the Windows 10 settings app, not Control Panel.</li>
<li>Search for <code class="highlighter-rouge">Developer</code> and select <code class="highlighter-rouge">For Developer Settings</code>.</li>
<li>Select ‘Developer Mode’ to enable it and restart if prompted.</li>
</ul>
<h4 id="install-bash">Install Bash</h4>
<p>In Windows, open <strong>Control Panel</strong>. Search for <code class="highlighter-rouge">Windows Features</code> and select <code class="highlighter-rouge">Turn Windows Features On/Off</code>; this may be alternatively found under the Programs and Features category. Next, <em>enable</em> (or verify) that <strong>Windows Subsystem for Linux</strong> is enabled and restart if prompted.</p>
<h4 id="enable-command-line-access">Enable Command Line access</h4>
<p>Open Powershell with Administrative access. You may do this by right-clicking on Powershell and running as administrator. Inside of Powershell’s terminal, run the following command:</p>
<pre><code class="language-ps">Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux`
</code></pre>
<p>You may be prompted to accept a EULA or install additional features. Say <code class="highlighter-rouge">y</code> (yes). You will need to create a Linux user. Linux geeks: these are saved in the same system location as Ubuntu. You’ll need to name your user and add a password. Follow any additional prompts if required. Linux newbies - you won’t be able to see the keys for your password; just hit enter when done.</p>
<h4 id="creating-a-bash-shortcut">Creating a Bash Shortcut</h4>
<p>Next, search for the <strong>Ubuntu Bash</strong> application your computer. Right-click and select <strong>pin to Start</strong> or <strong>create shortcut</strong> on the icon. From here on out, all commands will be ran inside of Ubuntu Bash. Next, we’ll install Git and some essential build tools for Linux.</p>
<div class="highlighter-rouge"><pre class="highlight"><code># update apt's repositories
apt update
# instsall git
apt install git
# install build tools
apt install build-essential
</code></pre>
</div>
<h2 id="installing-nodejs-lts-v60">2. Installing Node.js (LTS v6.0)</h2>
<p>This version of node contains most Javasript 2015 (ES6) features availability directly in Node without the need of transpiling. Node isn’t included with the standard list of applications available in <code class="highlighter-rouge">apt</code>. We’ll need to add it ourselves:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
</code></pre>
</div>
<p>Once completed, we can then install Node by running:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>apt install nodejs
</code></pre>
</div>
<p>You can verify that Node and <em>npm</em> have been installed by running the following commands.</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>npm -v
node -v
</code></pre>
</div>
<p>You should see you node version 6 or higher and npm version 3 or higher.</p>
<h2 id="installing-mongodb-3x">3. Installing MongoDB 3.x</h2>
<p>MongoDB requires that you add a link to their repositories. It is not hosted publically on <code class="highlighter-rouge">apt</code>. First, we’ll grab that repository, add it to <code class="highlighter-rouge">apt</code>, and update <code class="highlighter-rouge">apt</code> so we can install the parts of MySQL that we need. First, create the directories for your MongoDB databases:</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo mkdir /data
sudo mkdir /data/db
</code></pre>
</div>
<p>Now, you’ll need to import the public key used by the package management system from MongoDB.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
</code></pre>
</div>
<p>Next, create a list file for MongoDB:</p>
<div class="highlighter-rouge"><pre class="highlight"><code>echp "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
</code></pre>
</div>
<p>You can now reload local package database to include the MongoDB repositories.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo apt update
</code></pre>
</div>
<p>Finally, you can install MongoDB:</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo apt install mongodb-org
sudo apt install mongodb-org-server
sudo apt install mongodb-org-shell
sudo apt install mongodb-org-mongos
sudo apt install mongodb-org-tools
</code></pre>
</div>
<p>To start your server:</p>
<div class="highlighter-rouge"><pre class="highlight"><code>sudo service mongodb start
</code></pre>
</div>
<p>Alternatively, you can run the <code class="highlighter-rouge">sudo mongod</code> command.</p>
<p>To login to MongoDB, you may do so with <code class="highlighter-rouge">mongo</code>.</p>
<h2 id="installing-mysql">4. Installing MySQL</h2>
<p>MySQL requires that you add a link to Oracle’s repositories. It is not hosted publically on <code class="highlighter-rouge">apt</code>. First, we’ll grab that repository, add it to <code class="highlighter-rouge">apt</code>, and update <code class="highlighter-rouge">apt</code> so we can find MySQL. This guide installs MySQL 5.7.</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="c"># get the MySQL repository information</span>
wget http://dev.mysql.com/get/mysql-apt-config_0.8.0-1_all.deb
<span class="c"># install it</span>
sudo dpkg -i mysql-apt-config_0.8.0-1_all.deb
<span class="c"># you'll be provided a GUI option; select the default options (5.7)</span>
<span class="c"># and exit. this is ok! nothing flashy happens here.</span>
<span class="c"># update apt so it can point to the MySQL repository</span>
sudo apt update
</code></pre>
</div>
<p>Once that is installed, we’ll install MySQL.</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="c"># install a C library that Ruby uses to build the mysql2 gem with</span>
sudo apt install libmysqlclient-dev
<span class="c"># install mysql</span>
sudo apt install mysql-server
</code></pre>
</div>
<p>Once installed, we can control MySQL with the following commands:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="c"># start</span>
sudo service mysql start
<span class="c"># stop</span>
sudo service mysql stop
<span class="c"># info</span>
sudo service mysql status
</code></pre>
</div>
<p>To login to MySQL, you may do so with <code class="highlighter-rouge">mysql -p</code>. <code class="highlighter-rouge">-p</code> specifies that the user is using a password (so it requests you enter one).</p>
<h4 id="sources">Sources</h4>
<ul>
<li>https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-ubuntu/#run-mongodb-community-edition</li>
<li>https://msdn.microsoft.com/commandline/wsl/install_guide</li>
<li>https://msdn.microsoft.com/en-us/commandline/wsl/install_guide</li>
</ul>
Tue, 13 Dec 2016 00:00:00 +0000https://code-for-coffee.github.io/Install-Ubuntu-Bash-Node-MongoDB-MySQL-on-Windows-10
https://code-for-coffee.github.io/Install-Ubuntu-Bash-Node-MongoDB-MySQL-on-Windows-10windows10,bash,ubuntu,install,node,mysql,mongodb,linuxProfessional Speaking 101<p>Have you ever wanted to speak about something but were afraid to? There could have been a variety of reasons for your fear. Perhaps you were not <em>confident</em> in your presentation skills? When you were a new employee somewhere, maybe you didn’t know your <em>audience</em> quite yet? Were you afraid you <em>didn’t know enough</em> to speak up? These are just a sample of excuses that people just like you may use to not speak. In chapter two of The Analects, Confucius wrote “What you know, you know, what you don’t know, you don’t know. This is true wisdom.” In other words - true wisdom comes from knowing what you do and do not know. This article aims to guide you how to speak like the true professional that you are. It also requires for you to be honest with yourself; you’ll need to admit what you do and do not know. You’ll also need to do some hard work.</p>
<p>Let’s begin with a simple <em>assumption</em> that most people would make: because you are in front of the audience, those unfamiliar with your topic are likely to consider you to be an expert. That is a dangerous assumption indeed. Perhaps you’ve avoided speaking on a particular topic that you are incredibly passionate about. Your reasoning is simple: you do not feel like you are an expert on the subject. What if you have just begin learning a topic and want to share it with a group of your peers? You do not need to be a subject matter expert to discuss something. The simplest way to put your mind at ease is to simply <strong>set expectations with your audience</strong>. Explain <em>who you are</em>, <em>why you’re here</em>, <em>what you’re going to talk about</em>, and <em>what your experience with the talk is</em>. As long as a proper set of expectations between you and the audience are followed, there will mutual respect. Ask yourself: do you have the experience to talk about this? If not, will you have enough time to gain that experience between now and your speaking engagement?</p>
<p>What if someone <em>challenges</em> you with a question you don’t have an answer to? Or what if you are unsure? <strong>Be honest</strong>. Better to make light of the situation than to provide an incorrect answer or estimate. The truth is, people in the room can pull out their phone and fact check you within a few seconds. Unless you’re a comedian, there is no reason to lie. When someone provides a <em>challenge</em>, consider it an intellectual challenge. You now must consider your stance based on the perspective, evidence, or argument that someone else has provieded. However, <em>stick to the expectations you set</em>. What about the heckler? If you ever find yourself in the room with one, you should feel comfortable ignoring their input. Given the environment, asking for someone to be escorted out is within your right if they are truely being unruly. However, if someone is heckling you should take a second to consider if your discussion has given then reason to (such as the speaker taking a dominant position, excluding audience members, and more). Sometimes all a joker needs is some recognition and they will become your biggest ally. Truthfully: if you are challenged, can you keep your cool? Consider roleplaying this scenario out with someone before speaking.</p>
<p>Now that we’ve gotten some of the more social aspects of professional speaking out of the way, it is time to discuss the <strong>topic</strong> that you will be presenting to an <strong>audience</strong>. This event could be a conversation during a meeting at work or a presentation at a conference. First, you must know the topic that you will be covering. If you do not know the topic, what will you bring to the discussion? What if you want to lead a discussion for newbies on a topic, that is alright! You’ll still need to know <em>enough to be dangerous</em> about your topic. This means that you’ve <a href="https://medium.com/research-things/just-enough-research-b253a32e8d28#.jldjay3ce">done your research</a> (you should also check out Erika Hall’s <a href="https://abookapart.com/products/just-enough-research">Just Enough Research</a>). You should also be aware of your audience. If you are speaking at an event, look up past panels and topics covered. If you walk in blind - and this will happen at some point in your career - take the lead and use getting to know people as a way to include them (and their ideas) into your conversation, presentation, or lecture. Comedians employ this technique when performing with a live audience and you should to! Can you feel comfortable enough with yourself to engage others and make them part of your dialogue?</p>
<p>It is crucial to plan properly for your presentation. Some discussions will not give you a moment to research or plan. That’s okay - roll with it. However, most of the time you’re going to speak to an audience you’ll have a little bit of prep time. You should give yourself some time to think about how you would approach your subject <em>as if you were a member of your audience</em>. Then, write down how your plan to discuss your topic. Bullet point your ideas out into steps. Formulate these steps into <em>discussion/learning objectives</em>. I recommend trying to find a series of three key themes to a talk that I am about to give. I then break them down into four to six steps which I re-word into <em>objectives</em>. The objectives should be worded with the audience in mind. If we are going to teach children how to brush their teeth, a reasonable objective would be “<em>understand how to brush your molars</em>”. Once you have that information, you can begin preparing a slide deck, notecards, or whatever you will be presenting with. This is going to take time. Do not half ass it; everyone in attendance will know. If you are using a technical gadget to present, try to find out what sort of video input/output they offer (it is embarrassing to show up and not have an HDMI to <em>x</em> adapter and make a crowd wait while one is found). Will you take the actual time to create meaningful resources? Or will your presentation be doomed from the start because you didn’t put enough work into planning?</p>
<p>Finally, you need to put all of this together. That requires taking everything you read, trying to remember it, panicking, and throwing it out of the window. There are going to be mistakes. You’ll have someone give you a hard time. Perhaps you’ll stutter once or twice or one too many ‘uh’s drop from your mouth. That is okay. Professional speaking - just like everything else - requires practice to get better at. After you finish speaking, take a deep breathe and give yourself a moment for a mental pat on the back. Make a quick note of the one thing you wish you could improve next time (perhaps your delivery, objectives, or tone). Make a quick note of one thing that you’re proud of (perhaps you tried a new technique and it worked out). Good job for going out there. It takes courage to speak in front of an audience. As long as you are honest, have some knowledge of the topic, set proper expectations, and know your audience: things will be okay.</p>
Sun, 20 Nov 2016 00:00:00 +0000https://code-for-coffee.github.io/professional-speaking
https://code-for-coffee.github.io/professional-speakingjavascriptEnabling Team Multiplayer in Civilization 6<p>Civilization 6 did not ship with theability to team up during multiplayer. However, various internet searches yielded a few results in luascript files. I’ve decided to document this process and provide screenshots of what to expect. Before you begin, make sure you’ve closed Civilization 6.</p>
<p><img class="responsive-img" src="/images/civ6-team-multiplayer.png" /></p>
<p>First, find where the copy of Civilization was installed to. Here’s a sample Windows path (note: Mac OS users, find the <code class="highlighter-rouge">.app</code> for Civilization and then ctrl/right-click to <code class="highlighter-rouge">View Package Contents</code> to see the internal folder structure): <code class="highlighter-rouge">D:\Steam\steamapps\common\Sid Meier's Civilization VI\</code>. Inside are a set of folders that will contain a script for the multiplayer game staging room: <code class="highlighter-rouge">Base\Assets\UI\FrontEnd\Multiplayer\StagingRoom.lua</code>. Open this file in a plain text editor (Sublime Text, Atom, TextMate, Notepad, ..).</p>
<p>Next, you’ll need to perform a search (or jump to line <strong>1132</strong> as of writing) for the following:</p>
<script src="https://gist.github.com/code-for-coffee/80eda025a0369085ac8c471ba5412457.js"></script>
<p>Finally, edit the boolean value of <code class="highlighter-rouge">playerEntry.TeamPullDown:SetHide(false);</code> to <code class="highlighter-rouge">true</code> and save. That’s it. Restart Civlization 6 and head to the multiplayer lobby.</p>
<p>Some notes:</p>
<ul>
<li>You’ll have teams enabled but the first team started with <code class="highlighter-rouge">0</code>, not <code class="highlighter-rouge">1</code>. This is likely due to array logic.</li>
<li>You can only specify between team <code class="highlighter-rouge">0</code> or team <code class="highlighter-rouge">1</code>.</li>
<li>There is no column header that states you will be selecting a team (see screenshot above).</li>
<li>This <em>should</em> not get you banned from Steam.</li>
<li>This will not make your multiplayer game incompatible with someone who has not made this edit.</li>
<li>Players without this enabled may not know they are teamed if only the host has this modification enabled (we have not tested this).</li>
</ul>
<p>During team game, my friend and I noticed we were able to immediately see each other on the diplomacy screen. The entire game worked fine and we played a good 50-100 turns into our game. However, like the rest of Civilization 6’s gameplay, many features are not unlocked immediately. We noticed that we could declare friendship between our civilizations earlier than expected. However, we had to perform deals to open borders and so forth. We were unable to share our maps, either (though we suspect that would be unlocked in a later era). As of writing, our multiplayer game had just reached the medieval era so there could be a lot left to discover. I’ll update this post if/as we discover more.</p>
Sat, 12 Nov 2016 00:00:00 +0000https://code-for-coffee.github.io/enable-team-multiplayer-civilization-6
https://code-for-coffee.github.io/enable-team-multiplayer-civilization-6Categorizing Exoplanets by Type: Part One - Research<p>It is no secret that I am a space nerd. Over the past few months, I have decided to work on an Exoplanet visualization application (based on an Android application prototype that I had designed). I decided that I wanted to see how many planets of what type have been found by Kepler. The goal is to create a module that will allow users to input a CSV file from the <a href="http://exoplanetarchive.ipac.caltech.edu/cgi-bin/TblView/nph-tblView?app=ExoTbls&amp;config=planets">NASA Exoplanet Archive</a> and then render a list of planets by type. This introduced a few interesting challenges. First, Javascript isn’t <a href="http://stackoverflow.com/questions/11695618/dealing-with-float-precision-in-javascript">very precise with floating point values</a>. Second, how will I convert CSV data from NASA into something usable? Finally, how will I figure out what the planet type even is? Once I solve these questions, I can then take that knowledge and build a library/module/tool. However, before we can start, I needed to perform some research. In the firs part of this series of posts, I will outline my research, conclusion and results.</p>
<h4 id="project-outline">Project Outline</h4>
<p>Our user stories are as follows:</p>
<ul>
<li>A user instantiates our module with a NASA provided CSV file as an argument</li>
<li>A user queries for a list of planets that kepler has detected and is provided an Object</li>
<li>A user queries for an official list of planetary types to view and is provided an Object</li>
<li>A user queries for a list of solar systems and is provided an Object</li>
<li>For any result a user requests, a user may export the results to a prettified JSON file</li>
</ul>
<p>These sounds like pretty reasonable user stories. The module itself is not too complex but serves a single purpose: to allow users to convert NASA Exoplanet data into something usable.</p>
<h4 id="getting-the-nasa-data">Getting the NASA data</h4>
<p>NASA provides most of their data in some format or another. The Exoplanet Archive at CalTech provides a <a href="http://exoplanetarchive.ipac.caltech.edu/cgi-bin/TblView/nph-tblView?app=ExoTbls&amp;config=planets">very nice interface</a>. They have provided a lot of data in this exoplanet table. We are able to speculate the mass of an exoplanet based on transits that it makes between our telescopes and its host star. This mass is usually referred to as a ‘Jupiter Mass’ (or, how many Jupiters it would take to achieve the mass of this planet). However, I needed to filter out superfluous data. Before I could determine what data we’ll need, I needed to figure out how planets are categorized. In 2011, <a href="http://phl.upr.edu/library/notes/amassclassificationforbothsolarandextrasolarplanets">Abel Mendez</a> from the University of Puerto Rico at Arecibo published a paper that provides a scale to classify planets by their mass. However, these masses were in relative earth masses; not relative Jupiter masses.</p>
<p><img class="responsive-img" src="/images/EMC.jpg" /></p>
<p>I decided to structure these as JSON and as a Javascript module for future use.</p>
<script src="https://gist.github.com/code-for-coffee/70d06dc8090d7645e728f5fd786d2774.js"></script>
<p>Thankfully, I can easily convert a Jupiter mass to an Earth mass. I do this by comparing how many Earth mases it would take to fill up Jupiter. According to wikipedia, <a href="Jupiter is equivilent to 317.83 Earth masses">https://en.wikipedia.org/wiki/Jupiter_mass</a>:</p>
<p><em>Convert Jupiter mass to Earth Mass</em></p>
<div class="highlighter-rouge"><pre class="highlight"><code>1 (jupiter mass) input_value
______ = ___________
317.83 (earth mass) output_value
</code></pre>
</div>
<p>In keeping with our user stories, I now know that we can find the planet type and with some math, calculate the available Jupiter mass values that each exoplanet has. I can also check off querying for a list of planet types; I just need to turn that into a data structure. I also need to know which star (or host) that the planet is orbiting around. <a href="http://exoplanetarchive.ipac.caltech.edu/cgi-bin/TblView/nph-tblView?app=ExoTbls&amp;config=planets">Heading back to the exoplanet Archive</a>, I begin to look at each column. I pay attention to a few values that I’ll think will be important: <strong>Row ID</strong>, <strong>Host Name</strong>, <strong>Planet Letter</strong>, <strong>Number of Planets in System</strong>, <strong>Planet Mass (in Jupiter Mass)</strong>. I then <em>select columns</em> and de-select every column but those I mentioned. From there, I select <strong>Download Table</strong>, <em>download currently checked columns</em>, and select <em>download table as CSV</em>.</p>
<p><img class="responsive-img" src="/images/exoplanet_tutorial.png" /></p>
<blockquote>
<p><em>Screenshot of the NASA Exoplanet Archive with Columns Filtered</em></p>
</blockquote>
<p>Awesome! Now I have this wonderful <code class="highlighter-rouge">planets.csv</code> in my downloads folder. Upon inspection, it contains over a thousand rows of precious planets that the human race has discovered. Columns are identified in comments for ease of use/readability (thanks, NASA engineers).</p>
<pre><code class="language-csv"># This file was produced by the NASA Exoplanet Archive http://exoplanetarchive.ipac.caltech.edu
# Wed Nov 2 16:07:55 2016
#
# COLUMN pl_hostname: Host Name
# COLUMN pl_letter: Planet Letter
# COLUMN pl_pnum: Number of Planets in System
# COLUMN pl_orbper: Orbital Period [days]
# COLUMN pl_orbpererr1: Orbital Period Upper Unc. [days]
# COLUMN pl_orbpererr2: Orbital Period Lower Unc. [days]
# COLUMN pl_orbperlim: Orbital Period Limit Flag
# COLUMN pl_bmassj: Planet Mass or M*sin(i)[Jupiter mass]
# COLUMN pl_bmassjerr1: Planet Mass or M*sin(i)Upper Unc. [Jupiter mass]
# COLUMN pl_bmassjerr2: Planet Mass or M*sin(i)Lower Unc. [Jupiter mass]
# COLUMN pl_bmassjlim: Planet Mass or M*sin(i)Limit Flag
# COLUMN pl_radj: Planet Radius [Jupiter radii]
# COLUMN pl_radjerr1: Planet Radius Upper Unc. [Jupiter radii]
# COLUMN pl_radjerr2: Planet Radius Lower Unc. [Jupiter radii]
# COLUMN pl_radjlim: Planet Radius Limit Flag
#
rowid,pl_hostname,pl_letter,pl_pnum,pl_orbper,pl_orbpererr1,pl_orbpererr2,pl_orbperlim,pl_bmassj,pl_bmassjerr1,pl_bmassjerr2,pl_bmassjlim,pl_radj,pl_radjerr1,pl_radjerr2,pl_radjlim
1,11 Com,b,1,326.03000000,0.32000000,-0.32000000,0,19.40000,1.50000,-1.50000,0,,,,
2,11 UMi,b,1,516.22000000,3.25000000,-3.25000000,0,10.50000,2.47000,-2.47000,0,,,,
</code></pre>
<blockquote>
<p><em>Sample CSV file from the Exoplanet Archive</em></p>
</blockquote>
<p>Now, I just need to convert my CSV to a JSON file for ease of use with Javascript. After some research, I found a nice <a href="https://www.npmjs.com/package/csvtojson">npm module</a> called <code class="highlighter-rouge">csvtojson</code>. I decided to give it a whirl. After a bit, I threw together the following class to convert my CSV to JSON.</p>
<script src="https://gist.github.com/code-for-coffee/0793992d6a521b813db3ac1aa373df73.js"></script>
<p>To execute and test my code, I just run <code class="highlighter-rouge">node CSVObjectifier.js</code> in the same directory as my CSV file. When I do, I get some weird results… each object looks mangled.</p>
<div class="language-javascript highlighter-rouge"><pre class="highlight"><code><span class="p">{</span> <span class="s1">'# This file was produced by the NASA Exoplanet Archive http://exoplanetarchive'</span><span class="err">:</span> <span class="p">{</span> <span class="nl">ipac</span><span class="p">:</span> <span class="p">[</span><span class="nb">Object</span><span class="p">]</span> <span class="p">},</span>
<span class="nx">field2</span><span class="err">:</span> <span class="s1">'CoRoT-28'</span><span class="p">,</span>
<span class="nx">field3</span><span class="err">:</span> <span class="s1">'b'</span><span class="p">,</span>
<span class="nx">field4</span><span class="err">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="nx">field5</span><span class="err">:</span> <span class="mf">5.20851</span><span class="p">,</span>
<span class="nx">field6</span><span class="err">:</span> <span class="mf">0.00038</span><span class="p">,</span>
<span class="nx">field7</span><span class="err">:</span> <span class="o">-</span><span class="mf">0.00038</span><span class="p">,</span>
<span class="nx">field8</span><span class="err">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="nx">field9</span><span class="err">:</span> <span class="mf">0.484</span><span class="p">,</span>
<span class="nx">field10</span><span class="err">:</span> <span class="mf">0.087</span><span class="p">,</span>
<span class="nx">field11</span><span class="err">:</span> <span class="o">-</span><span class="mf">0.087</span><span class="p">,</span>
<span class="nx">field12</span><span class="err">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="nx">field13</span><span class="err">:</span> <span class="mf">0.955</span><span class="p">,</span>
<span class="nx">field14</span><span class="err">:</span> <span class="mf">0.066</span><span class="p">,</span>
<span class="nx">field15</span><span class="err">:</span> <span class="o">-</span><span class="mf">0.066</span><span class="p">,</span>
<span class="nx">field16</span><span class="err">:</span> <span class="mi">0</span> <span class="p">},</span>
</code></pre>
</div>
<p>I hypothesize that this is because of the comments at the top of our CSV file (they begin with <code class="highlighter-rouge"># ...</code>). To test this hypothesis, I remove the comments to the point where the first line of my CSV file is <code class="highlighter-rouge">rowid,pl_hostname,pl_letter,pl_pnum,pl_orbper,pl_orbpererr1,pl_orbpererr2,pl_orbperlim,pl_bmassj,...</code> and save file. Upon testing, it appears that my hypothesis was validated: each POJO (plain old Javascript object) looks clean.</p>
<div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="p">{</span> <span class="nl">rowid</span><span class="p">:</span> <span class="mi">100</span><span class="p">,</span>
<span class="nx">pl_hostname</span><span class="err">:</span> <span class="s1">'GJ 163'</span><span class="p">,</span>
<span class="nx">pl_letter</span><span class="err">:</span> <span class="s1">'b'</span><span class="p">,</span>
<span class="nx">pl_pnum</span><span class="err">:</span> <span class="mi">3</span><span class="p">,</span>
<span class="nx">pl_orbper</span><span class="err">:</span> <span class="mf">8.631</span><span class="p">,</span>
<span class="nx">pl_orbpererr1</span><span class="err">:</span> <span class="mf">0.001</span><span class="p">,</span>
<span class="nx">pl_orbpererr2</span><span class="err">:</span> <span class="o">-</span><span class="mf">0.001</span><span class="p">,</span>
<span class="nx">pl_orbperlim</span><span class="err">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="nx">pl_bmassj</span><span class="err">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="nx">pl_bmassjerr1</span><span class="err">:</span> <span class="s1">''</span><span class="p">,</span>
<span class="nx">pl_bmassjerr2</span><span class="err">:</span> <span class="s1">''</span><span class="p">,</span>
<span class="nx">pl_bmassjlim</span><span class="err">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="nx">pl_radj</span><span class="err">:</span> <span class="s1">''</span><span class="p">,</span>
<span class="nx">pl_radjerr1</span><span class="err">:</span> <span class="s1">''</span><span class="p">,</span>
<span class="nx">pl_radjerr2</span><span class="err">:</span> <span class="s1">''</span><span class="p">,</span>
<span class="nx">pl_radjlim</span><span class="err">:</span> <span class="s1">''</span> <span class="p">},</span>
<span class="p">...</span> <span class="mi">3302</span> <span class="nx">more</span> <span class="nx">items</span> <span class="p">]</span>
</code></pre>
</div>
<p>My output file looks like a great starting point for any Node.js (or really, anything) to work with!</p>
<div class="language-json highlighter-rouge"><pre class="highlight"><code><span class="p">[{</span><span class="nt">"rowid"</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span><span class="nt">"pl_hostname"</span><span class="p">:</span><span class="s2">"11 Com"</span><span class="p">,</span><span class="nt">"pl_letter"</span><span class="p">:</span><span class="s2">"b"</span><span class="p">,</span><span class="nt">"pl_pnum"</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span><span class="nt">"pl_orbper"</span><span class="p">:</span><span class="mf">326.03</span><span class="p">,</span><span class="nt">"pl_orbpererr1"</span><span class="p">:</span><span class="mf">0.32</span><span class="p">,</span><span class="nt">"pl_orbpererr2"</span><span class="p">:</span><span class="mf">-0.32</span><span class="p">,</span><span class="nt">"pl_orbperlim"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="nt">"pl_bmassj"</span><span class="p">:</span><span class="mf">19.4</span><span class="p">,</span><span class="nt">"pl_bmassjerr1"</span><span class="p">:</span><span class="mf">1.5</span><span class="p">,</span><span class="nt">"pl_bmassjerr2"</span><span class="p">:</span><span class="mf">-1.5</span><span class="p">,</span><span class="nt">"pl_bmassjlim"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="nt">"pl_radj"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjerr1"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjerr2"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjlim"</span><span class="p">:</span><span class="s2">""</span><span class="p">},{</span><span class="nt">"rowid"</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span><span class="nt">"pl_hostname"</span><span class="p">:</span><span class="s2">"11 UMi"</span><span class="p">,</span><span class="nt">"pl_letter"</span><span class="p">:</span><span class="s2">"b"</span><span class="p">,</span><span class="nt">"pl_pnum"</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span><span class="nt">"pl_orbper"</span><span class="p">:</span><span class="mf">516.22</span><span class="p">,</span><span class="nt">"pl_orbpererr1"</span><span class="p">:</span><span class="mf">3.25</span><span class="p">,</span><span class="nt">"pl_orbpererr2"</span><span class="p">:</span><span class="mf">-3.25</span><span class="p">,</span><span class="nt">"pl_orbperlim"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="nt">"pl_bmassj"</span><span class="p">:</span><span class="mf">10.5</span><span class="p">,</span><span class="nt">"pl_bmassjerr1"</span><span class="p">:</span><span class="mf">2.47</span><span class="p">,</span><span class="nt">"pl_bmassjerr2"</span><span class="p">:</span><span class="mf">-2.47</span><span class="p">,</span><span class="nt">"pl_bmassjlim"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="nt">"pl_radj"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjerr1"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjerr2"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjlim"</span><span class="p">:</span><span class="s2">""</span><span class="p">},{</span><span class="nt">"rowid"</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span><span class="nt">"pl_hostname"</span><span class="p">:</span><span class="s2">"14 And"</span><span class="p">,</span><span class="nt">"pl_letter"</span><span class="p">:</span><span class="s2">"b"</span><span class="p">,</span><span class="nt">"pl_pnum"</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span><span class="nt">"pl_orbper"</span><span class="p">:</span><span class="mf">185.84</span><span class="p">,</span><span class="nt">"pl_orbpererr1"</span><span class="p">:</span><span class="mf">0.23</span><span class="p">,</span><span class="nt">"pl_orbpererr2"</span><span class="p">:</span><span class="mf">-0.23</span><span class="p">,</span><span class="nt">"pl_orbperlim"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="nt">"pl_bmassj"</span><span class="p">:</span><span class="mf">4.8</span><span class="p">,</span><span class="nt">"pl_bmassjerr1"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_bmassjerr2"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_bmassjlim"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="nt">"pl_radj"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjerr1"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjerr2"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjlim"</span><span class="p">:</span><span class="s2">""</span><span class="p">},{</span><span class="nt">"rowid"</span><span class="p">:</span><span class="mi">4</span><span class="p">,</span><span class="nt">"pl_hostname"</span><span class="p">:</span><span class="s2">"14 Her"</span><span class="p">,</span><span class="nt">"pl_letter"</span><span class="p">:</span><span class="s2">"b"</span><span class="p">,</span><span class="nt">"pl_pnum"</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span><span class="nt">"pl_orbper"</span><span class="p">:</span><span class="mf">1773.4</span><span class="p">,</span><span class="nt">"pl_orbpererr1"</span><span class="p">:</span><span class="mf">2.5</span><span class="p">,</span><span class="nt">"pl_orbpererr2"</span><span class="p">:</span><span class="mf">-2.5</span><span class="p">,</span><span class="nt">"pl_orbperlim"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="nt">"pl_bmassj"</span><span class="p">:</span><span class="mf">4.64</span><span class="p">,</span><span class="nt">"pl_bmassjerr1"</span><span class="p">:</span><span class="mf">0.19</span><span class="p">,</span><span class="nt">"pl_bmassjerr2"</span><span class="p">:</span><span class="mf">-0.19</span><span class="p">,</span><span class="nt">"pl_bmassjlim"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="nt">"pl_radj"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjerr1"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjerr2"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjlim"</span><span class="p">:</span><span class="s2">""</span><span class="p">},{</span><span class="nt">"rowid"</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span><span class="nt">"pl_hostname"</span><span class="p">:</span><span class="s2">"16 Cyg B"</span><span class="p">,</span><span class="nt">"pl_letter"</span><span class="p">:</span><span class="s2">"b"</span><span class="p">,</span><span class="nt">"pl_pnum"</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span><span class="nt">"pl_orbper"</span><span class="p">:</span><span class="mf">798.5</span><span class="p">,</span><span class="nt">"pl_orbpererr1"</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span><span class="nt">"pl_orbpererr2"</span><span class="p">:</span><span class="mi">-1</span><span class="p">,</span><span class="nt">"pl_orbperlim"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="nt">"pl_bmassj"</span><span class="p">:</span><span class="mf">1.68</span><span class="p">,</span><span class="nt">"pl_bmassjerr1"</span><span class="p">:</span><span class="mf">0.15</span><span class="p">,</span><span class="nt">"pl_bmassjerr2"</span><span class="p">:</span><span class="mf">-0.15</span><span class="p">,</span><span class="nt">"pl_bmassjlim"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="nt">"pl_radj"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjerr1"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjerr2"</span><span class="p">:</span><span class="s2">""</span><span class="p">,</span><span class="nt">"pl_radjlim"</span><span class="p">:</span><span class="s2">""</span><span class="p">}]</span><span class="w">
</span></code></pre>
</div>
<blockquote>
<p><em>The above JSON output is truncated.</em> View the full JSON file <a href="https://gist.github.com/code-for-coffee/7f085a0c885d6fd3f271f1f8c392c224">on Github</a>.</p>
</blockquote>
<p>Now, I have been able to get the data I need, convert it a bit, and I know I can use it with practically anything now that it is JSON. My object structure even looks pretty!</p>
<h4 id="considering-mathematical-accuracy">Considering Mathematical Accuracy</h4>
<p>Javascript uses 64-bit floating point numbers for the <code class="highlighter-rouge">number</code> type that we use everything with <code class="highlighter-rouge">parseInt()</code> and <code class="highlighter-rouge">parseFloat()</code>. This means that we have an upper limit of a numerical value: <a href="https://en.wikipedia.org/wiki/9223372036854775807">9,223,372,036,854,775,807</a>. Because one of the primary jobs in figuring out a planet’s size requires calculating what appear to be large numbers, we should write a script to see if any numerical values fall beyond this range. We can do so by looping through each object in our JSON. According to the CSV comments, <em>pl_bmassj</em> is our key/column that contains the planet’s mass (see them commented above; I removed them from my CSV for conversion). To test this, I wrote a script that checked each row’s <code class="highlighter-rouge">pl_bmassj</code>.</p>
<script src="https://gist.github.com/code-for-coffee/b8b95ba78579e380db1bb757f3440ced.js"></script>
<p>After running this script, it appears that none of my numbers are too large. This is excellent news (no need to implement a BigDecimal <a href="https://github.com/dtrebbien/BigDecimal.js">style library</a>). However, in my log output I noticed that quite a few rows didn’t have values at all. This is okay; due to <a href="https://en.wikipedia.org/wiki/Methods_of_detecting_exoplanets">our current methods of detecting exoplanets</a>, scientists are not always able to calculate an accurate mass. I should take a note of that and find out how many planets we can categorize vs how many we cannot.</p>
<script src="https://gist.github.com/code-for-coffee/54c8a19218ba4b4fb42314338bf2d296.js"></script>
<p>So about 1/3 of confirmed exoplanets have mass. That data alone is interesting. Given all of the research that I have done so far, I now have a wealth of data and information to sift through. I have found that everything that I need: a way to categorize planets, mass information and the conversions needed, and I have ruled out any need for a large numeric type support in Javascript.</p>
<p>In the next post in this series, I will take this knowledge and put it to use with Node.js. I’ll use the research acquired and begin building out a node module that anyone can use with the intent of putting it online for anyone to use. In the final post of the series, I’ll use the module to render findings on the NASA exoplanet dataset. See you soon!</p>
Wed, 02 Nov 2016 00:00:00 +0000https://code-for-coffee.github.io/How-to-categorize-confirmed-Exoplanet-types
https://code-for-coffee.github.io/How-to-categorize-confirmed-Exoplanet-typesUsing Gulp for ES6/Javascript 2015 Support<p>Wouldn’t it be nice if there was a way to convert ES6 to code every browser can support? Of course! Wouldn’t it be cool if you could include module support from Node in client side code? Certainly. What could do this sort of magic for us? <em>Gulp Tasks</em>!</p>
<h4 id="goals">Goals</h4>
<p>By the end of this tutorial, you will understand:
* What Gulp is and what it can do
* How to install Gulp on your computer
* How to write a Gulp task and run it
* How to add use additional modules with Gulp</p>
<h4 id="introducing-gulp">Introducing: Gulp</h4>
<ul>
<li>Gulp is a software built on Node.</li>
<li>It runs <strong>tasks</strong> that manipulate files on your system.</li>
<li>It is an active, open-source project.</li>
<li>There are many community-built plugins built to work directly with gulp.</li>
<li>It is commonly used for bundling, minificiation, and ES6 support.</li>
<li><strong>Grunt</strong> is a popular alternative to Gulp.</li>
</ul>
<h4 id="installing-gulp">Installing Gulp</h4>
<p>To install <strong>Gulp</strong>, we should have a Node.js environment prepared. If you do not have one, you should visit <a href="Nodejs.org">https://nodejs.org/en/</a> to learn more.</p>
<ol>
<li>You’ll want to install gulp globally. You can do this by running the <code class="highlighter-rouge">npm install gulp -g</code> command.</li>
<li>This states that we want to use <code class="highlighter-rouge">npm</code> to install the <code class="highlighter-rouge">gulp</code> package globally (for any project to use).</li>
<li>Gulp requires that we store our tasks in a <code class="highlighter-rouge">gulpfile.js</code>. This should be in the same directory as your <code class="highlighter-rouge">package.json</code>.</li>
<li>We also need to include gulp in our project. To do that, we will run <code class="highlighter-rouge">npm install gulp --save-dev</code>.</li>
<li>Now, we should run <code class="highlighter-rouge">gulp</code>!</li>
<li>Oh no - we ran into a problem.</li>
</ol>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>Using gulpfile ~/path/to/gulpfile.js
Task <span class="s1">'default'</span> is not <span class="k">in </span>your gulpfile
Please check the documentation <span class="k">for </span>proper gulpfile formatting
</code></pre>
</div>
<p>Let’s solve this problem by defining a Gulp task.</p>
<h4 id="defining-a-gulp-task">Defining a Gulp Task</h4>
<ul>
<li>What is a task?</li>
<li>A task is something we must do to achieve a result.</li>
<li>In Gulp, we create tasks to perform tasks that can transform our code.</li>
<li>A task may perform one job; it may also perform many at once.</li>
</ul>
<p>In our <code class="highlighter-rouge">gulpfile.js</code> we need to include the <code class="highlighter-rouge">gulp</code> module. To do this, we should define a variable: <code class="highlighter-rouge">var gulp = require('gulp');</code> This will allow us to call upon Gulp to <strong>create a task</strong>.</p>
<h5 id="my-first-default-task">My First (Default) Task</h5>
<p>After declaring our <code class="highlighter-rouge">gulp</code> variable, we should create our first task. This will require us to call upon Gulp to define a task. We must also have a name for our task. By <em>default</em>, Gulp requires a <code class="highlighter-rouge">default</code> task. It is the first task that Gulp will look for when reading your <code class="highlighter-rouge">gulpfile.js</code>. Let’s define our first (default) task:</p>
<div class="language-javascript highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">gulp</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'gulp'</span><span class="p">);</span>
<span class="c1">//define a task with the name of 'default' </span>
<span class="c1">// and a callback to perform when the task is ran</span>
<span class="nx">gulp</span><span class="p">.</span><span class="nx">task</span><span class="p">(</span><span class="s1">'default'</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">'I am the default task. Hear me roar'</span><span class="p">);</span>
<span class="p">});</span>
</code></pre>
</div>
<p>(<a href="https://github.com/code-for-coffee/gulp_workflows/blob/master/gulpfile_lo3.js">Source</a>)</p>
<p>In your terminal, run <code class="highlighter-rouge">gulp</code>. This will have the library look for a <code class="highlighter-rouge">default</code> task in your <code class="highlighter-rouge">gulpfile.js</code>. It will then execute the callback that you define for your task. The output will appear as follows:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>Starting <span class="s1">'default'</span>...
I am the default task. Hear me roar
Finished <span class="s1">'default'</span> after 144 μs
</code></pre>
</div>
<h4 id="project-a-gulp-workflow-that-supports-es6-and-modules-for-the-web">Project: A Gulp Workflow that supports ES6 and Modules for the Web</h4>
<p>We’re going to include a few external modules to create a Gulp workflow. Our workflow will support:</p>
<ul>
<li>Node-style <code class="highlighter-rouge">require()</code> statements using <strong>Browserify</strong>.</li>
<li>Support ES6 (ES2016) and JSX (for React.js) using <strong>Babelify</strong> (and a few Babel plugins).</li>
<li>Compile individual modules together using <strong>vinyl-source-stream</strong>.</li>
</ul>
<p>We need to install a variety of modules. The installation commands are:
* <code class="highlighter-rouge">npm install --save-dev browserify</code>
* <code class="highlighter-rouge">npm install --save-dev babelify</code>
* <code class="highlighter-rouge">npm install --save-dev babel-preset-es2015 babel-preset-react</code>
* <code class="highlighter-rouge">npm install --save-dev vinyl-source-stream</code></p>
<p>We can then add our modules to our <code class="highlighter-rouge">gulpfile.js</code>:</p>
<div class="language-javascript highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">gulp</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'gulp'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">browserify</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'browserify'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">babelify</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'babelify'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">source</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'vinyl-source-stream'</span><span class="p">);</span>
</code></pre>
</div>
<p>We’re all set with our dependencies. Now, it is time to create a file structure for our project. We should create a folder called <code class="highlighter-rouge">source</code> for our actual Javascript application. We’ll create an <code class="highlighter-rouge">app.js</code> in that source directory. We should also create a <code class="highlighter-rouge">build</code> folder to contain our final, production-ready Javascript file.</p>
<p><code class="highlighter-rouge">touch source/.gitkeep build/.gitkeep source/app.js</code></p>
<p>You’ll notice that there is currently no file inside of our <code class="highlighter-rouge">build</code> directory other than a <code class="highlighter-rouge">.gitkeep</code>. We should define a task that will use the installed modules to transform our code and make it usable on the front-end. We should update our <code class="highlighter-rouge">gulpfile.js</code>’s <strong>default</strong> task.</p>
<div class="language-javascript highlighter-rouge"><pre class="highlight"><code><span class="nx">gulp</span><span class="p">.</span><span class="nx">task</span><span class="p">(</span><span class="s1">'default'</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">browserify</span><span class="p">(</span><span class="s1">'./source/app.js'</span><span class="p">)</span>
<span class="p">.</span><span class="nx">transform</span><span class="p">(</span><span class="s2">"babelify"</span><span class="p">,</span> <span class="p">{</span><span class="na">presets</span><span class="p">:</span> <span class="p">[</span><span class="s2">"es2015"</span><span class="p">,</span> <span class="s2">"react"</span><span class="p">]})</span>
<span class="p">.</span><span class="nx">bundle</span><span class="p">()</span>
<span class="p">.</span><span class="nx">pipe</span><span class="p">(</span><span class="nx">source</span><span class="p">(</span><span class="s1">'build.js'</span><span class="p">))</span>
<span class="p">.</span><span class="nx">pipe</span><span class="p">(</span><span class="nx">gulp</span><span class="p">.</span><span class="nx">dest</span><span class="p">(</span><span class="s1">'./build/'</span><span class="p">))</span>
<span class="p">});</span>
</code></pre>
</div>
<p>Let’s identify what is going on inside of our <strong>default</strong> task:
* The task uses <strong>browserify</strong> to include our modules that are required in our <code class="highlighter-rouge">source/app.js</code> file.
* It then transforms any ES6 (ES2015) and React JSX templates into usable code on the client side. This usually translates our modern Javascript code into ES5 that most current evergreen browsers support.
* The task then bundles our files together.
* Next, the task creates a file called <code class="highlighter-rouge">build.js</code>.
* Gulp finally places the <code class="highlighter-rouge">build.js</code> inside of a destination (<code class="highlighter-rouge">dest</code>) folder of <code class="highlighter-rouge">build/</code>.
* <a href="https://github.com/code-for-coffee/gulp_workflows/blob/master/gulfpile_lo4.js">The full version of this Gulpfile.js may be found here</a>.</p>
<p>Run <code class="highlighter-rouge">gulp</code> in your terminal. Inspect the <code class="highlighter-rouge">build/build.js</code> file. <em>What do you see?</em></p>
<h5 id="verifying-that-everything-works">Verifying that everything works</h5>
<p>Let’s write some ES6. We’ll then use <strong>gulp</strong> to run tasks that will create a file prepared for the client side. To verify everything works, we can run the script generated in the console.</p>
<p>In my <code class="highlighter-rouge">app.js</code>, I want todefine an ES6 class called HelloWorld. The class should have a toString() method that returns ‘Hello, world!’. I will then instantiate a new instance of the class and console log the <code class="highlighter-rouge">toString()</code> method that it contains.</p>
<div class="language-javascript highlighter-rouge"><pre class="highlight"><code><span class="c1">// define an ES6 class called HelloWorld</span>
<span class="kr">class</span> <span class="nx">HelloWorld</span> <span class="p">{</span>
<span class="c1">// define a toString() method on the class</span>
<span class="nx">toString</span><span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="s1">'Hello, world!'</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="c1">// instantiate a new instance of HelloWorld</span>
<span class="kd">var</span> <span class="nx">sample</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">HelloWorld</span><span class="p">();</span>
<span class="c1">// console.log sample's toString() method</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">sample</span><span class="p">.</span><span class="nx">toString</span><span class="p">());</span>
</code></pre>
</div>
<p>(<a href="https://github.com/code-for-coffee/gulp_workflows/blob/master/app.js">Source</a>)</p>
<p>Now, we should run <code class="highlighter-rouge">gulp</code> in the terminal. Upon completion, open the <code class="highlighter-rouge">build/build.js</code> file. It will contain a large amount of obfuscated code such as <code class="highlighter-rouge">(function e(t,n,r){function s(o,u)....</code>. Copy and paste this code into a browser’s Javascript console. Inside the console, you should see <code class="highlighter-rouge">Hello, world!</code>.</p>
<h5 id="tips-and-tricks">Tips and Tricks</h5>
<ul>
<li>You will need to re-run the <code class="highlighter-rouge">gulp</code> command every time you make a change.</li>
<li>There is <code class="highlighter-rouge">nodemon</code> support for gulp.</li>
<li>You can have <code class="highlighter-rouge">gulp</code> <strong>watch</strong> files for changes using <a href="https://www.npmjs.com/package/gulp-watch">gulp-watch</a>.</li>
</ul>
Mon, 18 Jan 2016 00:00:00 +0000https://code-for-coffee.github.io/using-gulp-for-es6-support
https://code-for-coffee.github.io/using-gulp-for-es6-supportYour first Sinatra web server with Ruby<p>This tutorial is designed to get you up and running with a Sinatra server with as little work as possible. This tutorial assumes that you have a basic knowledge of Ruby. However, it does not assume you know how to use Gems. If you haven’t used Ruby yet, that’s okay! Check out the language at http://tryruby.org. Now, it is time to build your first Sinatra based web server.</p>
<h4 id="introducing-sinatra">Introducing Sinatra</h4>
<p>Sinatra is a web framework. It is designed to listen for user requests and to provide responses. It is lightweight and designed to get to the point. As frameworks go, it is highly modular and built to scale. It is also (arguably) the easiest way to write a server in Ruby. Let’s get started by building a web server in Ruby!</p>
<h4 id="prepwork-with-gemfile">1. Prepwork with Gemfile</h4>
<p>You’ll need Sinatra. Time to install it! <code class="highlighter-rouge">gem install sinatra</code>. Next, you need the JSON gem to send responses back via JSON. This also allows us to call <code class="highlighter-rouge">.to_json</code> on hashes (and other data types such as Arrays). You should <code class="highlighter-rouge">gem install json</code>. Finally, you want Bundler - <code class="highlighter-rouge">gem install bundler</code>! This gem allows us to bundle all of your gems together for your application to use.</p>
<p>You need somewhere to store all of the Gems that your application needs - this will be a plaintext file called <code class="highlighter-rouge">Gemfile</code> (no extension). Gemfiles are where you store information about our application’s libraries (aka, gems). Essentially, the Gemfile allows us to specify what gems we want our application to use.</p>
<p><em>Gemfile</em></p>
<div class="language-ruby highlighter-rouge"><pre class="highlight"><code><span class="n">source</span> <span class="s1">'https://rubygems.org'</span>
<span class="n">gem</span> <span class="s1">'sinatra'</span>
<span class="n">gem</span> <span class="s1">'json'</span>
</code></pre>
</div>
<p>Each time the Gemfile had new Gems added to it, you need to <code class="highlighter-rouge">bundle</code>. Yes, <code class="highlighter-rouge">bundle</code> from terminal in the folder where your app lives. Bundler will then grab all the gems and bundle them together for your app. If you add additional gems, don’t forget to <code class="highlighter-rouge">bundle</code>!</p>
<hr />
<h4 id="configuraiton-with-configru">2. Configuraiton with Config.ru</h4>
<p>You now need a file to tell our application how it should be configured. This tells you what we need to do and what settings your app should use. Since you’re using Sinatra, this will be pretty simple! Create a <code class="highlighter-rouge">config.ru</code> in the same directory as your <code class="highlighter-rouge">Gemfile</code>.</p>
<p><em>config.ru</em></p>
<div class="language-ruby highlighter-rouge"><pre class="highlight"><code><span class="nb">require</span> <span class="s1">'./app'</span>
<span class="n">run</span> <span class="no">Sinatra</span><span class="o">::</span><span class="no">Application</span>
</code></pre>
</div>
<p>What was going on in that file? You required the <code class="highlighter-rouge">app.rb</code> file to be used by using Ruby’s <code class="highlighter-rouge">require</code> statement. This forces a file to be loaded once into our application and run. You then <code class="highlighter-rouge">run Sinatra::Application</code> - or tell Sinatra to start. That’s it!</p>
<h4 id="communicating-with-the-web">3. Communicating with the Web</h4>
<p>Now we’re going to create one more final - our <code class="highlighter-rouge">app.rb</code>. Our final app.rb will look like this.. but we’re going to build it and explain as we go.</p>
<div class="language-ruby highlighter-rouge"><pre class="highlight"><code><span class="nb">require</span> <span class="s1">'bundler'</span>
<span class="no">Bundler</span><span class="p">.</span><span class="nf">require</span><span class="p">()</span>
<span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
<span class="p">{</span><span class="ss">:name</span> <span class="o">=&gt;</span> <span class="s1">'test'</span><span class="p">}.</span><span class="nf">to_json</span>
<span class="k">end</span>
</code></pre>
</div>
<p>First, In your <code class="highlighter-rouge">app.rb</code> file, you now need to to require Bundler. It is what bundles your gems.</p>
<p><em>app.rb</em></p>
<div class="language-ruby highlighter-rouge"><pre class="highlight"><code><span class="nb">require</span> <span class="s1">'bundler'</span>
<span class="no">Bundler</span><span class="p">.</span><span class="nf">require</span><span class="p">()</span>
</code></pre>
</div>
<p>Now, you need to let users access resources on your server. But how will you tell them where to go? Sinatra provides <strong>Routers</strong>. These route the user to http://somedomain.com/route/. Or maybe http://somewhere.com/landing/. You’ll define a root route first to access http://localhost/. If this were on a live server, it could be http://somedomain.com/</p>
<p><em>app.rb</em></p>
<div class="language-ruby highlighter-rouge"><pre class="highlight"><code><span class="nb">require</span> <span class="s1">'bundler'</span>
<span class="no">Bundler</span><span class="p">.</span><span class="nf">require</span><span class="p">()</span>
<span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
<span class="c1"># some code goes here</span>
<span class="k">end</span>
</code></pre>
</div>
<p>Now that you can have a user access a resource via a route. It is time to expose a resource to them! You’ll use the JSON gem here to return a Hash back to a user as JSON.</p>
<p><em>app.rb</em></p>
<div class="language-ruby highlighter-rouge"><pre class="highlight"><code><span class="nb">require</span> <span class="s1">'bundler'</span>
<span class="no">Bundler</span><span class="p">.</span><span class="nf">require</span><span class="p">()</span>
<span class="n">get</span> <span class="s1">'/'</span> <span class="k">do</span>
<span class="p">{</span><span class="ss">:message</span> <span class="o">=&gt;</span> <span class="s1">'hello, world!'</span><span class="p">}.</span><span class="nf">to_json</span>
<span class="k">end</span>
</code></pre>
</div>
<h4 id="did-this-work-lets-run-your-server">4. Did this work? Let’s run your server!</h4>
<p>In terminal, run your app. Did you add any new gems? If so, <code class="highlighter-rouge">bundle</code>! Now, let’s start our server</p>
<blockquote>
<p><em>Note</em> This tells the <strong>Rackup</strong> middleware to run our server.</p>
</blockquote>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>bundle <span class="nb">exec </span>rackup
</code></pre>
</div>
<p>If everything went to plan, you can view your resource. Sinatra listens for requests on port <strong>9292</strong>. Browse to your resource at http://localhost:9292/. Hopefully everything worked out and you’ll see <code class="highlighter-rouge"><span class="p">{</span><span class="nt">"message"</span><span class="p">:</span><span class="s2">"hello, world!"</span><span class="p">}</span></code>.</p>
<h4 id="conclusion">5. Conclusion</h4>
<ul>
<li>You just build a webserver! Congrats! Hopefully this feels awesome and you want to learn more.</li>
</ul>
<blockquote>
<p><strong>Next Steps</strong>: Take a look at the official documentation - http://www.sinatrarb.com/</p>
</blockquote>
Thu, 25 Jun 2015 00:00:00 +0000https://code-for-coffee.github.io/first-sinatra-server
https://code-for-coffee.github.io/first-sinatra-serverTo the stars: Solar Systems beyond our own<blockquote>
<p>Originally Published October, 2014. Last updated 1/28/2016.</p>
</blockquote>
<h4 id="table-of-contents">Table of Contents</h4>
<ul>
<li>Abstract</li>
<li>
<ol>
<li>Introduction</li>
</ol>
</li>
<li>
<ol>
<li>The discovery of new planet types</li>
</ol>
</li>
<li>
<ol>
<li>The composition of other star systems</li>
</ol>
</li>
<li>
<ol>
<li>Planets within their star’s habitable zone and the possibility of liquid water</li>
</ol>
</li>
<li>
<ol>
<li>Conclusion</li>
</ol>
</li>
<li>References</li>
</ul>
<h4 id="abstract">Abstract</h4>
<p>In this essay, we present information about planets found outside of our own solar system. Our research touches on types of planets found, new types of solar system compositions that we have discovered. We also discuss planets that have been found that could contain liquid water. This essay’s aim is to expand upon our current knowledge of extrasolar planets (planets found outside of our solar system). Through space programs such as the Kepler program, we are able to find alien worlds and survey them. In the past two decades alone, scientists have been able to discovery over one hundred planets orbiting other stars.</p>
<h4 id="introduction">1. Introduction</h4>
<p>As the late Carl Sagan (1980) once said, “the surface of the Earth is the shore of the cosmic ocean”. In the past two decades, pioneers in the space sciences community have been looking beyond our own galactic home – to view into other solar systems in a search for other planets. Research suggests that a variety of unfamiliar exoplanet types and solar systems will likely be discovered due to recent discoveries of new planet types, the identification of unexpected planets orbiting unlikely host stars, and newly found planets that orbit in other solar system’s habitable zones. The findings of scientists have been fantastic, once unimaginable planets and solar systems. They have found worlds that orbit closer to their stars than Mercury orbits our own sol. We have found rocky planets larger than any in our own solar system. We have even found possible hope for finding life outside of our solar system by finding planets where liquid water theoretically could exist.</p>
<h4 id="the-discovery-of-new-planet-types">2. The discovery of new planet types</h4>
<p>Scientists have often wondered if planets are common in the universe;. Until the 1980s, our telescopes were not capable of detecting extrasolar planets. Exoplanets – planets that are beyond our solar system – are detected by measuring the light from a remote star. As a planet orbits (transits) around their host star, its gravity “tugs” on the star. Scientists then record stars for a long period of time (months to years) through a telescope. Next, we analyze the data that we record; this allows us to detect repeating gravitational anomalies that a planet exerts on a star. Each time an anomaly is detected it is representative of one orbit.</p>
<p>Our solar system is composed of eight planets – two Jovian gas giants (the gas giants Jupiter and Saturn), four rocky worlds (Mercury, Venus, Earth, and Mars), and two ice giants (Neptune and Uranus). Before we discovered exoplanets scientists were unsure if planets regularly formed around other stars. To our surprise, we have discovered hundreds of planets in just two decades worth of research. We were also unsure of what to results expect; many types of planets were theorized. Based on the results of scanning the night skies, the planets types that we have found are amazing. Scientists have discovered a variety of new planet types in the current sample (which contains 140 known exoplanets).</p>
<p>Out of the planet types we have found in our samples pool, we are starting to find enough that it is possible to begin categorizing them. Klahr. et al (2002) make a statement regarding the new types of planets we have discovered: “with more than 140 exoplanets known to date, some very interesting trends have already drawn attention in the past few years,” (p 132). Based on our observations, we have discovered that there are Chthonian planets (theorized to be the eroded core of gas giants), super Earths (rocky worlds with up to four times the mass of our own Earth), and “hot Jupiters” (gas giants that have a higher surface temperature than Saturn or Jupiter.</p>
<p>So called “Hot Jupiters” (also known as epistellar Jovians) seem to be abundant when searching for exoplanets. This could be attributed to the fact that they have such strong gravity that they remain within close orbit of their parent star. It could also due to a sampling bias – we do not yet have technology that could easily allows for us to find planets further from their parent stars (this should change with the upcoming launch of the James Webb Telescope). Regardless, we have found planets that orbit close enough to their stars that their atmospheres are nearly evaporating. Chthonian planets are theorized to be the remnants of these planets. Cole (2006) points out that data from NASA’s Spitzer Telescope has verified the existence of “hot Jupiters” and that “measurements confirm that each planet is indeed a hot Jupiter with surface temperatures of the order of 1,000 K” (p370).</p>
<p>It is believed that gas giants are common throughout the universe based on the sample data from our experiments. “For now, however, all that can be said is that bloated planets are not that unusual (Bakos, 2007)”. After sorting through our available data, many planets with one and a half times the radius of Earth (or more) appear to become gas giants. Based on our data it is theorized that any planet beyond that range forms into a gas giant. As Weiss et al note, “above 1.5 R (Earth), the average planet density rapidly decreases with increasing radius, indicating that these planets have a large fraction of volatiles (Weiss et al, 2014)”. There is good news for Earth-like planets, however. We have found what we suspect to be a multi-planet system orbiting around the star Gliese 581. Gliese 581d is notable in that as a planet, “Gliese 581d, can be considered the first confirmed exoplanet that could support Earth-like life, according to a team of scientists in France (CNRS, 2011).</p>
<h4 id="the-composition-of-other-star-systems">3. The composition of other star systems</h4>
<p>Many planets have been found orbiting host stars that we did not expect to be capable of containing planets. These solar systems are nothing like our own. Imagine a solar system where the only rocky planetoids orbit enormous gas giants. Our closest galactic neighbor – Alpha Centauri – is a binary star system with an orbiting red dwarf (creating an elongated triad of stars). The system is our closest galactic neighbor, it is still 4.39 light years away. It is hard to imagine how planets would form in such an unstable environment. While our own solar system is neat and organized (all of the planets orbit on near the same elliptical plane in our solar system), others star systems may not be. Extrasolar planetary systems are not mirrors of our own; instead we have found wild, unexpected star systems beyond our home.</p>
<p>With the “recent discovery of a planetary system with five Neptune-mass planets, as well as others including one mass of about 1.4 times that of Earth,” we are now able to fully realize how different alien solar systems are compared to our own (Committee on the Planetary Science Decadal Survey, 2003, p.175). We have found other planets similar in size to Venus and Earth; however they aren’t likely lush, watery worlds like our own planet. Some of them appear to have unstable planetary orbits, others orbit too close to their parent star to support life as we know it. Even though the Alpha Centauri contains “the first planet with a mass similar to Earth ever found around a star like the sun (Dumusque et al, 2012),” don’t get too excited: it is orbiting closer to its own star than Mercury is to our sun!</p>
<p>There are a few star systems that do look like our own. We have found similar planets to our own in configurations similar to our own solar system. Crowell points out it is possible that there are solar systems like ours; in fact “…similar to our own is Epsilon Eridani,” as it contains a Jupiter sized gas giant (Crowell, 2007). Unfortunately, smaller planets are harder to detect around their stars because of the smaller gravitational “tug” that they exert on their parent stars. It is difficult for current generation telescopes to detect planets further away from their stars. This currently limits us to what we can see; there could be entire worlds that we are missing in our surveys of other stars. Based on the small sample size that we have, it is likely that we will still find solar systems that continue to defy our expectations. Consider that “Kepler observed just 0.28 percent of the sky and the telescope was able to peer out to only 3000 light years away, studying less than 5 percent of the stars in its field of view (Becker, 2013)”.</p>
<h4 id="planets-within-their-stars-habitable-zone-and-the-possibility-of-liquid-water">4. Planets within their star’s habitable zone and the possibility of liquid water</h4>
<p>Even when we discover rocky worlds (planets that might be as small as Mercury to planets with 4 times the mass as Earth) they may not have suitable conditions for life as we know it. That life requires liquid water; for liquid water to exist on the surface of a planet, the planet must orbit close enough to the star to maintain liquid water on the surface of the planet. If you look at our own solar system, Mercury and the Moon both have ice in craters that sunlight never reaches that is locked away inside of ice. Mars’ northern ice cap is composed of liquid water (the southern ice cap contains dry ice). Europa and Enceladus – moons of the great Jovian planets in our solar system – have plumes of water jetting from their frozen surfaces into space; water is trapped underneath ice on these worlds and is spraying into space through what could be oceanic vents.</p>
<p>It is easy to classify types of worlds that could be habitable based on the planets found in our own solar system. There are “garden worlds” – worlds capable of maintaining liquid water on their surface at all times (like Earth). Ocean worlds are another possibility – worlds where either surface water freezes and allows for seas below the surface (such as Europa and Enceladus). There are finally barren worlds – worlds that could hold liquid water given certain conditions (and where it is found in ice) like Mars.</p>
<p>In our search for planets in other solar systems, we have found a handful that theoretically could be capable of maintaining liquid water due to their orbits resting within their host star’s habitable zones. First, there are planets like Mars – planets that under the right conditions could host liquid water. They might require a thicker atmosphere, plate tectonics, or even a stable orbit – but it is possible based on our observations that they could harbor liquid water. This is important if we want to find life (or to find a suitable planet to migrate to in the future of our species). We have also found planets that could be similar to our own Earth if geological conditions are right. “The geophysics of GJ581d is unknown, but if a similar mechanism were present there, its atmospheric CO2 would stabilize above the level needed to maintain a liquid water cycle by negative feedback (Wordsworth, 2011)”.</p>
<p>It is also possible that planets may only have a window where they can support liquid water. Perhaps as their star begins to heat up and expand, the planet begins drying up and the water on the world evaporates away. Or perhaps the gravitational tug of another planet displaces it further away from its star, freezing its surface. Based on these possibilities, it is possible that some planets in their habitable zones may have a shorter life span than our own Earth’s for liquid water (and life) to exist. “Compared to larger and more massive CO2-rich planets which may evolve to class II type habitable planets, smaller size planets like Mars cool down faster and water may condense earlier compared to an Earth-size and mass planet (Lammer, 2009)”. Looking at our own solar system, it is theorized that Venus may have once had liquid water (as it is in Sol, our star’s, habitable zone). Some speculate that it evaporated and caused the runaway greenhouse effect that is evident today.</p>
<h4 id="conclusion">5. Conclusion</h4>
<p>In just a few decades, the science community has gone from knowing nothing about extrasolar planets to realizing how abundant planets are in our own galaxy. We have found that there are solar systems that contain more ice giants (like Neptune and Uranus) than our own. We know that there are planets as large as Jupiter orbiting so close to their host stars that their atmospheres are close to evaporating away. We even know that there is a chance that a few planets could support liquid water – a requirement for the only known types of life in the universe. Our research into the unknown has allowed us to find solar systems that are nothing like our own, planets that orbit within their star’s habitable zones, and discovered planet types that we never knew existed. As scientific techniques (and technology) improve over the years to come, we are sure to find even more amazing things in other star systems.</p>
<h4 id="references">References</h4>
<p>Sagan, Carl (1980). Cosmos. Random House. ISBN 978-0-375-50832-5, 2002.</p>
<p>Cole, George H. A. (2006). Wandering Stars: About Planets and Exo-Planets : An
Introductory Notebook. London, GBR: Imperial College Press, 2006.</p>
<p>Klahr, Hubert, Brandner, Wolfgang, Jakosky, Bruce. Planet Formation: Observations, Experiments, and Theory. West Nyack, NY: Cambridge University Press, 2002.</p>
<p>Committee on the Planetary Science Decadal Survey. Vision and Voyages for Planetary Science in the Decade 2013-2022. Washington, DC: National Academies Press, 2003.</p>
<p>CNRS (Délégation Paris Michel-Ange). (2011, May 16). First habitable exoplanet? Climate simulation reveals new candidate that could support Earth-like life. ScienceDaily. Retrieved August 26, 2014 from www.sciencedaily.com/releases/2011/05/110516080124.htm</p>
<p>Dumusque, X., Pepe, F., Lovis, C., Ségransan, D., Sahlmann, J., Benz, W., Bouchy, F., Mayor, M., Queloz, D., Santos, N., Udry, S. (2012, October 17). An Earth-mass planet orbiting α Centauri B. Nature, 491.</p>
<p>Crowell, Lawrence B. Can Star Systems Be Explored? The Physics of Star Probes. River Edge, NJ: World Scientific, 2007.</p>
<p>Weiss, Lauren M. and Marcy, Geoffrey W. The Mass-Radius Relation for 65 Exoplanets Smaller than 4 Earth Radii. The Astrophysics Journal (Feburary 2014).</p>
<p>Becker, Adam (2013, September 25). How Many Earths? New Scientist. Retrieved on February 24th, 2014 from http://exoplanets.newscientistapps.com.</p>
<p>Bakos, G. A. et al (2007). HAT-P-1b: A Large-Radius, Low Density Exoplanet Transiting One Member of a Stellar Binary. The Astrophysical Journal vol. 656.</p>
<p>Wordsworth, Robin D. et al (2011). Gliese 581d is the First Discovered Terrestrial-Mass Exoplanet in the Habitable Zone. The Astrophysical Journal vol 733.</p>
<p>Lammer, H. et al (2009). What makes a planet habitable? Astronomy and Astrophysics Review, vol. 17.</p>
Sun, 26 Oct 2014 00:00:00 +0000https://code-for-coffee.github.io/to-the-stars-solar-systems
https://code-for-coffee.github.io/to-the-stars-solar-systemsReview Visual Studio 2013 Cookbook<p>Visual Studio has made a significant amount of changes in 2010 and 2012; 2013 is no different. Learning all of the new features from version to version isn’t always straightforward. It can also be a daunting task to learn the IDE in and out for new users. <a href="http://www.packtpub.com/visual-studio-2013-cookbook/book">Visual Studio 2013 Cookbook</a> by Jeff Martin and Richard Banks is a great bridge to new users and experienced users alike to the features of Visual Studio’s latest release, 2013. Don’t be fooled by the name - the book also covers ASP.NET MVC5, Windows Store Apps, Async code, and .NET Platform 4.5.1.</p>
<p>I primarily focus on the web development aspect of ASP.NET (MVC, Web API) and this book’s coverage of the platform’s latest technology is great. It covers MVC5 fairly well - from getting started to the base template changes with Bootstrap. It also covers Microsoft’s support for viewing your page in multiple browsers (hooray). There is also a solid introduction to HTML5/CSS3 as well as how to use Javascript Intellisense (yay). There’s also a solid overview of the System.Web.Optimization framework (Bundling and Minification). The introduction to TypeScript is great (mainly because TypeScript is awesome - writing ES6 strictly typed code that compiles into Javascript).</p>
<p>Two chapters that really stood out were the ones that covered how to use the Visual Studio debugger (this is great for new developers) and Team Foundation Server. Knowing how to use the debugging tools in Visual Studio gives you complete insight into bug-fixing and is in my opinion one of the most important tools a developer can have. In regards to the TFS coverage, I’ve used Subversion and Git in the past but recently began to use TFS. The tutorials had me up to speed in no time using TFS (even though I still prefer Git as my choice of source control).</p>
<p>The Windows Store tutorials will get you started on Microsoft’s modern UI in no time; if you’re interested in designing tablet/Windows Phone apps, you’ll be pleasantly surprised. The chapters covering the new platform changes with ASP.NET are solid, also (such as the C# Async code examples). For those of you who develop Python on Windows (or are curious), there is a great introduction to IronPython.</p>
<p>So, here is my verdict: this is the Visual Studio book that I wish I had available when I started programming using Visual Studio. The topics covered are better written than the Microsoft examples, the screenshots and figures are easy to read, and the amount of topics covered introduce you to new concepts and features in the Microsoft ecosystem. It also serves as a nice upgrade guide to users who may be using Web Forms, Windows Forms, and older versions of ASP.NET MVC. If you have recently upgraded from Visual Studio 2010 or older (and even 2012), this book will help you get accustomed to the new tools available to you.</p>
Mon, 28 Jul 2014 00:00:00 +0000https://code-for-coffee.github.io/Review-Visual-Studio-2013-Cookbook
https://code-for-coffee.github.io/Review-Visual-Studio-2013-CookbookBinding parameters to Web API controller with Backbone.js<p>This is a really quick write-up of an issue that isn’t well documented. One of our work related projects uses Backbone.js on the front end to handle models and collections and is powered by ASP.NET Web API 2.0. I ran into an issue regarding using the built in model functions <strong>.save()</strong> and <strong>.fetch()</strong>.</p>
<p>I found that to pass parameters in (either from a model or somewhere else) when making a <strong>GET</strong> request (such as the <strong>model.fetch()</strong> method) to the controller, you needed to declare the model/parameter with the <strong>[FromUri]</strong> attribute. Example:</p>
<pre>public testSampleModel Get([FromUri]testSampleModel model) { ... }</pre>
<p>How to send in a parameter on a <strong>.fetch()</strong>? Good question - here’s the answer (using jQuery):</p>
<pre>myModel.fetch({ data: $.param({ paramName: "foobar"}) });</pre>
<p>To pass parameters/model when making a POST request (such as model.save()), I found that you must declare the model/parameter as either [FromBody] or without an attribute at all. Example:</p>
<pre>public testSampleModel Get([FromBody]testSampleModel model) { ... }</pre>
<p>That’s it - just a quick, informative post.</p>
Tue, 24 Jun 2014 00:00:00 +0000https://code-for-coffee.github.io/Binding-parameters-to-Web-API-controllers-with-Backbone.js
https://code-for-coffee.github.io/Binding-parameters-to-Web-API-controllers-with-Backbone.js