<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chris Ramsey on Medium]]></title>
        <description><![CDATA[Stories by Chris Ramsey on Medium]]></description>
        <link>https://medium.com/@chrisramsey?source=rss-7885ed531150------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TD10v_0Sj-3SaPNScRtOBw.jpeg</url>
            <title>Stories by Chris Ramsey on Medium</title>
            <link>https://medium.com/@chrisramsey?source=rss-7885ed531150------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:53:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chrisramsey/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Type-Safety in Redux-Saga with Action Creators]]></title>
            <link>https://medium.com/@chrisramsey/type-safety-in-redux-saga-with-action-creators-398cb39b3a?source=rss-7885ed531150------2</link>
            <guid isPermaLink="false">https://medium.com/p/398cb39b3a</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[redux-saga]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react-redux]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Chris Ramsey]]></dc:creator>
            <pubDate>Fri, 01 Dec 2017 18:54:44 GMT</pubDate>
            <atom:updated>2017-12-01T18:54:44.636Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Disclaimer: I’m going to assume you already have some familiarity with redux-saga for this post.</em></p><p>First of all, I love Typescript. As a Terrible Developer<strong>™</strong> I routinely have syntax errors, forget APIs to modules I’ve written myself, and just generally write bad code. Typescript saves me from most of that pain. Just generally makes things better as a developer.</p><p>Well, recently I encountered a bug (my fault) where I was dispatching the wrong payload into my saga. Sigh.</p><p>See any issues with this code?</p><pre>import { dispatch } from &#39;./myStore&#39;</pre><pre>export interface MyAction {<br>  type: string;<br>  payload: { pageName: string; }</pre><pre>}</pre><pre>function myActionCreator(page: string) {<br>  return { type: &#39;SOMETHING&#39;, payload: { page } }</pre><pre>}</pre><pre>// in some other file<br>import { MyAction } from &#39;./myActionCreators&#39;</pre><pre><br>export function* mySaga(action: MyAction) {<br>  yield call(someClient, { page: action.payload.pageName });</pre><pre>}</pre><p>I’ll wait while you figure it out…</p><p>Ok. This is a dumb one. It’s literally just a collision of naming conventions. in the saga action.payload.pageName doesn’t actually exist, even though it’s in the type. The action creator is publishing a payload with a key of page because somebody got lazy and shortened it and then on top of that, used es6 shorthand to add it to the payload object. (sorry, it was me)</p><p>In normal javascript world this sort of thing would be a pain to track down. But when we catch it in Typescript we can force the action creator to conform to the same interface by adding the return value type. Simple and easy but enforces type safety across action creators and sagas.</p><pre>function myActionCreator(pageName: string): MyAction {<br>  return { type: &#39;SOMETHING&#39;, payload: { pageName } }</pre><pre>}</pre><p>Now, if we forget that the saga wants pageName and try and just shorten it to page we’re gonna get hit with a type mismatch error before the code ever compiles.</p><p>Please note that this is primarily a reminder for myself, but if anyone else gets a little use from it, all the better.</p><p>Got any useful tricks for using redux-saga? Leave a comment!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=398cb39b3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript Sentiment Analysis with Google’s Prediction API]]></title>
            <link>https://medium.com/@chrisramsey/javascript-sentiment-analysis-with-googles-prediction-api-b7d154675216?source=rss-7885ed531150------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7d154675216</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <dc:creator><![CDATA[Chris Ramsey]]></dc:creator>
            <pubDate>Tue, 16 Aug 2016 01:23:42 GMT</pubDate>
            <atom:updated>2016-08-16T01:23:42.433Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*PTx13XaWhUjxCernfCfFOg.jpeg" /><figcaption>How I felt when first playing with the Google Prediction API</figcaption></figure><p>Let me start off by saying I am a complete newb when it comes to machine learning, advanced algorithms, and things of that nature.</p><p>I’m a web developer for Pete’s sake. (Sorry for taking your name in vain Pete.) I don’t do that sort of thing. I make sure my widgets wobble and my gidgets do whatever those do.</p><p>Sure, I do plenty of backend programming, but my heart is in the Javascript world where algorithms and science-y things aren’t as common.</p><p>But I was recently tasked with doing some comparisons between Google’s Prediction API and IBM’s Alchemy APIs for sentiment analysis. Since they both seemed relatively easy to play with, I jumped in head first.</p><p>First, the verdict. With Google’s API I could train my own models (which meant that I could have more contextual results). With Alchemy, I was forced to use their models. Which is fine if you don’t want to do any sort of classification training things.</p><p>In short, because I had the data already, Google’s API was far more accurate. I think I had about an 86% accuracy rating if I recall.</p><p>Anyway, that said, let’s dive into what I did.</p><p>As mentioned, I had my own dataset to work with. It looked like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5997f9bff17a9e3198526caa94bd279f/href">https://medium.com/media/5997f9bff17a9e3198526caa94bd279f/href</a></iframe><p>Just a simple CSV file.</p><p>The first column is the result and the second is what you’re classifying.</p><p>You’re basically saying — <strong>classifierFunction(column[1]) === column[0]</strong></p><p>Keep in mind that the larger the dataset, the better your results. But, as it turns out, the API has limits. I tried to train it on a 1.3 million row file today and it timed out :(</p><p>C’est la vie.</p><p>Once you’ve got your model ready to rock, go install this npm package.</p><p><a href="https://www.npmjs.com/package/google-cloud-prediction-cli">google-cloud-prediction-cli</a></p><p>It’s a little CLI tool I built to make training models simpler.</p><h3><strong>Setting Up Your Model &amp; CLI Tool</strong></h3><p>So, you’ve got your file.</p><p>Next step is to upload your file to Google Cloud Storage.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fthumbs.gfycat.com%2FResponsibleGoodnaturedAmericancicada-mobile.mp4&amp;src_secure=1&amp;url=https%3A%2F%2Fgfycat.com%2FResponsibleGoodnaturedAmericancicada&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FResponsibleGoodnaturedAmericancicada-size_restricted.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=video%2Fmp4&amp;schema=gfycat" width="552" height="966" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cf6c23724276bb6f8556002cbb5eef0/href">https://medium.com/media/7cf6c23724276bb6f8556002cbb5eef0/href</a></iframe><p>Once you’ve gotten to storage, you’ll want to create a bucket and upload the file. No special permissions are required.</p><p>One last step and you can train your model.</p><p>For the CLI tool to work, you need to set an environment variable called GOOGLE_APPLICATION_CREDENTIALS that’s just the path to your Google credentials .json file. You can create one of those when activating the Google Prediction API in your console.</p><p>(In linux/osx, add something like the following to ~/.bash_profile)</p><p>export GOOGLE_APPLICATION_CREDENTIALS=~/.creds/mycredfile.json</p><p>Now you’re ready to rock.</p><h3><strong>Training Your Model</strong></h3><p>I’ll be frank. Google’s APIs are the pits. The docs are incomplete and figuring out what to pass to the methods in their SDK is not intuitive in the least.</p><p>So, let the CLI tool do the heavy lifting for you.</p><p>Once you’ve set everything up, just run the following to train your model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3368b7506d2c284b424ff4992fb955a7/href">https://medium.com/media/3368b7506d2c284b424ff4992fb955a7/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FUnrealisticPlasticFairybluebird&amp;url=https%3A%2F%2Fgfycat.com%2FUnrealisticPlasticFairybluebird&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FUnrealisticPlasticFairybluebird-size_restricted.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=gfycat" width="1332" height="240" frameborder="0" scrolling="no"><a href="https://medium.com/media/91d7e090ebfb90d4a6d278643c100b70/href">https://medium.com/media/91d7e090ebfb90d4a6d278643c100b70/href</a></iframe><p>This uses four flags.</p><ol><li>insert<br>This tells the tool you’re wanting to — well — insert and train a new model</li><li>project<br>This is the project name in Google Cloud</li><li>model-id<br>This is what you’re naming the model. Make it easy to remember.</li><li>model<br>This is a path to the file you uploaded earlier. It’s the bucket + the filename.</li></ol><p>Once you’ve inserted it, you can view the status of the training at any time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6daa96aa953152e72db2f9056e3a80c/href">https://medium.com/media/e6daa96aa953152e72db2f9056e3a80c/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FGlassWanAfghanhound&amp;url=https%3A%2F%2Fgfycat.com%2FGlassWanAfghanhound&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FGlassWanAfghanhound-size_restricted.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=gfycat" width="1332" height="210" frameborder="0" scrolling="no"><a href="https://medium.com/media/47740725346ddb2d4b6cb95d64ed84d9/href">https://medium.com/media/47740725346ddb2d4b6cb95d64ed84d9/href</a></iframe><p>That’s it! Now you’ve got a trained model that you can use to predict classifications with.</p><p>Let’s use it for sentiment analysis now.</p><p>Let’s imagine we have a tweet we want to analyze to see if it’s actionable.</p><p>We’re going to need to make a request to the Google Prediction API and provide them with our model data and the text we want to use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22f55f1dd29b495f318a5b023f0aa810/href">https://medium.com/media/22f55f1dd29b495f318a5b023f0aa810/href</a></iframe><p>If you’re fancy like me, you’ll stuff the nasty callbacks here into promises, but I think this will give you the idea of what’s going on.</p><p>And that’s it! Note that your results will live in the ‘outputLabel’ property on the res object.</p><p>They don’t really make that clear, but that’s where your results are.</p><p>Doing machine learning with cloud services like these is pretty damn easy. Thanks Google!</p><p>Also to note, I’m considering adding functionality for the last bit into the CLI tool. I just haven’t gotten around to that yet. If anyone wants to contribute to making it better, feel free to toss in a pull request and we can be on our way!</p><p>Thanks for reading and leave a comment if you’ve got any feedback or questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7d154675216" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I love Typescript for large applications]]></title>
            <link>https://medium.com/@chrisramsey/why-i-love-typescript-for-large-applications-aaf8c18575a3?source=rss-7885ed531150------2</link>
            <guid isPermaLink="false">https://medium.com/p/aaf8c18575a3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Chris Ramsey]]></dc:creator>
            <pubDate>Mon, 25 Jan 2016 22:33:05 GMT</pubDate>
            <atom:updated>2016-01-25T22:33:05.311Z</atom:updated>
            <content:encoded><![CDATA[<p>Let me start with an admission. I’m not a very smart guy.</p><p>I look back at code I wrote even six months ago and I’m ashamed. I feel bad for anyone else who has to look at my monstrosities.</p><p>Ok, maybe I exaggerate a little. But the point is, as much as I enjoy writing javascript, my brain can’t hold all the points of connection between functions for very long.</p><p>So when I finally ‘got’ Typescript, my view completely changed.</p><p>Over the last few years I’d tried to use Typescript for various projects, but it never really panned out. Sure, static typing was cool and all, but what good was it for me?</p><p>I was primarily working on smaller projects and never ran into the horror that is managing a ton of state over a long period of time.</p><p>That is, until I began work at HelpSocial about a year and a half ago.</p><p>HelpSocial is a cool tool. It helps customer support agents handle customer support issues just as well as they can over the phone, by chat, or email — but on social media.</p><p>It gives our users context to who they’re talking to, what sort of issues they might have had in the past, and how they might better be able to help them today.</p><p>The trouble is, that’s a lot of data to deal with. When you’re looking at 10k+ tweets in a day for a single customer, you’re going to run into issues with managing your state.</p><p>What’s worse, is when you’ve got a ton of really groovy features that all deal with that state, things can get mangled pretty quickly.</p><p>When I first started here, HelpSocial was still created as an internal tool for RackSpace. So it was my responsibility to take that tool and turn it into something that other companies could use too.</p><p>One of the things it really had going for it though was how it was built on a completely open API. I like to say to our customers, ‘If you really wanted to, you could use our API to build a clone of our front end.’</p><p>But that’s still only one piece of the puzzle. Our users sit on our application all day long. Most web applications don’t get that kind of usage. And that’s given us a really unique perspective on the user’s experience with the tool.</p><p>Bugs aren’t just an annoyance with this kind of application. They’ll stop a user in their tracks and keep them from doing the job they were hired for. As you can guess, that’s kind of a problem.</p><p>It became a recurring trend in those first months of putting out fires all over the place. That is, until we bit the bullet and decided to start using Typescript in our application.</p><p>Once we really started adding type checks into a compile time process (literally just adding a new task to our GulpFile to integrate Typescript) things started changing.</p><p>With a real compilation stage, I’d find potential bugs before they ever got into production. Typos on variable names have become a thing of the past. I know what kind of data will be passed into a function before it’s ever run.</p><p>And most importantly, I’ve rooted out almost all our runtime exceptions due to using, say, an array function on an object. That kind of error just doesn’t happen very often anymore.</p><p>At this point, if there are bugs, it’s usually due to some kind of logic mistake rather than just me missing a keystroke or forgetting what kind of variable I’m looking at.</p><p>Let’s look at a quick example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffd032024a5bba6d6f2146b5a9d6c2fe/href">https://medium.com/media/ffd032024a5bba6d6f2146b5a9d6c2fe/href</a></iframe><p>Here you’ll see a module, Validators (another great feature of TS) and a subclass named Activity. That’s just a normal ES6 class.</p><p>Anyway, you can see the types right in line there. IActivity is an `interface` created in a `something.d.ts` file. It’s essentially just a file that lists your type specifications.</p><p>Since `hasNotes` specifies that is returns a boolean, the usage somewhere else needs to reflect that, otherwise you get an error when compiling to plain old javascript.</p><p>And that’s where the beauty of all this comes in. With a strongly typed language like Haskell or C#, you have this sort of thing built in from the beginning.</p><p>Not so with Javascript. It’s really easy to start getting mixed up once your codebase reaches any significant size.</p><p>And in those cases using a tool like Typescript really makes your life as a developer easier.</p><p>Not having to deal with runtime exceptions because I was dumb and made a simple mistake makes my job lightyears easier. I can see what kind of trouble I can get myself into before ever running the code live in the browser or running unit tests.</p><p>There’s a lot of other great features with Typescript, but the types alone are worth making the switch if you’ve got a big project you manage.</p><p>But the best part about that is how easy it is to start. You don’t have to refactor your entire codebase. If you don’t add types, it’ll compile without any checks. Simple as that.</p><p>So you can start with a single file and a single function, then add types as you refactor and fix bugs elsewhere. That’s how we did it, and if you’re using Typescript in an existing project, that’s how I recommend you do it too.</p><p>Well there it is. That’s why we love Typescript at Helpsocial. Now, I’d love to hear why you do (or don’t) love Typescript in the comments section. So leave your thoughts and let’s get a discussion going.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aaf8c18575a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to connect Meteor.js to an external API]]></title>
            <link>https://medium.com/meteor-js/how-to-connect-meteor-js-to-an-external-api-93c0d856433b?source=rss-7885ed531150------2</link>
            <guid isPermaLink="false">https://medium.com/p/93c0d856433b</guid>
            <category><![CDATA[meteor]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Chris Ramsey]]></dc:creator>
            <pubDate>Mon, 15 Jun 2015 20:49:44 GMT</pubDate>
            <atom:updated>2018-03-20T03:48:12.932Z</atom:updated>
            <content:encoded><![CDATA[<p></p><h3>How to connect Meteor.js to an external API</h3><p>During the day I work for a great company, HelpSocial.com, and one of our biggest draws is our API.</p><p>The API is a great source of social data and meta-data related to the users posting.</p><p>Simple use case…</p><p>You run a company and have a Twitter account. A customer tweets you and says, “I broke my widget! WAAAH!”.</p><p>You tweet back and replace the widget.</p><p>Then a week later the same user messages you again saying they broke another widget.</p><p>Using the HelpSocial API you can not only know WHEN those tweets come in, but you also get context like what you’ve done with this customer in the past.</p><p>Social customer service agents instantly know what they need to know without having to do any back and forth with other employees.</p><p>Everything is right in their face.</p><p>Anyway, I say all this because as a developer I’m always experimenting with cool new things. And lately I’ve gotten hooked on Meteor.</p><p>So, I decided to figure out how to connect to external APIs thinking it would be a cool exercise to connect to our API for some kind of Meteor app.</p><p>I ended up coming across one <a href="http://meteorcapture.com/publishing-data-from-an-external-api/">very helpful article from Dave Burles</a>.</p><p>And <a href="https://github.com/cwramsey/redditreader">this is my implementation</a> of it.</p><p>In this project, I wanted to create a very simple tool that connected to Reddit and read the front page of a subreddit (basically a forum on a specific topic).</p><p>Firstly, I break up my Meteor projects into what are essentially ‘packages’ on the client and server end.</p><p>You can see my directory structure here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64988c00f1825a2a848213fc3f1020ce/href">https://medium.com/media/64988c00f1825a2a848213fc3f1020ce/href</a></iframe><p>In ./client/templates you’ll see /Posts.</p><p>This holds both the template and JS surrounding a ‘post’ item.</p><p>Each post on Reddit ends up being a ‘post’ in this app.</p><p>In ./server/packages/ you’ll see /RedditReader/RedditReader.js</p><p>This is a script that connects to Reddit, loads a JSON response, and shoves it into a collection to be read and displayed in the DOM.</p><p>Let’s take a look at these components.</p><h3>Connecting To An External Data Source</h3><p>You likely know how to connect to a Mongo collection already. This is pretty similar.</p><p>You’ll still be using the subscribe/publish system. You just won’t be using Mongo as your data source.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48fafdcf0c0c09889b84ef31fe90dc57/href">https://medium.com/media/48fafdcf0c0c09889b84ef31fe90dc57/href</a></iframe><p>This is pretty simple. First we’re publishing something called a ‘subredditSearch’ that we can subscribe to on the front end.</p><p>Once we’ve published, we’re using the HTTP module to grab data from Reddit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbeda382f95bf2cc890abc78f78644a3/href">https://medium.com/media/dbeda382f95bf2cc890abc78f78644a3/href</a></iframe><p>We’re not using any kind of auth, so we don’t need to use any OAuth libraries or require username/passwords to be inserted. One day I’ll update this project to include actual Reddit integration, but that’s not today.</p><p>Next, we’re iterating over each item we get back in JSON using the Underscore library.</p><p>If you haven’t used Underscore before, check it out. It’s a fantastic utility library.</p><p>Anyway, here’s that code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e75fa84d65431b695b930445d01b8935/href">https://medium.com/media/e75fa84d65431b695b930445d01b8935/href</a></iframe><p>Simply, what we’re doing is stripping out the data we actually want and adding each item to a collection we create elsewhere called ‘posts’.</p><p>There’s some other logic in here, but it’s specific to this use case, so it’s not important. Just know that you need to add your object to your collection that you’re creating in just a bit.</p><p>You can also ignore my Meteor.methods at the end of the first gist earlier. That is also specific to this case.</p><h3>Displaying Your Data</h3><p>Take a look at this mess.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f4f6e4e82d8c41f6e80581053f7414e/href">https://medium.com/media/2f4f6e4e82d8c41f6e80581053f7414e/href</a></iframe><p>Ok, it’s not actually that messy.</p><p>Anyway, let’s dive in.</p><p>The first thing we need to do is set some variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/637788df1d9ddeeb579bab516133457e/href">https://medium.com/media/637788df1d9ddeeb579bab516133457e/href</a></iframe><p>We create a global variable called Posts that we can access later on and set some default variables.</p><p>‘subreddit’ is set to ‘all’ for /r/all and ‘searching’ is set to false, since we’re not loading anything the second the app loads (Well, we are, but it hasn’t happened yet as far as the code goes)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be69dd0ae5524e373f7a0037f83281b3/href">https://medium.com/media/be69dd0ae5524e373f7a0037f83281b3/href</a></iframe><p>Now we’re adding in our tracker. We’re subscribing to our model that we published earlier and getting the initial bit of data from Reddit.</p><p>After this comes our events. Most of this isn’t important to you. You’ll have your own DOM events.</p><p>But there is one awesome thing I want to mention.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b266ba03cb0ead4c6e72efd235d83d4/href">https://medium.com/media/5b266ba03cb0ead4c6e72efd235d83d4/href</a></iframe><p>Blaze.getData is very, very cool.</p><p>Blaze, Meteor’s templating engine, keeps a record of every DOM element it creates and the data associated with it.</p><p>So if we plug in a DOM element, we can get the model data that is used to create it. How cool and amazingly useful is that!</p><p>You can see how I’m using it to get the data from a click event above.</p><p>The rest is pretty standard Meteor.</p><p>You’ve got your templates, you’ve got your handlers, and you’ve got your utility methods.</p><p>In short, that is how you connect to an API and extract it’s data into a Meteor collection for use in a reactive template.</p><p>And lastly, if you need someone with years of experience in the ever-changing world of Javscript to lend a hand or simply some advice, send an email to cwramsey (at-sign) gmail (dot) com and we can talk. I’m currently only open for small gigs, so I book up quickly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93c0d856433b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/meteor-js/how-to-connect-meteor-js-to-an-external-api-93c0d856433b">How to connect Meteor.js to an external API</a> was originally published in <a href="https://medium.com/meteor-js">Meteor Hammer</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Meal Calendar Made In Meteor]]></title>
            <link>https://medium.com/meteor-js/a-meal-calendar-made-in-meteor-13612234b33c?source=rss-7885ed531150------2</link>
            <guid isPermaLink="false">https://medium.com/p/13612234b33c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[meteorjs]]></category>
            <category><![CDATA[meteor]]></category>
            <dc:creator><![CDATA[Chris Ramsey]]></dc:creator>
            <pubDate>Mon, 15 Jun 2015 17:50:38 GMT</pubDate>
            <atom:updated>2015-06-15T17:50:38.310Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been on the lookout for a simple way to create rich SPA’s for a long time.</p><p>During the day I work on a very cool web app, HelpSocial.com with a strong PHP backend, but I’ve really liked the idea of using both the same language on the front and back ends.</p><p>I’ve worked at building APIs with node. Toyed with Ruby on Rails. Experimented with Ember. And fooled around with Angular, just to name a few…</p><p>And they all felt, ‘lacking’.</p><p>I don’t know. Something just felt off about the whole process. Not to mention Ember left me crying in the corner like a little girl. (But let’s not share that with anyone)</p><p>Well, yesterday I finally bit the bullet and tried out Meteor.</p><p>By George, I was hooked in the first 5 minutes.</p><p>In absolutely no time I was up and running with a simple web app that was controlled on both the front and back end via Javascript. Plus deploying to a simple server (kinda like Heroku’s free plan) was done in a single command.</p><p>You just can’t beat the simplicity yet underlying strength of the system.</p><p>Anyway, in maybe an hour and a half I built my first app in Meteor.</p><p>And <a href="http://foodcal.meteor.com/">here it is</a> in all it’s glory. And <a href="https://github.com/cwramsey/foodcal">here it is on Github</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*ZVMskLQ0PkoAhAzc.png" /></figure><p>Quick shout out for the <a href="https://fezvrasta.github.io/bootstrap-material-design/">Bootstrap Material Theme</a>. It’s great for knocking out quick and pretty UIs.</p><p>Anyway, the goal here is to create a simple app that let’s you figure out a simple meal plan for X days.</p><p>In the future I plan on adding lunch/dinner, but let’s just assume it’s for dinner right now.</p><p>So let’s get started. Run this in your terminal.</p><blockquote><em>meteor create FoodCal &amp;&amp; cd FoodCal &amp;&amp; meteor</em></blockquote><p>This will go ahead and start your media server.</p><p>For this project we’re going to use the standard meteor structure that’s created by default.</p><p>In future posts we’ll use a better client/server structure, but this is fine since this is a small project.</p><h3>The HTML &amp; Template</h3><p>To start, here’s the HTML we’ll be using for this project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e394ad2531ba48be1843110025416898/href">https://medium.com/media/e394ad2531ba48be1843110025416898/href</a></iframe><p>There’s a few things you’ll notice in here.</p><p>1. The {{#each}} statement.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02d09b6c1d465c16182b37ff879a809c/href">https://medium.com/media/02d09b6c1d465c16182b37ff879a809c/href</a></iframe><p>In the Javascript we’ll be creating a collection called ‘meals’ and subscribing to it.</p><p>Here is where we’ll be printing them out. This handlebar-esque block will automatically handle updating the DOM when the collection changes. So freakin’ cool.</p><p>2. The template tag at the bottom</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fe569239eef1edcc7c2606aecf0eb90/href">https://medium.com/media/5fe569239eef1edcc7c2606aecf0eb90/href</a></iframe><p>This is <a href="http://www.html5rocks.com/en/tutorials/webcomponents/template/">a special (and kinda new) HTML tag</a> that’s going to be inserted in the aforementioned {{#each}} block.</p><p>So, for each entry in the meals collection you’ll be inserting {{&gt; meal}} — which refers to the template name.</p><p>In the future you’ll want to separate these into different packages, but having it inline after the &lt;/body&gt; is fine for now.</p><h3>The Client</h3><p>Next we’ll focus on the Javascript.</p><p>Once again, this should be separated into different files later, but since this is a simple project, leaving it all in one is fine.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d0d5b870a642872760fa6b50d19a4f2/href">https://medium.com/media/6d0d5b870a642872760fa6b50d19a4f2/href</a></iframe><p>There are two distinct sections here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d17567a2ce92c2bfb4ef95e81399b37/href">https://medium.com/media/9d17567a2ce92c2bfb4ef95e81399b37/href</a></iframe><p>And…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cce20f45f22aefe23c5fe2a02dcf9cd/href">https://medium.com/media/7cce20f45f22aefe23c5fe2a02dcf9cd/href</a></iframe><p>These two sections are how we determine what happens in the browser vs on the server.</p><p>This is an important distinction because there are certain things we don’t want to happen in the browser side, like automatically updating the Collections. That exposes some security issues that we’ll talk about in another Munchie later on.</p><p>Anyway, the first thing we need to do is create the actual collection.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5010fe52ca2aad58bd9d6ff091e59191/href">https://medium.com/media/5010fe52ca2aad58bd9d6ff091e59191/href</a></iframe><p>This will either create a new MongoDB collection or connect to an existing one. Unlike writing your first app in Angular or Ember, the data here is actually persistent because we’re connecting to a real MongoDB instance that’s bundled with Meteor. Again, so cool.</p><p>That means you can deploy this to a server (and we will later) and be up and running using real data in no time.</p><p>Next we need to subscribe to the collection.</p><p>In short, this just means ‘give me the data and keep me updated if something changes’.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb89b61c753c42594060aaf80acee137/href">https://medium.com/media/cb89b61c753c42594060aaf80acee137/href</a></iframe><p>Next, add this bit. It’ll create a connector between the actual data model and the DOM, allowing for automated (reactive) updates.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e0ed29848e1633299fb0c8dd198aa9a/href">https://medium.com/media/2e0ed29848e1633299fb0c8dd198aa9a/href</a></iframe><p>The next part is the most fun, for me anyway.</p><p>Handling DOM events.</p><p>Meteor makes this really, really easy.</p><p>Normally in the JQuery world a click handler would look something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6b0079f94563b6f8febfbdac73f6d9d/href">https://medium.com/media/f6b0079f94563b6f8febfbdac73f6d9d/href</a></iframe><p>However, in Meteor, our event handlers are a bit different.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48df1d75b81b1a2d10b0407de29414be/href">https://medium.com/media/48df1d75b81b1a2d10b0407de29414be/href</a></iframe><p>In the object key, ‘click #new-meal’, you’ve got two separate sections.</p><p>The first is the event, in this case ‘click’, and then the DOM element CSS selector.</p><p>So, when someone clicks on #new-meal, do something.</p><p>Now let’s add all our click handlers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d17a7809a0b5bb74702803b44089c4d7/href">https://medium.com/media/d17a7809a0b5bb74702803b44089c4d7/href</a></iframe><p>I won’t go into all the logic here, but I’ll talk about the Meteor specific things.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5d338e9e4f29ba5c49101ba921d649a/href">https://medium.com/media/e5d338e9e4f29ba5c49101ba921d649a/href</a></iframe><p>This is pretty similar to…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2267edc02f97c0cedc75d219b1fad507/href">https://medium.com/media/2267edc02f97c0cedc75d219b1fad507/href</a></iframe><p>However, in Meteor we’re using these so that later on we can add some security into the system.</p><p>That won’t be added in this Munchie, but in the followup to this post we’ll be adding a login system.</p><p>Check out <a href="https://github.com/cwramsey/FoodCal">the project on GitHub</a> if you want to see how all that works immediately.</p><p>You can see another example of a Meteor.call a bit further down in the delete function and in a little bit we’ll actually be adding these methods. So keep on scrolling.</p><h3>The Server</h3><p>In this project, the server is actually REALLY simple.</p><p>All we’re doing is ‘publishing’ the meals collection.</p><p>This is a connection to the subscription we created earlier so that the database will talk with the front end.</p><p>Meteor makes this system incredibly easy.</p><p>Publish a data source (database, API, file) and subscribe to it in the DOM for reactive updates. Pretty nifty.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/153a2f22c3c58376890d5c90f166b873/href">https://medium.com/media/153a2f22c3c58376890d5c90f166b873/href</a></iframe><p>And lastly…</p><p>The Methods</p><p>This is where we connect the front end to the back end. Earlier we were using Meteor.call methods and this is where we create them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d9aec06bd2ebf8d0f8f2c9192067fde/href">https://medium.com/media/2d9aec06bd2ebf8d0f8f2c9192067fde/href</a></iframe><p>In here we’ve got two methods. addMeal and deleteMeal.</p><p>Both of them are interacting with the Meals model we created at the very top of the file.</p><p>Pay attention to the methods you’re calling on the model. Meteor makes it incredibly easy to manage your data.</p><p>And the really cool part is that Mongo is a schemaless database.</p><p>Unlike something like MySql, you don’t have to create a layout for your ‘tables’ (collections).</p><p>You can manage it on the fly.</p><p>That said, you should put some thought into your layout anyway. But that’s a chat for another day.</p><p>Now, slap it all together and you’re just about done.</p><p>Since you started the meteor server earlier, you can go to localhost:3000 and see the working site right in front of your eyes.</p><p>Great job!</p><p>Now, to deploy the project to the web for others to play with, just run this command.</p><blockquote><em>meteor deploy YourProject.meteor.com</em></blockquote><p>And you’re done.</p><p>You can now go to yourproject.meteor.com and see it live.</p><p>How easy is that?</p><p>Next time we’ll talk about adding a user system, which Meteor also makes stupidly easy.</p><p>If you want to see that live now, go <a href="https://github.com/cwramsey/foodcal">check out the project on GitHub</a>. It’s all there.</p><p>If you liked this post or have any questions, feel free to <a href="http://about.me/chrisramsey">contact me</a> and we can chat. I’d love to hear from you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13612234b33c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/meteor-js/a-meal-calendar-made-in-meteor-13612234b33c">A Meal Calendar Made In Meteor</a> was originally published in <a href="https://medium.com/meteor-js">Meteor Hammer</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>