Showing posts with label build. Show all posts
Showing posts with label build. Show all posts

2015-05-20

Level Up - Ruby on Rails: How to create a very minimal blog website (two different ways)

As I was refreshing myself with Ruby on Rails, I've decided to share these notes. To follow these steps, you don't actually need to know any Ruby or Rails, but you should have them installed already. I'm using Ruby 2.1.5p273, Rails 4.2.0, Windows 8.1, but these steps are simple enough to do on any version.

I show two different ways to create a very code minimal blog. It also demonstrates the power of of Rails scaffolding.

Using scaffold


1. Just run the following commands one after another:

    rails new quick-blog
    cd quick-blog
    rails generate scaffold post title:string body:text
    rails generate scaffold comment post_id:integer body:text
    rake db:migrate

2. To create a post or comment, make sure that the `rails server` is started. Then, in browser, navigate to `/posts/new` or `/comments`.
3. Done


Without using scaffold


1. Run `rails new very-minimal-blog`
2. Run `cd very-minimal-blog`, then `rake db:create`
3. Create the model for the posts: Run `rails generate model Post title:string body:text`
4. Run `rake db:migrate`
5. Create a controller for the posts: Run `rails generate controller Posts`
6. In that controller that was just created in `app/controllers/posts_controller.rb`, add some code so that it looks like the following:

    class PostsController < ApplicationController
      def index
        @posts = Post.all
      end

      def show
        @post = Post.find(params[:id])
      end
    end

7. In `app/views/posts/`, create a new file called `index.html.erb` and add the following code:

   

Very Minimal Blog


    <% @posts.each do |post| %>
     

<%= post.title %>


      <%= link_to "Read me", post_path(post) %>
    <% end %>

8. Create a way to get to the posts. In `config/routes.rb` add, `resources :posts`
9. In `app/views/posts/`, create a new file called `show.html.erb` and add the following code:

   

<%= @post.title %>


    <%= @post.body %>

10. Done. :)


## To create a blog post ##
1. Open Rails console by running `rails console`
2. Run `Post.create(title: "My Title", body: "This is my awesome blog post!")`


## To view the blog ##
1. Start the Rails server by running `rails server`
2. Navigate to `localhost:3000/posts`


~ Danial Goodwin ~



2014-08-30

Level Up - Android: Speed up your Gradle build times with one-line!

Whether or not you are using Android Studio, Gradle build times are slow (especially when you don't have continuous automated builds (another discussion)).

Here's one way to improve the speed Gradle commands like `assembleRelease` is to enable the Gradle daemon. I've sped up my release builds by about 20%!

2014-02-20

Experience Publishing to Different App Platforms

Q: How do you gain experience in publishing apps to a certain platform?
A: You create 100 apps and publish them.

Q: How do you lose experience in publishing apps to a certain platform?
A: You create 100 apps and publish them. (Details below)

I don't think anybody actually asks the second question (but I just did!). Anyways, after the first few publishes, programmers/hackers get tired of the same routines. Our jobs are basically to automate things and makes things easier!

So, that's what I did and am doing. I'm starting to automate the entire process of publishing an app. There is this great tool that is a high-level scripting language called AutoHotkey. With it, I can easily open any program programatically, and send any keyboard and mouse commands that I want to the program. Basically, a macro builder for the entire end-user operating system.

About half of the process is automated now. I'm about halfway to my personal goal of 100 apps. My goal would be to make the entire process from app file to publish a one-click process. I know it's possible, and it'll be fun to build.

Once the process is all automated, I can be free to forget the process and start thinking of other abstractions to make.

;)
~ Danial Goodwin ~