<?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 Kimchi on Medium]]></title>
        <description><![CDATA[Stories by Kimchi on Medium]]></description>
        <link>https://medium.com/@apertureless?source=rss-78b6281cf144------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Kimchi on Medium</title>
            <link>https://medium.com/@apertureless?source=rss-78b6281cf144------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 20:18:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@apertureless/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[How to build a load more button with Vue.js and GraphQL]]></title>
            <link>https://medium.com/hackernoon/how-to-build-a-load-more-button-with-vue-js-and-graphql-5e6de1b61a6b?source=rss-78b6281cf144------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e6de1b61a6b</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[build-a-load-more-button]]></category>
            <dc:creator><![CDATA[Kimchi]]></dc:creator>
            <pubDate>Wed, 11 Apr 2018 12:36:01 GMT</pubDate>
            <atom:updated>2018-04-11T12:36:01.028Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ldGjoCumsHL0b0noWGSwvw.png" /></figure><p>While I was working on 🎨 <a href="https://www.colourhunt.com/">Colour Hunt</a> I had to implement pagination at some point. No one wants to load a ton of color palettes at once. However I really like the lazy load approach instead of a classic pagination.</p><h3>💪 Preparation</h3><p><a href="https://www.colourhunt.com/">Colour Hunt</a> is build with Nuxt.js, Graph.cool and <a href="https://github.com/Akryum/vue-apollo">vue-apollo</a>. The stack is a dream for rapid development as you don’t need to fiddle around with a backend. The idea behind Colour Hunt is, that people can create and share color palettes. However you can use this techniques for all kind of graphql nodes. Most examples are using the good old Blog example and posts.</p><p>So let’s take a look at our GraphQL query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*170zLHoVwV3U1H4mVGuFqg.png" /><figcaption>Colour Hunt example query</figcaption></figure><p>Lets say we have a simple query like this. Just query all palettes that are available and order them by a variable. And our vue component would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N7wlZJol-muLFiJ9SqOl8Q.png" /><figcaption>Vue component with query</figcaption></figure><p>We simply load our query, and vue-apollo does all the magic behind the scenes. And we just iterate over our query results. And render the color-palette component.</p><h3>📝 Pagination</h3><p>We now need to add two arguments to our query. The skip argument which defines the <em>offset </em>where the query will start and the first argument which defines the <em>limit</em> or how many element you want to query. And we also need to know how many elements there are. So we utilize the _meta query. So our new query will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sdonjqouLl9xMBAoYbA-yg.png" /><figcaption>New query with first and skip arguments</figcaption></figure><p>Now our GraphQL query is ready. And we need to update the Vue component. First we need to update our data. Because we added the totalCount to our query.</p><p>The totalCount is quite important, because we need it to check if there are more palettes to load. If we loaded all palettes, we should not fetch again. We simply add a computed property that will tell us, if we can fetch more. And we can use it, as a condition for our <em>Load More</em> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ViBebO1XPlo25yv8WmJlyw.png" /><figcaption>Updated data and computed property</figcaption></figure><p>Now we need to update our vue-apollo query and add the missing variables. We should at first create a new variable which holds our number of items we want to fetch. For example PALETTES_PER_PAGE which I created as a local const variable. You could also use a separate file like constants.js where you save all this kind of constants. So you can change it in one place.</p><p>Now it becomes a bit tricky. Because vue-apollo automatically map your query result to your local data model. But we have two returned objects. First allPalettes and second totalCount . I guess you could also execute the query twice, but this seems to me like a code smell.</p><p>Instead we can use the result() method which comes with vue-apollo. We simply grab the totalCount and assign it to our local totalCount.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yAefHVp-lzox8io8JJ1wCg.png" /></figure><p>Now lets create our button which will fetch more entries. Simple as that we just add a render condition, which is our computed property. <br>And as we have our loading state, we can change the button text, depending on if it is loading or not.</p><p>And on a click we call our loadMore() method, which we will create in a second.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w4M_pP_aA51vc6ibQf9A2A.png" /></figure><h3>⚡️ Updating the query</h3><p>Now comes the fun part. We need to update our query and fetch more. Vue-apollo comes with a build-in method for that. In our loadMore() method we just need to call</p><pre><em>this</em>.$apollo.queries.allPalettes.fetchMore({<br>  variables: {<br>    skip: <em>this</em>.allPalettes.length<br>  }<br>})</pre><p>So you remember what the skip argument is doing? Right, it is setting an <em>offset</em>. In our initial query we set skip: 0 and first to PALETTES_PER_PAGE which equals 10. So we are not skipping anything, and loading the first 10 palettes. Now we fetchMore and skip the first 10 palettes. Because this.allPalettes.length` is now 10.</p><p>However this is not enough. We also have to update our query in the cache. Which is quite simple: We are checking if there are fetchMoreResults if not, we are returning the previousResults . Otherwise we append the new palette results to the old one with Object.assign() and the spread operator. If you have trouble following, it is always helpful to check out the structure of the apollo cache with the <a href="https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm">apollo chrome plugin</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g7acoc_vt3JwCjr_Wk01cA.png" /></figure><h3>🎉 Final Result</h3><p>And thats actually it! We implemented lazy loading of palettes in just a few lines of code. And here is the final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*_0F9b9wiw3Yiss-dzAyPqg.gif" /></figure><p>I am building <a href="https://www.colourhunt.com/">Colour Hunt</a> in public and you can follow the progress on <a href="https://wip.chat/products/880">WIP</a>. I am also live streaming the development from time to time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e6de1b61a6b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-to-build-a-load-more-button-with-vue-js-and-graphql-5e6de1b61a6b">How to build a load more button with Vue.js and GraphQL</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Build a Web App with Vue, Chart.js and an API Part II]]></title>
            <link>https://medium.com/hackernoon/lets-build-a-web-app-with-vue-chart-js-and-an-api-part-ii-39781b1d5acf?source=rss-78b6281cf144------2</link>
            <guid isPermaLink="false">https://medium.com/p/39781b1d5acf</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[charts]]></category>
            <dc:creator><![CDATA[Kimchi]]></dc:creator>
            <pubDate>Sun, 30 Apr 2017 11:48:14 GMT</pubDate>
            <atom:updated>2017-07-19T12:03:32.250Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rsTJUWzJ4SS0NNAI45USFw.png" /></figure><h4>Second part of building a webapp which interacts with the npm api and generate charts</h4><p>In case you missed the first part, you can find it <a href="https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-544eb81c4b44">here</a>. First of all, wow! Thanks for all the feedback and twitter messages! 💝 I never imagined to reach such a wide audience. But enough of that. Let’s get to work 💪.</p><h4>⚡ Quickstart</h4><p>So, we are building <a href="http://npm-stats.org/">npm-stats.org</a>. A small web application build with <a href="https://vuejs.org/">Vue.js</a>, <a href="http://vue-chartjs.org/#/">vue-chartjs</a> and the <a href="https://medium.com/npmjs.org">npm</a> API, to grab the download statistics of packages and generate charts based on them.</p><h4>What we have done so far</h4><p>A small recap of what we have build in <a href="https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-544eb81c4b44">Part 1</a>:</p><ul><li>✅ Create a vue.js application with vue-init</li><li>✅ Install dependencies and setup the vue-router</li><li>✅ Create a Line Chart component with vue-chartjs</li><li>✅ Make an API call to npm and render the daily downloads statistics of the last-month</li></ul><p>This is quite a lot. In the end we had our app running. However there is always space for improvement!</p><h4>What we will do today:</h4><ul><li>⚙ Add settings to change the start and end period</li><li>📆 Integrate an external datepicker component</li><li>📈 Mutate our data to add a yearly statistics chart</li><li>🔨 Refactor our methods and DRY out a bit so we can easily add more charts</li></ul><h4>⚙ Settings</h4><p>Right now our default period is set to last-month but it would be awesome if we could set the startPeriod and endPeriod. This way we could inspect the statistics for a whole year or more.</p><p>For this purpose we need to add two additional input fields and data models. But for a better user experience we will pull in an external datepicker component. We don’t have to reinvent the wheel right? 👨‍🔬 And to format our date properly we will also pull in moment.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*5efC00Bu1w0pX-UBlNFjug.png" /><figcaption>Datepicker</figcaption></figure><p><strong>📆 Install dependencies</strong></p><p>yarn add vuejs-datepicker moment</p><p>Todos for our <strong>Start.vue</strong>:</p><ul><li>Import the datepicker</li><li>Add two datepicker fields for the start and end period</li><li>Add two data models</li></ul><pre>// Start.vue<br><br>&lt;template&gt;<br><br>...<br><br>&lt;datepicker placeholder=&quot;Start Date&quot; v-model=&quot;periodStart&quot; name=&quot;start-date&quot;&gt;&lt;/datepicker&gt;<br>&lt;datepicker placeholder=&quot;Start Date&quot; v-model=&quot;periodStart&quot; name=&quot;start-date&quot;&gt;&lt;/datepicker&gt;<br><br>...<br><br>&lt;/template&gt;<br><br>&lt;script&gt;<br>  import axios from &#39;axios&#39;<br>  import Datepicker from &#39;vuejs-datepicker&#39;<br>  import LineChart from &#39;@/components/LineChart&#39;<br>  <br>  export default {<br>    components: {<br>      LineChart,<br>      Datepicker<br>    },<br>    data () {<br>      return {<br>        package: null,<br>        packageName: &#39;&#39;,<br>        loaded: false,<br>        downloads: [],<br>        labels: [],<br>        showError: false,<br>        errorMessage: &#39;Please enter a package name&#39;,<br>        periodStart: &#39;&#39;,<br>        periodEnd: new Date()<br>      }<br>    },<br>    <br>    .....<br>}<br> <br>&lt;/script&gt;</pre><p>We also removed our old period data model which was set to last-month. As the period will now be composed of periodStart and periodEnd. We also set the periodEnd to the current day. As most of the time you will only change the start date.</p><p>We need a format like this: 2017-04-18:2017-04-30. However if we now select a date we get something like this: 2017-04-17T22:00:00.000Z. A Date() with the time attributes, which we don&#39;t need. This is a nice job for moment.js.</p><h4>Computing the period</h4><p>For this case we have <a href="https://vuejs.org/v2/guide/computed.html">computed properties</a> which are a pleasure to work with. To keep things a bit cleaner, we will create three properties. A formatted startDate, a formatted endDate and the composed period.</p><pre>computed: {<br>  _endDate () {<br>    return moment(this.periodEnd).format(&#39;YYYY-MM-DD&#39;)<br>  },<br>  _startDate () {<br>    return moment(this.periodStart).format(&#39;YYYY-MM-DD&#39;)<br>  },<br>  period () {<br>    return this.periodStart ? <br>           `${this._startDate}:${this._endDate}` : <br>           &#39;last-month&#39;<br>  }<br>},</pre><p>As we want to persist the default behaviour of fetching data of the last month if no start date is set, we add our condition to the period property.</p><p>And thats it! We don’t need to change our request, as we simply replaced the content of period which we are using in our request. You can check the code on github in this <a href="https://github.com/apertureless/npm-stats/tree/feature/date_settings_%234">feature branch</a></p><h4>📈 More charts</h4><p>Well, the chart with the daily statistics is great. But we can generate more! We have all data we need for that. We will not transform and group our data, so we can pass it to another line chart for yearly statistics. And we will refactor a bit our code.</p><h4>All this data</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*dvc1IR3c1A13TZVyHpdbjA.jpeg" /></figure><p>So, our data we get from the npm api looks like this:</p><pre>data: [<br>{day: &quot;2017-04-18&quot;, downloads: 16280},<br>{day: &quot;2017-04-19&quot;, downloads: 14280},<br>{day: &quot;2017-04-20&quot;, downloads: 17280}<br>]</pre><p>But to pass it to our chart we need two arrays, one which the labels (<em>day</em>) and one with the data (<em>downloads</em>). For the daily statistics, it was pretty easy. As we could simply use map() to get the data and labels. However now we need to do more.</p><ol><li>Format our day key to a year.</li><li>For the labels, remove the duplicates so we have only the unique years</li><li>Sum all the downloads in the same year.</li></ol><p>☝ But first, it is a good time to refactor some bits of our code. We see that step 1 is to format our date to a year. And later if we want monthly statistics we need to format it to a month format and so on. So it is a good time to introduce a helper method and extract the logic from the <strong>Start.vue</strong> file.</p><p>So we create src/utils/dateFormatter.js which will help us to format our date.</p><pre>import moment from &#39;moment&#39;<br>  <br>export const dateToYear = date =&gt; moment(date).format(&#39;YYYY&#39;)<br>export const dateToMonth = date =&gt; moment(date).format(&#39;MMM YYYY&#39;)<br>export const dateToWeek = date =&gt; moment(date).format(&#39;GGGG-[W]WW&#39;)<br>export const dateToDay = date =&gt; moment(date).format(&#39;YYYY-MM-DD&#39;)<br>export const dateBeautify = date =&gt; moment(date).format(&#39;Do MMMM YYYY&#39;)</pre><p>And in our <strong>Start.vue</strong> we can now remove the moment import and import our helper modules and replace the moment statements with them. (In our _startPeriod and _endPeriod. And we add a new computed property to which will replace the period in our chart container.</p><pre>import { dateToYear, dateToDay, dateBeautify } from &#39;../utils/dateFormatter&#39;<br>  <br>  computed: {<br>    _endDate () {<br>      return dateToDay(this.periodEnd)<br>    },<br>    _startDate () {<br>      return dateToDay(this.periodStart)<br>    },<br>    period () {<br>      return this.periodStart ?  `${this._startDate}:${this._endDate}` : &#39;last-month&#39;<br>    },<br>    formattedPeriod () {<br>      return this.periodStart ? `${dateBeautify(this._startDate)} - ${dateBeautify(this._endDate)}` : &#39;last-month&#39;<br>    }<br>  },</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ms5y_4ltcsMvWTv6tedMGQ.png" /><figcaption>Chart with formattedPeriod in title</figcaption></figure><h4>Time to transform</h4><p>Now we create three new data models rawData which will hold our downloads data we get from the api call, downloadsYear: [] and labelsYear: []. And we create a new method called formatYear() .</p><p>In our axios request promise we then assign the data.downloads to rawData and call formatYear().</p><pre>axios.get(`https://api.npmjs.org/downloads/range/${this.period}/${this.package}`)<br>    .then(response =&gt; {<br>      this.rawData = response.data.downloads // 🆕<br>      this.downloads = response.data.downloads.map(entry =&gt; entry.downloads)<br>      this.labels = response.data.downloads.map(entry =&gt; entry.day)<br>      this.packageName = response.data.package<br>      this.formatYear() // 🆕<br>      this.setURL()<br>      this.loaded = true<br>      <br>    })</pre><p>Now we will create two additional helper methods. Because we want different data transformations in the future. Like weekly stats and monthly. And to keep our component clean we extract those into a separate file.</p><p>So we create our src/utils/downloadFormatter.js which will contain two methods:</p><ol><li>removeDuplicate (a, b) {..}</li><li>getDownloadsPerYear(data) {…}</li></ol><p>In our <strong>Start.vue</strong> we import both modules and now we can use them in our formatYear() method.</p><pre>formatYear () {<br>  this.labelsYear = this.rawData<br>    .map(entry =&gt; dateToYear(entry.day))<br>    .reduce(removeDuplicate, [])<br>  this.downloadsYear = getDownloadsPerYear(this.rawData)<br>},</pre><p>Now thats a bit tricky now. Normally I write down my methods and clean then up later. However I hope you can follow me here.</p><p>First we need to get the years, right? So we use again map() to get the day key like we did in the request for our daily statistics. But now we format it with our dateToYear() helper. So now our data will look like this:</p><pre>data: [<br>{day: &quot;2017&quot;, downloads: 16280},<br>{day: &quot;2017&quot;, downloads: 14280},<br>{day: &quot;2017&quot;, downloads: 17280}<br>]</pre><p>And now we will use reduce() to remove the duplicated years. Because our labels array will have only unique years. And as we may use this more then once, we extracted it into our downloadFormatter.js</p><p>In our <strong>downloadFormatter.js</strong> we now finish our removeDuplicate function.</p><pre>export function removeDuplicate (a, b) {<br>    if (a.indexOf(b) &lt; 0) {<br>      a.push(b)<br>    }<br>    return a<br>  }</pre><p>Now our this.labelYear array will contain only unique years. And it&#39;s time to group and transform our data. For this we will again use map() and reduce() and filter().</p><p>The rawData looks like this:</p><pre>data: [<br>{day: &quot;2017-04-18&quot;, downloads: 16280},<br>{day: &quot;2017-04-19&quot;, downloads: 14280},<br>{day: &quot;2017-04-20&quot;, downloads: 17280}<br>]</pre><p>So first we need to find the unique dates again. Which we do with reduce() then we chain a map() to it and return an object with the date and the downloads which are in that date. Thats why we use filter() there and our dateToYear() helper.</p><p>However our data will look now like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*O49eVMPIRWNBVyZMoFExVA.png" /><figcaption>First reduce</figcaption></figure><p>But as we don’t need the date now, we map it to only the downloads and then use reduce() to sum it up. Now our object will contain the sum of all downloads of the year. However it is nested and we still have the date key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*UwiR7ow8qxlBX3l1_sVbGA.png" /><figcaption>After map and second reduce</figcaption></figure><p>But a last map() will fix this.</p><pre>export const getDownloadsPerYear = (data) =&gt; {<br>    // Find unique dates<br>    return data.reduce((date, current) =&gt; {<br>      if (date.indexOf(dateToYear(current.day)) &lt; 0) {<br>        date.push(dateToYear(current.day))<br>      }<br>      return date<br>    }, [])<br>      .map((date) =&gt; {<br>        return {<br>          date: date,<br>          downloads: data.filter(el =&gt; dateToYear(el.day) === date)<br>            .map(el =&gt; el.downloads)<br>            .reduce((total, download) =&gt; total + download)<br>        }<br>      })<br>      .map(element =&gt; element.downloads)<br>  }</pre><h4>Chart time</h4><p>Now we have our transformation done and can copy the template for our first chart and pass in the downloadsYear props.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*WgX8Fm5LSM_YnUZazTCPVw.png" /><figcaption>Downloads per Year Chart</figcaption></figure><p><strong>You can check the source up to this point at this </strong><a href="https://github.com/apertureless/npm-stats/tree/feature/yearly_chart"><strong>feature branch</strong></a></p><h4>🔨 Refactor and more charts</h4><p>As we now finished our data transformer it is pretty easy to add new charts. Like weekly statistics and monthly. We could duplicate our getDownloadsPerYear() method and change our dateToYear() helper to dateToMonth(). But, this is not very DRY. Because we end up with multiple methods which are doing pretty much the same.</p><p>So let’s refactor our specific getDownloadsPerYear() method to a more general one. The only thing, that would change it our dateFormatter helper. So we should make it an argument you can pass to our method.</p><ol><li>Rename our method to something more general like groupData</li><li>Add a second argument which will be our helper function</li><li>???</li><li>Profit!</li></ol><pre>export const groupData = (data, dateFormatter) =&gt; {<br>  return data.reduce((date, current) =&gt; {<br>    if (date.indexOf(dateFormatter(current.day)) &lt; 0) {<br>      date.push(dateFormatter(current.day))<br>    }<br>    return date<br>  }, [])<br>    .map((date) =&gt; {<br>      return {<br>        date: date,<br>        downloads: data.filter(el =&gt; dateFormatter(el.day) === date)<br>          .map(el =&gt; el.downloads)<br>          .reduce((total, download) =&gt; total + download)<br>      }<br>    })<br>    .map(element =&gt; element.downloads)<br>}</pre><p>In our <strong>Start.vue</strong> we now need to pass our helper function.</p><pre>this.downloadsYear = groupData(this.rawData, dateToYear)</pre><p>Now we can do this for our monthly and weekly data too, with only swapping out the dateToYear</p><p>You can find the source up to this point in this <a href="https://github.com/apertureless/npm-stats/tree/feature/monthly_chart">feature branch</a> with some additions like a loading indicator and a new fetch of the data if the datepicker value changed, which I did not covered here.</p><blockquote>I hope you enjoyed it and learned something. Feel free to leave me feedback! ✌</blockquote><blockquote>You can follow me on <a href="https://www.twitter.com/apertureless">twitter</a> and <a href="https://github.com/apertureless">github</a>.</blockquote><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39781b1d5acf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/lets-build-a-web-app-with-vue-chart-js-and-an-api-part-ii-39781b1d5acf">Let’s Build a Web App with Vue, Chart.js and an API Part II</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Build a Web App with Vue, Chart.js and an API]]></title>
            <link>https://medium.com/hackernoon/lets-build-a-web-app-with-vue-chart-js-and-an-api-544eb81c4b44?source=rss-78b6281cf144------2</link>
            <guid isPermaLink="false">https://medium.com/p/544eb81c4b44</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kimchi]]></dc:creator>
            <pubDate>Wed, 19 Apr 2017 16:24:57 GMT</pubDate>
            <atom:updated>2017-07-19T09:49:56.841Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dNalUVozyJe65knA-BrZow.png" /></figure><h4>The first part of building a small web app which interacts with the npm API and generates nice charts</h4><p>Data is beautiful. And with modern technologies it is crazy easy to visualize your data and create great experiences. In this quick how to, we cover how to interact with the npm 💘 API to get download statistics of a package and generate a chart from this data with <a href="http://www.chartjs.org/">Chart.js</a></p><h3>⚡ Quickstart</h3><p>We will build <a href="http://npm-stats.org/">npm-stats.org</a> and will be using following tools:</p><ul><li><a href="https://vuejs.org/">Vue.js</a> with vue-router</li><li><a href="http://www.chartjs.org/">Chart.js</a></li><li><a href="http://vue-chartjs.org/#/">vue-chartjs</a></li><li><a href="https://github.com/vuejs/vue-cli">vue-cli</a></li><li><a href="https://github.com/mzabriskie/axios">axios</a></li></ul><p>With Vue.js we will build the basic interface of the app and and routing with vue-router . And we scaffold our project with <a href="https://github.com/vuejs/vue-cli">vue-cli</a> which creates our basic project structure. For the chart generation we will be using Chart.js and as a wrapper for Vue, <a href="http://vue-chartjs.org/#/">vue-chartjs</a>. As we need to interact with an API, we’re using <a href="https://github.com/mzabriskie/axios">axios</a> to make the http requests. However feel free to swap that one out with any other lib.</p><h3>🔧 Install &amp; Setup</h3><p>At first we need to install vue-cli to scaffold our project. I hope you have a current version of node and npm already installed! 🙏 Even better if you have <a href="https://yarnpkg.com/lang/en/">yarn</a> installed! If not, you really should! If you don’t want, just swap out the yarn commands with the npm equivalents.</p><pre>$ npm install -g vue-cli</pre><p>Then we can scaffold our project with vue-cli. If you want to can enable the unit and e2e tests, however we will not cover them.🔥 But you need to check vue-router!</p><pre>$ vue init webpack npm-stats</pre><p>Then we cd in our project folder and install the dependencies withcd npm-stats &amp;&amp; yarn install . So our basic project dependencies are installed. Now we need to add the one for our app.</p><pre>$ yarn add vue-chartjs chart.js axios</pre><p>Just a quick check if everything is running with yarn run dev . Now we should see the boilerplate page of vue.</p><p>Aaaand we’re done! 👏</p><h3>💪 Time to build</h3><p>Just a small disclaimer here, I will not focus on the styling. I guess you’re able to make the site look good by your own 💅 so we only cover the javascript related code.</p><p>And another disclaimer, this is rather a small MVP then super clean code right now. I will refactor some of it in later stages. Like in the real world.</p><h4>Components</h4><p>Let’s think about what components we need. As we’re looking at the screenshot we see an input field for the package name you’re looking for and a button. Maybe a header and footer and the chart itself.</p><p>You totally could make the button and input field a component however as we don’t build a complex app, why bother? Make it simple. Make it work!</p><p>So I ended up with following components:</p><ul><li>components/Footer.vue</li><li>components/Header.vue</li><li>components/LineChart.vue</li><li>pages/Start.vue</li></ul><p>I will skip the <em>Header</em> and <em>Footer</em> as they only contain the logo and some links. Nothing special here. The <em>LineChart</em> and <em>Start</em> page are the important ones.</p><h4>LineChart</h4><p>The LineChart component will be our chart.js instance which renders the chart. We need to import the Line component and extend it. We create two props for now. One for the data which is the number of downloads and the labels which are for example the days, weeks, years.</p><pre>props: {<br> chartData: {<br>   type: Array,<br>   required: false<br> },<br> chartLabels: {<br>   type: Array,<br>   required: true<br> }<br>},</pre><p>As we want all our charts to look the same, we define some of the Chart.js styling options in a data model which get passed as <em>options</em> to the <strong>renderChart()</strong> method.</p><p>And as we will have only one dataset for now, we can just build up the dataset array and bind the labels and data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c1fe292c802dca603841046dffe9b88/href">https://medium.com/media/3c1fe292c802dca603841046dffe9b88/href</a></iframe><h3>📺 Our start page</h3><p>As we have our LineChart component up and working. It’s time to build the rest. We need an input field and button to submit the package name. Then request the data and pass the data to our chart component.</p><p>So, let’s first think about what data we need and what states / data models. First of all we need a package data model, which we will use with v-model in our input field. We also want to display the name of the package as a headline. So packageName would be good. Then our two arrays for the requested data downloads and labels and as we’re requesting a time period we need to set the period . But, maybe the request goes wrong so we need errorMessage and showError . And last but not least loaded as we want to show the chart only after the request is made.</p><h4>npm API</h4><p>There are various endpoints to get the downloads of a package. One is for example</p><pre>GET <a href="https://api.npmjs.org/downloads/point/%7Bperiod%7D%5B/%7Bpackage%7D%5D">https://api.npmjs.org/downloads/point/{period}[/{package}]</a></pre><p>However this one gets only a point value. So the total downloads. But to draw our cool chart, we need more data. So we need the range endpoint.</p><pre>GET <a href="https://api.npmjs.org/downloads/range/%7Bperiod%7D%5B/%7Bpackage%7D%5D">https://api.npmjs.org/downloads/range/{period}[/{package}]</a></pre><p>The period can be defined as for example last-day or last-month or a specific date range 2017-01-01:2017-04-19 But to keep it simple we set the default value to last-month . Later in Part II we can then add some date input fields so the user can set a date range.</p><p>So our data models are looking like this:</p><pre>data () {<br> return {<br>  package: null,<br>  packageName: ‘’,<br>  period: ‘last-month’,<br>  loaded: false,<br>  downloads: [],<br>  labels: [],<br>  showError: false,<br>  errorMessage: ‘Please enter a package name’<br> }<br>},</pre><h3>💅 Template</h3><p>Now it’s time to build up the template. We need 5 things:</p><ul><li>Input Field</li><li>Button to trigger the search</li><li>Error message output</li><li>Headline with the package name</li><li>Our Chart.</li></ul><pre>&lt;input<br> class=”Search__input”<br> <a href="http://twitter.com/keyup">@keyup</a>.enter=”requestData”<br> placeholder=”npm package name”<br> type=”search” name=”search”<br> v-model=”package”<br> &gt;<br>&lt;button class=”Search__button” <a href="http://twitter.com/click">@click</a>=”requestData”&gt;Find&lt;/button&gt;</pre><pre>&lt;div class=&quot;error-message&quot; v-if=&quot;showError&quot;&gt;<br>  {{ errorMessage }}<br>&lt;/div&gt;</pre><pre>&lt;h1 class=&quot;title&quot; v-if=&quot;loaded&quot;&gt;{{ packageName }}&lt;/h1&gt;<br>&lt;line-chart v-if=&quot;loaded&quot; :chart-data=&quot;downloads&quot; :chart-labels=&quot;labels&quot;&gt;&lt;/line-chart&gt;</pre><p>Just ignore the css classes for now. We have our Input Field which has an keyup event on enter. So if you press enter you trigger the requestData() method. And we bind v-model to package</p><p>For the potential error we have a condition, only if showError is <em>true</em> we show the message. There are two types or errors that can occur. The one is, someone try to search for a package without entering any name or he’s entering a name that does not exist.</p><p>For the first case, we have our default errorMessage, for the second case we will grab the error message that comes from the request.</p><p>So our full template will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0227eddd7e86c68e7f4b41c85c446bd2/href">https://medium.com/media/0227eddd7e86c68e7f4b41c85c446bd2/href</a></iframe><h3>🤖 Javascript</h3><p>Now it’s time for the coding. First we will do our requestData() method. It is rather simple. We need to make a request to our endpoint and then map the data that comes in. In our <strong>response.data </strong>we have some information about the package:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*UB5wPbn6UMGZmWa1O7xiBQ.png" /><figcaption>response.data</figcaption></figure><p>Like the start data, end date, the package name and then the downloads array. However the structure for the downloads array is something like this:</p><pre>downloads: [<br> {day: ‘2017–03–20’, downloads: ‘3’},<br> {day: ‘2017–03–21’, downloads: ‘2’},<br> {day: ‘2017–03–22’, downloads: ‘10’},<br>]</pre><p>But we need to separate the downloads and days, because for chart.js we need one array only with the data (downloads) and one array with the labels (day). This is an easy job for <strong>map</strong></p><pre>requestData () {<br> axios.get(`<a href="https://api.npmjs.org/downloads/range/$%7Bthis.period%7D/$%7Bthis.package%7D%60">https://api.npmjs.org/downloads/range/${this.period}/${this.package}`</a>)<br> .then(response =&gt; {<br>   this.downloads = response.data.downloads.map(download =&gt; download.downloads)<br>   this.labels = response.data.downloads.map(download =&gt; download.day)<br>   this.packageName = response.data.package<br>   this.loaded = true<br> })<br> .catch(err =&gt; {<br>   this.errorMessage = err.response.data.error<br>   this.showError = true<br> })<br>}</pre><p>Now if we enter a package name, like vue and hit enter, the request is made, the data mapped and the chart rendered! But, wait. You don’t see anything. Because we need to tell vue-router to set the index to our start page.</p><p>Under router/index.js we import or page and tell the router to use it</p><pre>import Vue from ‘vue’<br>import Router from ‘vue-router’<br>import StartPage from ‘@/pages/Start’</pre><pre>Vue.use(Router)</pre><pre>export default new Router({<br> routes: [<br>   {<br>     path: ‘/’,<br>     name: ‘Start’,<br>     component: StartPage<br>   },<br> ]<br>})</pre><h3>💎 Polish</h3><p>But, we are not done yet. We have some issues, right? First our app breaks if we don’t enter any name. And we have problems if you enter a new package and hit enter. And after an error the message does not disappear.</p><p>Well, it’s time to clean up a bit. First let’s create a new method to reset our state.</p><pre>resetState () {<br> this.loaded = false<br> this.showError = false<br>},</pre><p>Which we call in our requestData() method before the axios api call. And we need a check for the package name.</p><pre>if (this.package === null <br>    || this.package === ‘’ <br>    || this.package === ‘undefined’) {<br>  this.showError = true<br>  return<br>}</pre><p>Now if we try to search an empty package name, we get or default errorMessage.</p><p>I know, we covered a lot, but let’s add another small cool feature. We have vue-router, but not really using it. At our root / we see the starting page with the input field. And after a search we stay at our root page. But it would be cool if we could share our link with the stats, wouldn’t it be?</p><p>So after a valid search, we add the package name to our url.</p><p>npm-stats.org/#/vue-chartjs</p><p>And if we click on that link, we need to grab the package name and use it to request our data.</p><p>Let’s create a new method to set our url</p><pre>setURL () {<br> history.pushState({ info: `npm-stats ${this.package}`}, this.package, `/#/${this.package}`)<br> }</pre><p>We need to call this.setURL() in our response promise. Now after the request is made, we add the package name to our URL. But, if we open a new browser tab and call it, nothing happens. Because we need to tell vue-router that everything after our / will also point to the start page and define the string as a query param. Which is super easy.</p><p>In our router/index.js we just need to set another path in the routes array. We call the param package.</p><pre>{<br>  path: ‘/:package’,<br>  component: StartPage<br> }</pre><p>Now if you go to localhost:8080/#/react-vr you will get the start page. But without a chart. Because we need to grab the param and do our request with it.</p><p>Back in our Start.vue we grab the param in the mounted hook.</p><pre>mounted () {<br> if (this.$route.params.package) {<br>   this.package = this.$route.params.package<br>   this.requestData()<br> }<br>},</pre><p>And thats it!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0192a2efe9a81f20f69f3b30fb2a6c1c/href">https://medium.com/media/0192a2efe9a81f20f69f3b30fb2a6c1c/href</a></iframe><p>You can check out the full source at <a href="https://github.com/apertureless/npm-stats">GitHub</a> and view the demo page at 📺 <a href="http://npm-stats.org/">http://npm-stats.org/</a></p><h3>Improvements</h3><p>But hey, there is still room for improvements. We could add more charts. Like monthly statistics, yearly statistics and add date fields to set the period and many more things. I will cover some of them in<strong> Part II</strong> ! So stay tuned!</p><p>Part 2: <a href="https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-part-ii-39781b1d5acf">https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-part-ii-39781b1d5acf</a></p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=544eb81c4b44" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/lets-build-a-web-app-with-vue-chart-js-and-an-api-544eb81c4b44">Let’s Build a Web App with Vue, Chart.js and an API</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ How to publish your package on npm]]></title>
            <link>https://medium.com/hackernoon/how-to-publish-your-package-on-npm-7fc1f5aae600?source=rss-78b6281cf144------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fc1f5aae600</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Kimchi]]></dc:creator>
            <pubDate>Sat, 08 Apr 2017 14:32:25 GMT</pubDate>
            <atom:updated>2018-03-30T08:49:52.632Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ASqubrsGsRTIrDh8hNV3HA.jpeg" /></figure><h4>An in-depth guide on how to publish your modules on <a href="https://www.npmjs.com/">npm</a>, without pain.</h4><p>So, you have finished a lib, cli tool, component or some other scripts to want to share with the world.🌍 So it is time to publish it on <a href="https://www.npmjs.com/">npm</a>.</p><h4>🥇 Your first package</h4><p>Let’s assume, you already use <a href="https://www.npmjs.com/">npm</a> for your dependencies. You installed them with npm install XYZ or if you&#39;re super cool 😎 with <a href="https://yarnpkg.com/lang/en/">yarn</a></p><p>If you now want to publish your package on npm there is a simple command for that:</p><pre>npm publish</pre><p>🔥 But before we do this, we have still some points on our 📋checklist.</p><h4>📦 Package.json</h4><p>You know that all dependencies get saved in your package.json. Furthermore you save also relevant information about your package in this file. You can look them up <a href="https://docs.npmjs.com/files/package.json">here</a></p><p>However the most important would be</p><ul><li>name</li><li>version</li><li>description</li><li>author</li><li>license</li><li>repository</li><li>main</li></ul><p>The name field defines the name your package will have in the registry and people will install your package over the name you define there. yarn add XYZ .</p><p>The version tag defines the version of your package. You really should consider using <a href="http://semver.org/">semver</a>. Because maybe a lot of people will use your package. And there is no worse feeling then breaking peoples production code because you introduce breaking changes but only change the patch version of your package. 🙈</p><p>In the description field you should add a quick and on-point description, about your package. People will read it if they search for your package on npmjs.org</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxhtZKRvBSD58UKN51E25w.png" /><figcaption>npm search shows title, username, version and description defined in your package.json</figcaption></figure><p>In the author field you add your name and e-mail, so people know who published the package. It&#39;s common to add it in the form of Name &lt;e-mail&gt;.</p><p>I guess the license field is one of the most forgotten fields. People often think it&#39;s not <em>that</em> important. However if you want people to use your package, maybe even in bigger projects you <strong>definitely</strong> should add a license. So they know if they can use it in commercial projects, what are the restrictions and so on.</p><p>You should also add the repository field, with a link to the github repo and you can also add the bugs field with the link to the github issues page. So people can report bugs and know where to request features.</p><p>You can also add keywords which help people to find your package if they search for something on npmjs.org</p><h4>🗄 Dependencies</h4><p>So we all know that you can add dependencies to your project. Or save them as devDependencies with yarn add or yarn add -D</p><p>Now if you work on a project like an app or website, it does not make such a big difference if you add your dependencies as a dependency or devDependency. Because they get bundled into a browser build most of the time.</p><p>However if you want to publish a package, a lib, a vue component etc. it <strong>is</strong> important to get your dependencies right.</p><p><strong>Dependencies</strong> are required for your lib to work. So if you writing an API or a service and you’re using for example <a href="https://github.com/request/request">request</a> it is a dependency. Because it is needed for your code to run properly.</p><p><strong>DevDependencies</strong> are the one, which are required for the development. Like eslint or xo for linting or karma or ava for testing. This is important, because if someone installs your package over yarn add my-awesome-lib the devDependencies does not get installed! So if you add request as a devDependency and somewhere in your code you have an import request from &#39;request&#39; this will not work. Because of the missing dependency.</p><p><strong>peerDependencies</strong> are mostly used if you write a plugin for something. Because it requires the user to have the dependency installed already. For example you want to write a plugin for webpack and you use some functions of webpack and extend them. If you would add webpack as a dependency the user would have installed two versions of webpack the one which he got installed already for his build process and the one which comes with your plugin.</p><p>Which is nonsense. You would have to update your package.json on every release of a new webpack patch and update the dependency version. With peerDependencies you say, <em>Hey look, you need webpack to run my plugin, so install it please. Prefered version is 2.1.x</em> If someone would install webpack 2.2.x your plugin would mostly work, too. There would be a peerDependency version mismatch but as long, there would be no breaking changes it would work. This way you give the user freedom to chose the version and upgrade the dependencies.</p><h4>🚪 Entry Points</h4><p>Now comes a fun part. The entry points of your lib/package. This one <strong>heavily</strong> depends on the type of your package or lib. Is it a node module? Is it a browser plugin?</p><p>The basic entry point will be defined over the main field. There you can add your for example index.js. If you transpile your source or bundle it, you can define the dist file there.</p><pre>&quot;main&quot;: &quot;dist/my-awesome-lib.js&quot;,</pre><p>And if you publishing node modules, you will be fine with this one.</p><p>But if you’re going to publish something for the browser there are more fields to know.</p><p>For example the unpkg field. If you publish your lib on npm it will be available over <a href="https://unpkg.com/#/">unpkg</a>. It&#39;s a CDN so people can pull your scripts into their scripts without installing them over npm.</p><pre><a href="https://unpkg.com/package@version/file">https://unpkg.com/package@version/file</a></pre><p>In the unpkg field you can define the default file, which get served if someone includes <a href="https://unpkg.com/package.">https://unpkg.com/package.</a></p><p>Most of the time, it is a good practice to define the minified version of your lib there.</p><pre>&quot;unpkg&quot;: &quot;dist/my-awesome-lib.min.js&quot;,</pre><p>Last but not least, there are two more fields.</p><p>The module and jsnext:main fields. Which are used by modern build systems like Webpack 2, to grab ES6 Modules.</p><p>So you have build your lib. Mostly with modern ES6. People want to use it directly in the browser. So you need to transpile it. But as you also have dependencies, you need to bundle the dependencies into it. So you generate an UMD module.</p><p>But some people may want to use your package with browserify and gulp. Or with webpack 1. So you need a transpiled and bundled CommonJs build. However we now have 2017 and things like tree-shaking are now in fashion. To do so, you need an extra build. A ES Module build. Where most of the functions and statements get transpiled into ES2015, except the import and export statements.</p><p>I think right now, only <a href="https://rollupjs.org/">Rollup</a> supports ES Modules as a target output. (But you can transpile with with babel,too) So if you have an ES module you can set the entry in the module and / or jsnext:main field.</p><p>This way, you serve different builds, for different people and environments.</p><h4>⛓ Compatibility</h4><p>Mostly important for node modules, you can define which minimal version of nodejs should be installed to run your module. Thats important if you’re using async / await without transpiling it down for example.</p><pre>&quot;engines&quot;: {<br>    &quot;node&quot;: &quot;&gt;=7.8.0&quot;<br>  },</pre><h4>🚫 Ignores and ✅ Files</h4><p>Okay, now we have our different bundles and builds defined and we are nearly ready to publish our package. However you may have a log of stuff in your git repository. The source, maybe assets, the bundled files etc. It’s not smart to include all of this into your npm package. It’s a good practice to keep the size small.</p><p>First of all, you don’t want your generated files in your git repo. So you ignore them in your .gitignore</p><p>You can also add a <a href="https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package">.npmignore</a>.</p><p>If you don’t create a .npmignore but you have a .gitignore npm will exlcude all files defined in the .gitignore</p><p>So, we ignored for example our dist folder in our .gitignore because we don&#39;t want it in our repo. Now we need to tell npm, that we want to include this files.</p><p>So we add a files array in our package.json.</p><pre>&quot;files&quot;: [<br>    &quot;dist&quot;<br>  ],</pre><p>You can also be more explicit and add only files</p><pre>&quot;files&quot;: [<br>    &quot;dist/my-awesome-lib.js&quot;,<br>    &quot;dist/my-awesome-lib.min.js&quot;,<br>    &quot;dist/my-awesome-lib.esm.js&quot;<br>  ],</pre><h4>💯 Publish</h4><p>Now we are ready to publish our package. But because we are developers, and developers are lazy we should add an additional command to our scripts. The prepublish command script.</p><p>This one runs, before every npm publish. So it is good practice to for example clean your node_modules and make a fresh install of the dependencies, lint and test your code and then build your code before a publish. But thats up to you! 👇🏻</p><pre>&quot;scripts&quot;: {<br>    &quot;prepublish&quot;: &quot;yarn run lint &amp;&amp; yarn run test &amp;&amp; yarn run build&quot;<br>  },</pre><p>And finally we run npm publish. Keep in mind that you need an account on npmjs.org ;)</p><h4>🏷 Dist-Tags</h4><p>Last topic is a very handy one! Dist-tags. If you publish your package, it will automatically get the <strong>@latest</strong> tag for the version you published it.</p><p>People can install your package with a strict version or the latest tag: yarn add my-awesome-package@0.0.1 or yarn add my-awesome-package which is equivalent to my-awesome-package@latest</p><p>Now there are some circumstances where you will need dist-tags. One is if you support multiple versions of you package. Good examples are webpack, vue and many more. Where you start with a v1 but then working on a v2.</p><p>Let’s say your package is at v1.10.0 but you’re working on a v2.0.0 release and want people to test it and report issues etc.</p><p>The problem is, that if you simply npm publish it, it will get the latest tag. So everyone installing it over npm install my-lib will get the unstable v2.0.0 which is not what we want. For this purpose we have tags. You can list your tags with npm dist-tag ls and you will get a list of tags and package versions assigned to them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*0TzKsPs7Plfe99t42_eFQA.png" /></figure><p>So you can add a tag to your publish command now.</p><pre>npm publish --tag beta</pre><p>This way the current version v2.0.0 will be tagged with beta. And the @latest tag remains on the v1.10.0</p><p>Now you can install it over npm install my-awesome-lib@beta -D</p><p>🔥 <strong>It’s important to know that you can only assign one version to a tag. And you can’t overwrite changes to a version.</strong></p><p>This is quite important for testing purpose. I learned myself the hard way, that only because your code is working locally and the unit tests pass, this does not mean that the bundled file published on npm will work like you think.</p><p>Thats why it’s good to test your packages before releasing with the @latest tag. You can use the good old release candidates for this. Because if you change the version of your package from 2.0.0 to 2.0.1 and publish it with the beta tag, and then you see that you still got a bug into it, you need to publish the next one with 2.0.2. You can&#39;t make a change to the 2.0.1 release and publish it with the same version with the latest tag.</p><p>Thats why <em>release candidates</em> or <em>beta</em> postfixes come handy.</p><p>You simple set the version in your package.json to 2.0.0-rc1 and publish it with the beta tag. Then you can test it and only bump the rc1 to rc2 etc. If you think you ready to go, you publish it as 2.0.0 ⭐</p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fc1f5aae600" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-to-publish-your-package-on-npm-7fc1f5aae600">📦 How to publish your package on npm</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating stunning charts with Vue.js and Chart.js]]></title>
            <link>https://medium.com/hackernoon/creating-stunning-charts-with-vue-js-and-chart-js-28af584adc0a?source=rss-78b6281cf144------2</link>
            <guid isPermaLink="false">https://medium.com/p/28af584adc0a</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[charts]]></category>
            <dc:creator><![CDATA[Kimchi]]></dc:creator>
            <pubDate>Tue, 28 Feb 2017 13:04:23 GMT</pubDate>
            <atom:updated>2018-02-05T14:16:36.971Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dc_ghRRz_QPo-yoOUaCe9Q.png" /></figure><p>Dive into the options of chart.js to create stunning charts.</p><p>Interactive charts can provide a cool way to visualize your data.<br>However most out of the box solutions are not as beautiful as they could be, with default options.</p><p>I will show you how to customize your chart.js options to make some cool charts!</p><h3>⚡ Quick Start</h3><p>What we will use:</p><ul><li><a href="https://vuejs.org/">Vue.js</a></li><li><a href="http://vue-chartjs.org/">vue-chart.js</a></li><li><a href="https://github.com/vuejs/vue-cli">vue-cli</a></li></ul><p>We use <em>vue-cli</em> to create a basic structure. So I hope you got it installed already. And we use <em>vue-chart.js</em> as a wrapper for chart.js.</p><pre>vue init webpack awesome-charts</pre><p>Then we go into our project folder and install our dependencies.</p><pre>cd awesome-charts &amp;&amp; yarn install</pre><p>And we add <a href="http://vue-chartjs.org/">vue-chartjs</a> :</p><pre>yarn add vue-chartjs chart.js</pre><h3>Our first chart</h3><p>So, let’s create our first line chart.</p><pre>touch src/components/LineChart.js &amp;&amp; subl .</pre><p>Now we need to import the Line BaseChart from <a href="http://vue-chartjs.org/">vue-chartjs</a> and create our component.</p><p>In the <strong>mount()</strong> function we need to call the <strong>renderChart()</strong> method with our data and options.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d7b70aceb3b88e4ac4ad51fea58e2e5/href">https://medium.com/media/1d7b70aceb3b88e4ac4ad51fea58e2e5/href</a></iframe><p>We pass in a basic chart.js data object with some sample data and in the option parameter, we pass <strong>responsive: true. </strong>So the chart will grow brased on our outer container.</p><p>☝ We can call the method <strong>renderChart()</strong> because we extended the BaseChart, were this method and some props are defined</p><h4>Mount &amp; Test it</h4><p>Now we delete the Hello.vue component from our App.vue and import our chart.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72499df4c5d8055cf6fbfaa316b3c87e/href">https://medium.com/media/72499df4c5d8055cf6fbfaa316b3c87e/href</a></iframe><p>And after we run the dev script in our terminal, we should see our chart.</p><pre>yarn run dev </pre><h3>💄 Make me beautiful</h3><p>Okay, now it is time for some beautification 💅. There are a few cool tricks in chart.js. We can pass a color hex value to <strong>backgroundColor; </strong>But we can also pass a rgba() value. So we can make our color transparent. And as chart.js is using html canvas to draw, we can utilize <a href="https://developer.mozilla.org/de/docs/Web/API/CanvasRenderingContext2D/createLinearGradient">createLinearGradient()</a></p><p>This is where the fun starts. 🎢 But to use it we need the canvas object. But this is not a big deal, as <a href="http://vue-chartjs.org/">vue-chartjs</a> holds a reference to it. We can access it over <strong>this.$refs.canvas</strong></p><p>So in our LineChart.js we create two variables to store a gradient. Because we have to datasets.</p><p>Then we create two gradients:</p><pre>this.gradient = this.$refs.canvas<br> .getContext(‘2d’)<br> .createLinearGradient(0, 0, 0, 450)</pre><pre>this.gradient2 = this.$refs.canvas<br> .getContext(‘2d’)<br> .createLinearGradient(0, 0, 0, 450)</pre><p>There is another cool function we can use: <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasGradient/addColorStop">addColorStop()</a></p><p>We create three colorStops for each gradient. For 0%, 50% and 100%.</p><pre>this.gradient.addColorStop(0, ‘rgba(255, 0,0, 0.5)’)<br>this.gradient.addColorStop(0.5, ‘rgba(255, 0, 0, 0.25)’);<br>this.gradient.addColorStop(1, ‘rgba(255, 0, 0, 0)’);<br> <br>this.gradient2.addColorStop(0, ‘rgba(0, 231, 255, 0.9)’)<br>this.gradient2.addColorStop(0.5, ‘rgba(0, 231, 255, 0.25)’);<br>this.gradient2.addColorStop(1, ‘rgba(0, 231, 255, 0)’);</pre><p>Now we can pass <strong>this.gradient</strong> to <strong>backgroundColor</strong>. And we have a very nice gradient. To get a nicer effect we also set the borderColor to the individual color with an alpha of 1. (or we use the hex value) And set the borderWidth to 1 and last but not least the pointColor.</p><pre>borderColor: ‘#FC2525’, <br>pointBackgroundColor: ‘white’, <br>borderWidth: 1, <br>pointBorderColor: ‘white’,</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47895f52ff435fef0251cdaae0408fc1/href">https://medium.com/media/47895f52ff435fef0251cdaae0408fc1/href</a></iframe><h4>Presentation</h4><p>Last step is to add some styling to the container in our App.vue</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eec37d127b7e78095076b199dffc42a6/href">https://medium.com/media/eec37d127b7e78095076b199dffc42a6/href</a></iframe><h3>👏 Final Result</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dc_ghRRz_QPo-yoOUaCe9Q.png" /></figure><p>Happy coding!</p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28af584adc0a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/creating-stunning-charts-with-vue-js-and-chart-js-28af584adc0a">Creating stunning charts with Vue.js and Chart.js</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WordPress, Vue and Chart.js]]></title>
            <link>https://medium.com/@apertureless/wordpress-vue-and-chart-js-6b61493e289f?source=rss-78b6281cf144------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b61493e289f</guid>
            <category><![CDATA[charts]]></category>
            <category><![CDATA[charts-and-graphs]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kimchi]]></dc:creator>
            <pubDate>Sun, 19 Feb 2017 14:12:07 GMT</pubDate>
            <atom:updated>2017-02-19T14:12:07.791Z</atom:updated>
            <content:encoded><![CDATA[<p>Integrate Chart.js in your WordPress site and build fancy charts.</p><p>Well, data visualisation is a hot topic. In my day to day business I work a lot with WordPress and Vue.js. I can’t say how much I 💘 Vue.js and how much cleaner my workflow and code is, because of it.</p><p>Building large WordPress sites can be tricky, especially if you have a lot of interactions going on. But with Vue components, you can separate everything super clean.</p><p>From time to time, you may want to include some cool charts to enchant your articles with nice data and it’s pretty easy with vue and chart.js.</p><h3>Prerequisites</h3><ul><li>🔧 <a href="https://www.advancedcustomfields.com/">Advanced Custom Fields</a> (duh, could not live without ‘em)</li><li>⚡ <a href="https://vuejs.org/">Vue.js</a></li><li>📊 <a href="https://github.com/apertureless/vue-chartjs">vue-chart.js</a></li></ul><p>I am building most projects with the <a href="https://roots.io/bedrock/">bedrock</a> stack and <a href="https://roots.io/sage/">sage</a> as a starting theme. However you can actually implement it in every other theme, too.<br>However I am not going into detail how the build system works. I am using the sage webpack config, just a bit modified. If you’re using a different build system, you may have to change some of the steps and code examples.</p><p>Advanced Custom Fields are not essential to this, but they provide a super easy to use custom fields.</p><h3>Custom Fields</h3><p>So we first need to create some custom fields, to feed them with data.</p><p>We create a repeater field for the datasets, which contain subfields. One field to toggle the legend and one field for the x-axis labels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sOLE7czYRN5xE8vl1pt0DQ.png" /></figure><p>The subfields of the Dataset field are pretty straight forward. We have a label, color and the actual data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COdYVHfQd2Sw4FgG_Dkkcg.png" /></figure><p>Then we can fill our component with some sample data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TDeIj_YxVyrrfvFnVvcVuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K9eaqk0MGuF24FSk1q8ONQ.png" /><figcaption>Sample data. Published posts on medium and tumblr over the last 7 years</figcaption></figure><h3>Make it vue</h3><p>Now it is time to create our vue component. I expect that you already wired up vue to your WordPress site. We now have to install <a href="https://github.com/apertureless/vue-chartjs"><em>vue-chartjs</em></a> and create a bar chart component.</p><pre><br>npm install vue-chartjs -D<br></pre><h4>Create a bar chart component</h4><p>So we create a BarExample.js in our assets folder:</p><pre>import { Bar } from ‘vue-chartjs’</pre><pre>export default Bar.extend({<br> props: [“data”, “options”],<br> mounted () {<br>  this.renderChart(this.data, this.options)<br> }<br>})</pre><p>Thats the basic structure from the examples. We pass the data and chart options. Then we add it as a vue component in our main.js file.</p><p>The structure of the required data object for chart.js looks like this:</p><pre>{<br>      labels: [&#39;X Axis Label 1&#39;, &#39;X Axis Label 2&#39;],<br>      datasets: [<br>        {<br>          label: &#39;Data One&#39;,<br>          backgroundColor: &#39;#f87979&#39;,<br>          data: [40, 20, 12]<br>        }<br>      ]<br>}<br></pre><p>There are now two possibilities, how to build this object. One is, to build it up in php the second is to build it up in Javascript. I personally find it a bit ugly to build it up in php, so I do it in Javascript.</p><p>For this purpose I change our <em>BarExample. </em>And add two new properties: One for the x-axis labels and one for the datasets. Then I utilize computed properties to build it up.</p><pre>import { Bar } from &#39;vue-chartjs&#39;</pre><pre>export default Bar.extend({<br>  props: [&#39;labels&#39;, &#39;datasets&#39;],</pre><pre>  computed: {<br>    &#39;chartdata&#39;: function () {<br>      return {<br>        labels: this.labels,<br>        datasets: this.datasets<br>      }<br>    }<br>  },</pre><pre> mounted () {<br>    this.renderChart(this.chartdata, <br>    {responsive: true, maintainAspectRatio: false})<br>  }<br>})</pre><h3>Template</h3><p>Now it’s time to wire it up a bit. We create a template file for the acf content to have a clean component.</p><pre>&lt;?php if(have_rows(&#39;datasets&#39;)): ?&gt;<br>  &lt;?php<br>    $datasets = [];<br>   ?&gt;</pre><pre>&lt;?php while ( have_rows(&#39;datasets&#39;) ) : the_row();<br>    $datasets[] = array(<br>      &#39;label&#39; =&gt; get_sub_field(&#39;dataset_label&#39;),<br>      &#39;backgroundColor&#39; =&gt; get_sub_field(&#39;dataset_color&#39;),<br>      &#39;data&#39; =&gt; explode(&#39;, &#39;, get_sub_field(&#39;dataset_data&#39;))<br>    );<br>  endwhile;</pre><pre>$labels = get_field(&#39;x_axis&#39;);<br>  $legend = get_field(&#39;legend&#39;);</pre><pre>$chartDatasets = htmlspecialchars(json_encode($datasets));<br>  $chartLabels = htmlspecialchars(json_encode(explode(&#39;, &#39;, $labels)));</pre><pre>?&gt;</pre><pre>&lt;section class=&quot;chart-box text&quot;&gt;<br>  &lt;div class=&quot;text__wrapper&quot;&gt;<br>    &lt;bar-example<br>      :labels=&quot;&lt;?= $chartLabels; ?&gt;&quot;<br>      :datasets=&quot;&lt;?= $chartDatasets; ?&gt;&quot; &gt;<br>    &lt;/bar-example&gt;<br>  &lt;/div&gt;<br>&lt;/section&gt;<br>&lt;?php endif; ?&gt;</pre><p>Now you can add the php component to posts or pages and we have our beautiful chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ki_TZtjzLqKPTTomhcmvAg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b61493e289f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why you should do Open Source]]></title>
            <link>https://medium.com/@apertureless/why-you-should-do-open-source-3cce6ecd5f4e?source=rss-78b6281cf144------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cce6ecd5f4e</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kimchi]]></dc:creator>
            <pubDate>Wed, 16 Nov 2016 13:11:17 GMT</pubDate>
            <atom:updated>2016-11-16T13:11:17.277Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EoCyVk0uzD1HhOC6Sj6dTA.png" /></figure><h4>What I have learned and how I started</h4><p>Recently one of my <a href="https://github.com/apertureless/vue-chartjs">repos</a> on GitHub reached 100 stars. It’s not much if you compare it to many many other awesome repositories and projects. But for me it is awesome. Because it was more or less my first “bigger” open source project. Now I want to share what I’ve learned so far and how I started with open source.</p><p>Open Source was always that fascinated me, as I have a strong linux background. (I was using <a href="https://www.gentoo.org/">Gentoo</a> for many years) However I always wanted to contribute to projects and start own, it was kind of hard for me. I never felt that I was good enough to contribute to the big projects. And somehow I never had good ideas to start own projects that are useful.</p><h4>How I finally started doing open source</h4><p>Well until very recently I was using GitHub mostly for my university courses <a href="https://github.com/apertureless/whs-gui-prak">stuff</a>. But as I started working at <a href="http://www.nextindex.de/">nextindex</a> I was also writing some smaller scripts and tools for our workflows. For one project I was using <a href="http://nadarei.co/mina/">mina</a> to deploy it, and as we were using HipChat back then (switched to slack now) I wrote a little <a href="https://github.com/apertureless/mina-hipchat">notification script</a>. Well it got some downloads on rubygems but there was no real activity on github.</p><p>As we are using WordPress for most of our projects, there is no way around <a href="https://github.com/wp-cli/wp-cli">wp-cli</a>. It is like the most awesome tool ever! You can scaffold post-types, create users and do pretty much everything you want with a small cli command. Furthermore you can create own plugins which utilize some wp-cli features!</p><p>And as you are using something on a daily basis, you discover bugs. So did I. And like a good user, I wanted to submit an issue. But I discovered that someone else created it and it was labeled “<strong>good-first-issue”.</strong></p><p>So I looked up the source code and found where the bug is and the fix wasn’t very complicated. And as I am very impatient, I wanted to fix it by myself. So I forked wp-cli, created a fix branch and fixed the bug. And then, … submitted a PR.</p><blockquote>Welcome to the open source world!</blockquote><p>After a few hours I received an e-mail. Someone commented my PR. Well, as I fixed bug I also created new functions and the PR was missing tests. And I was asked to provide some tests. 😲 Oh man… I did some unit testing before, however wp-cli was using behat. But they got a pretty nice test coverage with many many different tests. So I could lookup how the other tests looked and forge my own test case. Then my PR got merged 🎊.</p><p>My very first open source contribution. After that, you could say the ice was broken. I fixed some other bugs on wp-cli and some other projects.</p><h4>What was important to start?</h4><p>I have to say, that it was really good to have this issues labeled with “<strong>good-first-issue” </strong>because it really invites people to at least try to fix them. Most of the time this issues are pretty simple and a good start. The heavy test coverage was also important, because you don’t have to setup the whole testing framework by yourself and spend hours learning the specific testing framework. With all these tests you have a lot of examples you can learn from.</p><h3>Vue-ChartJs</h3><p>Some month ago, we started a small hackathon at our company. And I was playing around with <a href="http://www.chartjs.org/">Chart.js</a> for some simple out-of-the-box charts. Because we are using <a href="https://vuejs.org/">Vue.js</a> for pretty much all of our projects I created <a href="https://github.com/apertureless/vue-chartjs">vue-chartjs</a>, which is a simple wrapper for Chart.js in Vue. Without thinking much about it, I put it on GitHub, because… why not, right?</p><p>Slowly it got a bit attention. It some some stars, some npm downloads. And people started to submit issues. Like the width and height props were not working correctly and feature requests for Vue 2, which was back then in RC state.</p><p>And people even submitted PRs with charts I forgot to implement. And at this point I realized, well open source is not only fun, it is also work! And then after I saw that vue-chartjs got a few hundert installs on npm I realized that real people were using it in real projects. Which was super scary. (As I had no test coverage 🙈 ) So the first thing I did, was to add some tests. Because I really did not want to break something while adding features or fixing bugs and push it on npm so people would install broken versions.</p><p>And I learned a lot about how vue.js works and testing javascript, while writing the tests. I would even say, I spend more time researching and writing tests, then writing features or fixes.</p><h4>What I’ve learned maintaining a project</h4><ul><li>Add tests to your open source projects. Really. Do it. There is nothing worse then the feeling that you’ve broken some production env. with a bad version of your code.</li><li>Add test coverage like <a href="https://codecov.io/">codecov</a>. And CI like <a href="https://travis-ci.org/">travis</a>. It will save you a lot of time.</li><li>People find bugs or request features, that you’ve never thought about.</li><li>Add a lot of examples and docs. It will reduce issues where people ask how to use your stuff!</li></ul><p>So, start doing open source! Follow frameworks, tools that you use and help the maintainers. It’s fun and you will learn a lot!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cce6ecd5f4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Notebook 00]]></title>
            <link>https://medium.com/@apertureless/notebook-00-af596e8c744b?source=rss-78b6281cf144------2</link>
            <guid isPermaLink="false">https://medium.com/p/af596e8c744b</guid>
            <category><![CDATA[zsh]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[ham-radio]]></category>
            <dc:creator><![CDATA[Kimchi]]></dc:creator>
            <pubDate>Tue, 15 Nov 2016 11:30:37 GMT</pubDate>
            <atom:updated>2016-11-15T11:30:37.164Z</atom:updated>
            <content:encoded><![CDATA[<h3>📓 Notebook 00</h3><h4>Random thoughts</h4><p><em>Notebook</em> is a new ongoing blogging series in which I talk about developing, music, cooking, apps and basically everything I write down in my paper notebook, day by day.</p><h4>Music</h4><p>I stumbled upon Föllakzoid, which is a fantastic psychedelic rock band. Enjoy!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fembed.spotify.com%2F%3Furi%3Dspotify%3Atrack%3A0c35I79bxG3qq2z12pL5Kc&amp;url=https%3A%2F%2Fopen.spotify.com%2Ftrack%2F0c35I79bxG3qq2z12pL5Kc&amp;image=https%3A%2F%2Fi.scdn.co%2Fimage%2Ffd26d4ffe0da2977058340965429489ecd534f2b&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=spotify" width="300" height="380" frameborder="0" scrolling="no"><a href="https://medium.com/media/75caaffc5a0e273f1b832c98b390016f/href">https://medium.com/media/75caaffc5a0e273f1b832c98b390016f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GuNxZxD_WdKukSLcOujeIA.png" /><figcaption>HyperTerm with pure prompt and hyper-snazzy theme</figcaption></figure><h4>Github Repo</h4><p>I recently installed <a href="https://github.com/sindresorhus/pure">pure</a>, which is a very beautiful, minimal and fast zsh prompt. I really like the simple style and with the <a href="https://github.com/sindresorhus/hyper-snazzy">hyper-snazzy</a> theme. I would really love the hyper-snazzy theme for sublime or vim, because the colours are fantastic.</p><h4>New Hobby — Ham Radio</h4><p>After watching a few very cool talks about ham radios from the ccc and defcon, I got pretty much psyched about it. So in the following weeks I will be learning for the license. It’s kind of interesting how different the licensing systems are. As far as I understand in there are 3 licenses in the US. Starting with more likely a “novice” license up to an advanced license. With each class you make, more frequencies get available to use. And you need to make all 3 in order. So you can’t start with the advanced one. However in the US it’s rather cheap. 15 $ per license and if you make all 3 in a row only 15 $ for all 3. And then you have to renew it every 10 years for free.</p><p>Well in Germany its way more expensive. We have here 2 license classes. class E for ‘Einsteiger’ or novice and class A for ‘advanced’. The E class costs about 80 $ and the A class about 110 $ . However you don’t need to make the E class first. You can start with the A class. The only difference is that the technical part is bigger and more in-depth. In addition you need a “callsign” which also costs about 70 €. And a frequency usage fee which is around 10 $ / year.</p><p>And you need to get some learning material. So my pocket will hate me, but most hobbies are expensive, right?</p><p>Let’s see how long it will take me, to get my license. I had some electronics in school, but it’s too long ago. But I have this semester physics and next one media technology which got a lot of electronics included, so I think I will benefit from it.</p><blockquote>I fear those big words which make us so unhappy.</blockquote><p>— “James Joyce”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af596e8c744b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Abenteuer mit Go und Vue]]></title>
            <link>https://medium.com/@apertureless/abenteuer-mit-go-und-vue-7765401f5051?source=rss-78b6281cf144------2</link>
            <guid isPermaLink="false">https://medium.com/p/7765401f5051</guid>
            <category><![CDATA[deutsch]]></category>
            <category><![CDATA[side-project]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Kimchi]]></dc:creator>
            <pubDate>Sun, 09 Oct 2016 14:25:22 GMT</pubDate>
            <atom:updated>2016-10-09T14:25:22.804Z</atom:updated>
            <content:encoded><![CDATA[<h3>Abenteuer mit Go und Vue.js</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6qKN5O1HQ_BY0x3rDxt_ow.png" /></figure><p>Der ein oder andere mag auf <a href="https://twitter.com/apertureless/status/784823736960688129">Twitter</a> schon mitbekommen haben, dass ich mich wieder etwas vermehrt mit Go beschäftige. Irgendwie mag ich Go. Ich weiß auch nicht genau warum. Die Sprache fühlt sich sehr nach dem Kind von C und Ruby an. Ich mochte C damals sehr. Jedenfalls mehr als C++. Was aber auch vielleicht an der Objekt-Orientiertheit lag.</p><h3>Jakub Juszczak on Twitter</h3><p>D</p><p>Jedenfalls habe ich jetzt ein kleines Sideproject gestartet. Mit Go und Vue.js. Was eigentlich eine super Kombination ist, da Go für das Backend zuständig ist und Vue für das Frontend. Ich mag z.B. auch Laravel sehr und auch das Micro Framework Lumen, jedoch finde ich es für viele Sachen einfach Overkill.</p><p>Und deswegen mag ich auch Go sehr, weil man extrem schnell kleine Programme, Services etc. schreiben kann, ohne viel overhead. Und der Vorteil an so einem Sideproject ist, dass man sich einfach mal mit einigen Themen auseinander setzt. Wie z.B. mit Go. Oder auch mit Vim. Da ich, wenn ich Go programmiere, vim benutze. Ich bin zwar ein großer Sublime Advokat, aber für Go finde ich Vim einfach deutlich angenehmer. Besonders das vim-go Plugin leistet tolle Arbeit mit auto fmt und shortcuts für go run, go build, go docs etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gc7EujKJAdAy6ebImx7Fcg.png" /><figcaption>Sketches</figcaption></figure><h4>Sideprojekt Backup Statistiken</h4><p>Wir benutzen auf der Arbeit seit kurzem Backup, was ein sehr cooles Ruby Gem ist um <a href="https://github.com/backup/backup">Backups</a> zu fahren. Man kann über eine DSL einfach seine Backup Models erstellen, unterstützt verschiedene Datenbanken, verschiedene Kompressionen, Verschlüsselung der Backups über OpenSSL oder GPG, verschiedene Storages und Syncers (S3, Rackspace, Dropbox, SCP etc.) Und hat dazu noch einige Notifier im petto, wie Email, Twitter, Slack, DataDog, Nagios, HTTP POST und einige anderen.</p><p>Wenn man nun sowas wie Nagios oder DataDog laufen hat, dann hat man ja Monitoring und Statistiken schon abgedeckt. Falls nicht, wäre es ja cool eine Übersicht der vergangenen Backups zu haben.</p><h4>Die Integration</h4><p>Die einfachste Version, ist einfach der kleine Go Service der läuft und eine einfache API hat um Backup Logs in einer sqlite zu speichern und abzurufen.</p><p>So kann man beim Backup Notifier einfach einen HTTP POST request an den Service schicken, mit Status des Backups (success, warning, failure), Start- und Endzeit, Duration und der Message.</p><h4>Das Dashboard</h4><p>Das Vue Frontend fragt dann die Daten ab und basierend auf der Message die idR den Model Namen beinhaltet, der sowas wie der Projektname ist, gruppiert es die Daten und erstellt einem schöne Karten pro Projekt mit Charts der letzten Backups.</p><p>So kann man auf einem Blick sehen, wie die Backups verlaufen sind und wo es Probleme gab. Zusätzlich könnte man noch Logs von z.B. S3 auswerten um Speicherauslastung und Kosten anzuzeigen.</p><h4>Status</h4><p>Das Go Backend läuft soweit. Ich bin jetzt noch dran das Frontend zu bauen. Wenn das fertig ist, wird nur noch ein Docker Image erstellt und dann auf <a href="https://github.com/apertureless">GitHub</a> geschmissen!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7765401f5051" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ich habe gerade kein bock auf dich, mag dich aber trotzdem]]></title>
            <link>https://medium.com/@apertureless/nur-weil-ich-kein-bock-auf-dich-habe-hei%C3%9Ft-es-nicht-dass-ich-1ff2ff522127?source=rss-78b6281cf144------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ff2ff522127</guid>
            <category><![CDATA[freundschaft]]></category>
            <category><![CDATA[blooger]]></category>
            <category><![CDATA[deutsch]]></category>
            <dc:creator><![CDATA[Kimchi]]></dc:creator>
            <pubDate>Sat, 08 Oct 2016 21:20:23 GMT</pubDate>
            <atom:updated>2016-10-08T21:22:36.881Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jSx1XHf8wSql3EE1LB7Pfg.jpeg" /></figure><p>Als ich vor kurzem meine Freundes Liste bei Facebook so durchgescrollt und aussortiert habe, musste ich viel über Freundschaft nachdenken. Wie gut befreundet man mit manchen Menschen doch eine Zeit lang war und wie schnell dann der Kontakt abgebrochen ist.</p><p>Wie man bei Stardew Valley gelernt hat, muss man seine sozialen Kontakte pflegen. Nicht nur in der virtuellen, sondern auch in der realen Welt. Das nimmt Zeit und oftmals Nerven in Anspruch und ist nicht jedermanns Sache. Ich persönlich bin ein sehr introvertierter Mensch und tue mich auch oft schwer mit sozialer Interaktion. Ich habe oft einfach Tage, wo ich mein Handy aus mache und keine Lust auf niemanden habe. Jede Form von sozialem Kontakt kommt mir dann äußerst lästig vor und unheimlich anstrengend.</p><p>Das wird oft missinterpretiert und die Menschen in meinem Umfeld glauben, dass ich sie nicht mag. Was auch irgendwie verständlich ist, wenn man sich eine längere Zeit nicht meldet. Aber man sollte diesen temporären Zustand von genereller Menschenabscheu nicht persönlich nehmen.</p><p>Etwas erleichtert stelle ich oft fest, dass ich nicht ganz alleine bin, mit dieser Einstellung. Ich kenne einige Menschen, die auch oft einfach mal keinen Bock auf andere Menschen haben, sich abschotten und unerreichbar scheinen. Um nun wieder auf das Thema Freundschaft zurück zu kommen, glaube ich, dass Freundschaft sich gerade dadurch definiert. Das man auch mal keinen Bock aufeinander haben kann, sogar den Kontakt für eine lange Zeit unterbrechen kann, aber dann, wenn man wieder Kontakt hat, es einfach so ist wie früher. Als wäre nichts gewesen.</p><p>Also liebe Menschen da draußen, seid euren Freunden nicht böse, nur weil die mal kein Bock auf euch haben.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ff2ff522127" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>