<?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 Hguot on Medium]]></title>
        <description><![CDATA[Stories by Hguot on Medium]]></description>
        <link>https://medium.com/@hguotblog?source=rss-317330aac290------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6tEPu0XT1NR4NnnvQ-nnKg.jpeg</url>
            <title>Stories by Hguot on Medium</title>
            <link>https://medium.com/@hguotblog?source=rss-317330aac290------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 11:24:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hguotblog/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[Use D3.js for Data Visualisation with Rails]]></title>
            <link>https://medium.com/@hguotblog/use-d3-js-for-data-visualisation-with-rails-69b4f030e366?source=rss-317330aac290------2</link>
            <guid isPermaLink="false">https://medium.com/p/69b4f030e366</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[3d]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Hguot]]></dc:creator>
            <pubDate>Tue, 24 Nov 2015 11:57:45 GMT</pubDate>
            <atom:updated>2015-11-24T11:58:07.579Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Install D3.js with gemfile</h3><p>We will use gem “d3-rails” (see <a href="https://github.com/iblue/d3-rails">https://github.com/iblue/d3-rails</a>) in this project. Add this line to your Gemfile:</p><pre>gem &quot;d3-rails&quot;</pre><p>D3.js will be provided via the asset pipeline and you don’t need to copy their files into your application. Rails will get them from d3-rails automatically. Then add it to your manifest file at app/assets/javascripts/application.js:</p><pre>//= require d3</pre><h3>2. Customise rails assets pipeline for “data folder” in assets folder</h3><p>Usually we only store images, JavaScripts and CSS in “Assets folder”. To store “data” in assets, we have to add this line in “application.rb” to customize the assets pipeline.</p><pre> config.assets.paths &lt;&lt; Rails.root.join(“data”)</pre><h3>3. Basic concept of D3.js</h3><p>D3.js is a library to bind datas and DOMs. There are three basic stages for our data.<br>1. Enter: Import the data which will create DOMs later.<br>2. Update: Update the data and change DOMs.<br>3. Exit: Remove DOMs when less data is shown after update.</p><p>Generally speaking, a common pattern is to break the initial selection into three parts: the updating nodes to modify, the entering nodes to add, and the exiting nodes to remove. In most cases, if you don’t remove unnecessary DOMs, performance will be increasingly poor.</p><h3>4. Draw with SVG</h3><ol><li>SVG area</li><li>scale</li><li>Import data</li><li>coerce to number</li></ol><pre>&lt;body&gt;<br>&lt;h1&gt;D3 TEST&lt;/h1&gt;<br>&lt;div id=”line-chart”&gt;&lt;/div&gt;<br>&lt;style&gt;<br>.chart {<br> border: 1px solid red;<br>}<br>.chart rect {<br> fill: steelblue;<br>}</pre><pre>.chart text {<br> fill: white;<br> font: 10px sans-serif;<br> text-anchor: end;<br>}</pre><pre>&lt;/style&gt;<br>&lt;svg class=”chart”&gt;&lt;/svg&gt;<br>&lt;script&gt;</pre><pre>// Data<br>// var data = [4, 8, 15, 16, 23, 42];</pre><pre>var width = 420,<br> barHeight = 20;</pre><pre>// Set the scale<br>var x = d3.scale.linear()<br> // .domain([0, d3.max(data)])<br> .range([0, width]);<br>var chart = d3.select(“.chart”)<br> .attr(“width”, width);</pre><pre>d3.tsv(“&lt;%= asset_path ‘example_data.tsv’ %&gt;”, type, function(error, data) {<br> x.domain([0, d3.max(data, function(d) { return d.value; })]);</pre><pre>chart.attr(“height”, barHeight * data.length);</pre><pre>var bar = chart.selectAll(“g”)<br> .data(data)<br> .enter().append(“g”)<br> .attr(“transform”, function(d, i) { return “translate(0,” + i * barHeight + “)”; });</pre><pre>bar.append(“rect”)<br> .attr(“width”, function(d) { return x(d.value); })<br> .attr(“height”, barHeight — 1);</pre><pre>bar.append(“text”)<br> .attr(“x”, function(d) { return x(d.value) — 3; })<br> .attr(“y”, barHeight / 2)<br> .attr(“dy”, “.35em”)<br> .text(function(d) { return d.value; });<br>});</pre><pre>function type(d) {<br> d.value = +d.value; // coerce to number<br> return d;<br>}</pre><pre>&lt;/script&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69b4f030e366" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A step-by-step guide to Set up a basic website with ruby on rails and deploy on heroku]]></title>
            <link>https://medium.com/@hguotblog/a-step-by-step-guide-to-set-up-a-basic-website-with-ruby-on-rails-and-deploy-on-heroku-528748e6e3e1?source=rss-317330aac290------2</link>
            <guid isPermaLink="false">https://medium.com/p/528748e6e3e1</guid>
            <dc:creator><![CDATA[Hguot]]></dc:creator>
            <pubDate>Mon, 20 Oct 2014 09:09:44 GMT</pubDate>
            <atom:updated>2014-11-05T02:57:08.510Z</atom:updated>
            <content:encoded><![CDATA[<h3>A step-by-step guide to Set up a basic website with Ruby on Rails and deploy it on Heroku</h3><p>Before you start to read this article, you have to know basic things in advance. here’s the list:</p><ol><li>Register on <a href="https://id.heroku.com/login">Heroku</a> and setup the ssh keys</li><li>Setup basic Rails development environment ( Ruby on Rails, Terminal )</li><li>Setup your development tools ( your favorite text editor and browser)</li><li>Know basic git command line and usage of Terminal</li></ol><blockquote>Ok, let’s get started. You just need only 15 minutes to go through the steps</blockquote><h3>1. Create your project named “skywalker”</h3><p>Open your Terminal and simply type as below.</p><pre>rails new skywalker</pre><h3>2. Go to “skywalker” project folder</h3><p>Don’t forget this step or you’ll code like a stupid in the next steps.</p><pre>cd skywalker</pre><h3>3. Setup templates and router</h3><p>Generate the “controller” for your website “pages”. The controller defines the methods which connect to your templates. In this case, we will generate a controller called “main”, and several 5 pages called “index”, “about”, “service”, “product” and “contact”.</p><pre>rails generate controller main</pre><p>Then open your file “app/controllers/main_controller.rb” and modified the file like this…</p><pre>class MainController &lt; ApplicationController<br>    def index<br> <br>    end<br>    def about<br> <br>    end<br>    def service<br> <br>    end<br>    def product<br> <br>    end<br>    def contact<br> <br>    end<br>end</pre><p>Now the controller is ready. Next, you have to add templates to present your pages. Add files “index.html.erb”, “about.html.erb”, “service.html.erb”, “product.html.erb” and “contact.html.erb” in “app/views/main”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*q04comHid_ZjU56UKqQ8lw.png" /></figure><p>Now the controller and templates are ready. Next, you have to tell Rails which page you are going to present in the browser when you type in the Url. Open the file “config/routes.rb” which is used to setup your Url. Modify the file like this…</p><pre>Rails.application.routes.draw do<br>    get ‘about’ =&gt; ‘main#about’<br>    get ‘service’ =&gt; ‘main#service’<br>    get ‘product’ =&gt; ‘main#product’<br>    get ‘contact’ =&gt; ‘main#contact’<br>    root ‘main#index’<br>end</pre><p>Let’s look at “ get ‘about’ =&gt; ‘main#about’ ”. This line means when you add ‘about’ to your url, Rails will go to “main” controller to find ‘about’ method which will call the template “view/main/about.html.erb” and you will see the “about” page in browser.</p><p>Then look at “ root ‘main#index’ ”. This line means when you add nothing after your Url , Rails will go to “main” controller and find the “index” to represent as your home page.</p><p>The last step before you run the server, open file “app/views/layouts/application.html.erb” and modify the file to add the navigation menu.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Demo&lt;/title&gt;<br>    &lt;%= stylesheet_link_tag ‘application’, media: ‘all’, ‘data-turbolinks-track’ =&gt; true %&gt;<br>    &lt;%= javascript_include_tag ‘application’, ‘data-turbolinks-track’ =&gt; true %&gt;<br>    &lt;%= csrf_meta_tags %&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;%= link_to ‘index’ , root_path %&gt;<br>    &lt;%= link_to ‘about’ , about_path %&gt;<br>    &lt;%= link_to ‘service’ , service_path %&gt;<br>    &lt;%= link_to ‘product’ , product_path %&gt;<br>    &lt;%= link_to ‘contact’ , contact_path %&gt;<br>    &lt;%= yield %&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Now run the Rails server. Open your Terminal and run this…</p><pre>rails s</pre><p>Go to <a href="http://localhost:3000/">http://localhost:3000/</a> in your browser. You should see you home page and the navigation links. Try to click the links to go to different pages.</p><h3>4. Setup your production environment</h3><p>Open the “gemfile” in your project. You’ll see a list of gems you are using.</p><p>Notice that there’s a gem called “sqlite” which is used in “development” environment. While we are going to deploy our site to “production” enviroment which is different from local “development” environment, we have to assign gems to different environment. In production environment, we use “pg” instead of “sqlite3”. In addition, we have to add a heroku-specific gem called “rails_12factor” which enables serving assets in production and setting your logger to standard out.</p><p>Now, your code should be like this…</p><pre>group :development do<br> gem &#39;sqlite3&#39;<br>end<br>group :production do<br> gem &#39;pg&#39;<br> gem &#39;rails_12factor&#39;<br>end</pre><p>Then open “config/environments/production.rb” and modify the “config.assets.compile” from “false” to “true”, which is for setting up assets for production environment. This setting is for serving assets on Heroku.<br>By default Rails 4 will not serve the assets.</p><pre>config.assets.compile = true</pre><p>Open Terminal, leave server mode and type:</p><pre>rake assets:precompile</pre><p>This procedure is important for express the “looking”, i.e CSS, of your site correctly.</p><h3>5. Deploy on Heroku</h3><p>Open your Terminal and type as below to initialize and assign commit to your project.</p><pre>git init<br>$ git add .<br>$ git commit -m &quot;init&quot;</pre><p>Before you push your code, we have to create a heroku project which links to your local files. Type a little more codes in Terminal…</p><pre>heroku create<br>git push heroku master</pre><p>Heroku will automatically assign you a random Url. Type “heroku open” in Terminal to open it.</p><pre>heroku open</pre><p>Boooooom! Skywlker is right there!</p><p>Now you can play with your website and share with friends on the internet. If you have any question, feel free to contact me. I speak English or basic Chinese. Here’s my email address: hguotblog@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=528748e6e3e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>