Category: Tech

Posts related to tech.

Getting Started: With ember.js 2 + firebase + materialize css.

Introduction

This article assumes that you have some idea about programming and web development in general. I’ll still try to be as descriptive as possible.

The project associated with this article is on GitHub!
If you want to try it out, follow these instructions:

First, make sure you have the first three tools in “Part I – Acquiring the tools”.

Then, go to a folder where you would want to store the cloned project. Then, do this:

git clone https://github.com/jayantbh/shoutout.git shoutout_clone
cd shoutout_clone
git reset --hard 12289dc050d60156804e58cede11e73db96bbb04
npm install
bower install
ember server

This project is also available for viewing live on https://shoutoutdb.firebaseapp.com/.

Part I – Acquiring the tools

Tools you’ll need and how to install them:
Note: I’m assuming you have an idea of how node and npm works. Even it not, won’t really matter too much.

  • node.js and npm
    • Installing npm from a simple apt-get install gives you the v10.x.x of node.js. I, or anyone else will suggest installing the following way:
      • sudo apt-get install curl
        curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
        sudo apt-get install nodejs
        
  • bower
    • npm install -g bower
  • ember-cli
    • npm install -g ember-cli
  • emberfire
    • emberfire is a Firebase adapter for ember.js, don’t worry about it, we’ll discuss it later in the article. This must be installed after ember-cli has been installed.
      • ember install emberfire
  • phantom.js 2 (kinda optional)
    • Ember uses Phantom for running automated tests. But since we’re not gonna talk about running tests here, we won’t really be using it. In case ember throws up errors saying it needs phantom.js, you can install this, this way. Phantom.js 1 won’t really work here.
      • npm install -g phantomjs2
  • materialize css (optional)
    • Materialize CSS is a front-end design framework based on Google’s Material Design. I’ll talk about this wherever needed as I’ve used this in the project. If you’re more familiar with Twitter Bootstrap, you should be able to change most of this code into Bootstrap with minimal effort.
      • npm install -g ember-cli-materialize --save
        ember g ember-cli-materialize
  • js cookie (optional)
    • It is a pure JS cookie utility library. We’re using this in the project, so if you want to follow exactly as I go, you will need to use this when needed.
      • Obtain from THIS link.
  • ember inspector, chrome/firefox extension (optional, but very useful)
    • This is just like the chrome/firefox/etc inspector that you’re familiar with, but for ember.js apps. It shows you all the routes you’re using, and available to you, all the data in your ember app, ember element nesting, and tons of other stuff.

Part II – Getting started

Now that you’ve acquired pretty much all the tools needed to get started, let’s talk about how you’d move ahead.
Note: I’m using ubuntu, even then, all ember related commands will remain the same.

Initialize the project

Go to the folder you intend to generate your project in. For the sake of similarity with my existing code, we’ll call the project name as “ShoutOut”.
So my intended project folder will be “shoutout”. We use all lowercase because some tools have problems with uppercase letters.

jayantbhawal@px:~$ cd Projects/
jayantbhawal@px:~/Projects$ ember new shoutout

The command: ember new shoutout creates a new folder named “shoutout” and generates the default ember app structure with files inside it.
You’ll see a ton of files and folders being created and some npm installs, and then bower installs. You now have to navigate into the project folder, and run the server.

jayantbhawal@px:~/Projects$ cd shoutout
jayantbhawal@px:~/Projects/shoutout$ ember server

This automatically starts a server at the default port 4200. Your project is now viewable at http://localhost:4200
To change the port at which you want to start the server at, do this, and you can replace 1234 with any number under 65535 and over 1000, to be safe:

ember server --port 1234

OR

ember s --port 1234

Note: “s” is an alias for “server” in ember-cli.

You should be seeing one piece of text in big letters saying Welcome to Ember.js”. This piece of text comes from a Handlebars template file at “app/templates/application.hbs“.

If you haven’t already, now would be a great time to fire up your code editor and load the project.

My recommended code editors in order of preference are:

  1. WebStorm 10
  2. Sublime Text 3
  3. Notepad++

Important Note: If you don’t know how to configure WebStorm at all, you may want to stick to Sublime Text 3. I may add the required configuration for WS10 later.

Now if you’ve launched the editor, let’s deal with some odd-jobs and tiny annoyances. Listing them:

  1. Open “shoutout/config/environment.js”, find a line saying,
    firebase: 'https://[YOUR-FIREBASEIO-URL].firebaseio.com/',

    to this

    firebase: 'https://shoutoutdb.firebaseio.com/',

    or leave it as it is now, we’ll get back to it later.

  2. Open “shoutout/package.json”, and remove a line that has:
    "ember-cli-content-security-policy":"[some-version]"

    The text may not be exactly same, but you’ll get it. Remove the whole line.

  3. Go to “shoutout/public”, create a folder named “public”, create a subfolder named “js” or whatever you prefer to store your javascript files in, and store this file there.
  4. Now, restart your server. To this, use CTRL+C to stop the running server, and start the server again. You should notice that if you were noticing some “content security policy violation” errors or messages before, they’re gone, which is genuinely a relief.

One last thing to explain before we start, the meanings of the directory structure of your app, and some guide regarding how to use the Ember-CLI, courtesy of Ember-CLI user guide.

Folder Layout

File/directory Purpose
app/ Contains your Ember application’s code. Javascript files in this directory are compiled through the ES6 module transpiler and concatenated into a file called .js. See the table below for more details.
dist/ Contains the distributable (optimized and self-contained) output of your application. Deploy this to your server!
public/ This directory will be copied verbatim into the root of your built application. Use this for assets that don’t have a build step, such as images or fonts.
tests/ Includes your app’s unit and integration tests, as well as various helpers to load and run the tests.
tmp/ Temporary application build-step and debug output.
bower_components/ Bower dependencies (both default and user-installed).
node_modules/ npm dependencies (both default and user-installed).
vendor/ Your external dependencies not installed with Bower or npm.
.jshintrc JSHint configuration.
.gitignore Git configuration for ignored files.
ember-cli-build.js Contains the build specification for Broccoli.
bower.json Bower configuration and dependency list. See Managing Dependencies.
package.json npm configuration and dependency list. Mainly used to list the dependencies needed for asset compilation.

Layout within app directory

File/directory Purpose
app/app.js Your application’s entry point. This is the first executed module.
app/index.html The only page of your single-page app! Includes dependencies, and kickstarts your Ember application. See app/index.html.
app/router.js Your route configuration. The routes defined here correspond to routes in app/routes/.
app/styles/ Contains your stylesheets, whether SASS, LESS, Stylus, Compass, or plain CSS (though only one type is allowed, see Asset Compilation). These are all compiled into .css.
app/templates/ Your HTMLBars templates. These are compiled to /dist/assets/.js. The templates are named the same as their filename, minus the extension (i.e.templates/foo/bar.hbs -> foo/bar).
app/controllers/,app/models/, etc. Modules resolved by the Ember CLI resolver. See Using Modules & the Resolver.

app/index.html

The app/index.html file lays the foundation for your application. This is where the basic DOM structure is laid out, the title attribute is set, and stylesheet/javascript includes are done. In addition to this, app/index.html includes multiple hooks – {{content-for 'head'}} and {{content-for 'body'}} – that can be used by addons to inject content into your application’s head or body. These hooks need to be left in place for your application to function properly however, they can be safely ignored unless you are directly working with a particular addon.

Using Ember CLI

Command Purpose
ember Prints out a list of available commands.
ember new Creates a directory called and in it, generates an application structure. If git is available the directory will be initialized as a git repository and an initial commit will be created. Use --skip-git flag to disable this feature.
ember init Generates an application structure in the current directory.
ember build Builds the application into the dist/ directory (customize via the --output-path flag). Use the --environment flag to specify the build environment (defaults to development). Use the --watch flag to keep the process running and rebuilding when changes occur.
ember server Starts the server. The default port is 4200. Use the --proxy flag to proxy all ajax requests to the given address. For example,ember server --proxy http://127.0.0.1:8080 will proxy all ajax requests to the server running at http://127.0.0.1:8080.
ember generate Runs a specific generator. To see available generators, run ember help generate.
ember destroy Removes code created by the generate command. If the code was generated with the --pod flag, you must use the same flag when running thedestroy command.
ember test Run tests with Testem in CI mode. You can pass any options to Testem through a testem.json file. By default, Ember CLI will search for it under your project’s root. Alternatively, you can specify a config-file.
ember install Installs the given addon into your project and saves it to the package.json file. If provided, the command will run the addon’s default blueprint.

 

You may also want to know how Handlebars templates are used.

And if you feel a bit lost, you can look around the official emberjs user-guide.

You’re done. Time to start coding our application.

Part III – Diving into the code

You are about to build a simple ember app that allows users to post on a public feed.
The goal is to let them create a user profile that will be stored locally in the browser cookies, and let them post stuff on the feed.

We intend to make a single page app, where the major application logic works under one route.
Note: If you’re confused by any term, don’t worry, follow along, you’ll understand.

Section A – Configuring Routes

Let’s start with creating two routes.

ember generate route index
ember generate route profile

You can also replace “generate” with “g”.

You should see something like this, for once each for both the commands.

jayantbhawal@px:~/Projects/shoutout$ ember g route index
version: 1.13.8
Could not find watchman, falling back to NodeWatcher for file system events.
Visit http://www.ember-cli.com/user-guide/#watchman for more info.
installing route
create app/routes/index.js
create app/templates/index.hbs
updating router
add route index
installing route-index
create tests/unit/routes/index-test.js

For the attentive ones, you see version: 1.13.8 although the article mentions version 2. That is the version that comes with the latest ember-cli, and even according to it’s developers, it’s just emberjs 2 in disguise.

Now open app/router.js.

import Ember from 'ember';
import config from './config/environment';

var Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
  this.route('index', {path:'/'});
  this.route('profile', {});
});

export default Router;

It should look like this, except the {path:’/’} in the index route declaration. You have to add that.
That tells the app to load anything related to the index route when the user loads localhost:4200 (or whatever your port is).
We did not pass any path parameter to the profile route, so by default it’ll try to load anything related to the profile route on the path: ‘/profile’.

Section B – Working on the ‘application’ template

The app/templates/application.hbs template has stuff that needs to be persistent throughout the app. You can add things such as a Navigation Bar or a site-wide footer here.

Your application.hbs must be looking nearly empty, in my case, I’ve added a navbar built with Materialize.

Open app/templates/application.hbs.

<nav>
    <div class="nav-wrapper">
      <div style="margin-left: 20px;">{{#link-to 'index' class='brand-logo'}}ShoutOut! <span class="grey-text text-lighten-2" style="font-size: 0.5em;">v0.3a</span>{{/link-to}}</div>
      <ul id="nav-mobile" class="right">
         <li>{{#link-to 'profile'}}Profile{{/link-to}}</li>
      </ul>
   </div>
</nav>
<div class="container">{{outlet}}</div>

{{!-- ember-cli-materialize modal container --}}
{{md-modal-container}}

New stuff!

  1. {{#link-to ‘route-name’ …additional parameters…}} someText {{/link-to}}
    This is called a link-to helper. Helpers are things in ember.js that “help” you perform certain actions. The link-to helper helps you to switch the route, and hence the view of the page without having to reload the entire app.
  2. {{outlet}}
    While not exactly useful here, the outlet component loads any data from any nested routes. Our app won’t be using nested routes because we don’t need to.
    Note that the rest of the entire application is going to be rendered in the {{outlet}} above. Reasons is described below.
    Either way, here is some information about nested routes and how outlet works, that you can skip for now if you want to focus on building the app first.

    1. Nested Routes
      If you had a posts route, you would expect it to load all posts. If you had a posts/1, posts/2 … route, you would expect these routes to load posts with IDs 1, 2, … .
      Now, assume that your app is divided into two vertical parts. The left part has a list of post titles. The right shows the content of whatever post title is clicked. In this scenario, the content in your app/template/posts.hbs would be consisting of mostly the left part. The right part would only have one thing. That is…
    2. Outlet
      The outlet component shows content from its child route./posts/1 is a child route of /posts. So when /posts/1 loads the data of only the post, that data is shown nicely fitting inside the parent route of /posts.
    3. Generating Child Routes
      Child routes can be generated with ember-cli this way:

      ember g route posts/post
  3. {{md-modal-container}}
    That is a result of using ember-cli-materialize, and won’t be there otherwise. It’s used for modals in Materialize. Interesting stuff.
  4. {{!– … –}}
    This is how comments are used in Handlebars.

Section C – Working on the ‘index’ route.

We’re going to have two main things on our index page. One post input area, one post feed area. It’s a good practice to break a big page into smaller components in handlebars.

Note: You’ll be needing quite a few components now, to generate components using ember-cli, do this:

ember g component my-component-name

This is how the page looks like after I’m done.

Open app/templates/index.hbs.

<div class="row">
   <div class="col s12 m8 offset-m2">
        <h2 class="tooltipped" data-position="bottom" data-delay="50" data-tooltip="No, no one actually shouts, in case you thought that.">Shout feed</h2>
   </div>
</div>
{{post-input action='addPost'}}
{{#post-feed posts=model}}
   {{outlet}}
{{/post-feed}}

New Stuff!

  1. {{post-input action=’addPost’}} is a component in ember.js. action is like an HTML attribute, except that we can have any kind of user-defined attributes here.
    Important Note: Think of components as some kind of alternate HTML5 tags. If you notice, post-input looks like a self closing tag. #post-feed looks like a tag that has an additional closing tag, like most tags.  Components that need a closing tag are prefixed by a #. All components can be self-closing, or not. In my case, in case you haven’t figured out already, due to the absence of any sub-routes, the outlet is useless, so #post-feed might as well have been a self closing tag.
  2. Data Downs, Actions Up. This is a rule-of-hand, that you should pass data down into the layers of components, and retrieve actions generated by the components. In this case, the app/routes/index.js file is the file responsible for handling everything about app/templates/index.hbs, notice the same name? Then post-input component sends an action, the index route file will receive and act upon it, and when the index route file gets some data, it passes that into the post-feed component, where that data is passed into HTML tags and rendered. Both the components have their respective JS files for handing data and passing actions and etc.
  3. Tooltip. That is a Materialize thing. Pretty handy.

 

Generating components:

Components can be generated using:

ember g component your-component-name

Let’s look at the component templates after I’m done working on them:

app/templates/components/post-input.hbs

<div class="row">
    <form class="col s12 m8 offset-m2" {{action 'submitPost' on='submit'}}>
        <div class="row">
            <div class="input-field col s12">
            {{input id='new-post-title' type='text' value=postTitle}}
                <label for="new-post-title">Post Title</label>
         </div>
            <div class="input-field col s12">
            {{textarea id='new-post-body' class='materialize-textarea' value=postBody}}
                <label for="new-post-body">Post Body</label>
         </div>
            <div class="input-field col s12">
                <button class="btn">Shout<i class="mdi-content-send right"></i></button>
            </div>
        </div>
    </form>
</div>

New Stuff!

  1. input and textarea helpers. When using any kind of form fields in your app, the problem with using standard HTML tags would be that, ember won’t be able to bind itself to it. Using these helpers allows ember to implement something called data-binding. Now when the user enters values in then, these values are immediately reflected in this compoents JS file and in the local ember data-store.
  2. {{action ‘submitPost’ on=’submit’}}
    This means, when the form is submitted, the post-input (this component) will generate an action that will invoke the submitPost function in the app/components/post-input.js file. We’ll look into that soon.

app/templates/components/post-feed.hbs

{{#if posts}}
    <ul class="post-feed col s12 m8 offset-m2">
      {{#each posts as |post|}}
            <li class="post-item">
            {{post-item post=post}}
            </li>
      {{/each}}
    </ul>
{{else}}
    <div class="center" style="width:100%;">
        <h5>No cookie for you.</h5>
        <h6>No shouts available.</h6>
    </div>
{{/if}}

New Stuff!

  1. Conditionals. Statements like if and unless are implemented as built-in helpers. It’ll be great if you read about these in detail on ember guides.
  2. Iterators. Read about how to iterate over a list of items here and here.
  3. What’s happening here? You have seen in app/templates/index.hbs that we passed a model value to a posts attribute in the posts-feed tag. (Note: They aren’t officially called attributes or tags, I’m just using those terms so that you can relate better with HTML). We see that this model, that we’ll later find out contains a list of posts, is now being processed as the variable posts inside the template. the #each helper takes the list posts and iterates it through the variable post, which we see is subsequently passed into a smaller component named post-item. It should be obvious what it’s doing there.
  4. Note: posts is actually a JSON array. So post will be a JSON object in each iteration of that object array.

app/templates/components/post-item.hbs

<div class="col s12">
    <div class="card" style="min-height: 240px;">
        <div class="card-content">
            <span class="card-title grey-text text-darken-4 activator">{{post.title}}<i class="mdi-navigation-more-vert right waves-effect"></i></span>
            <p class="">{{post.body}}</p>
        </div>
        <div class="card-reveal">
            <span class="card-title grey-text text-darken-4">About {{post.userFullName}}<i class="mdi-navigation-close right waves-effect"></i></span>
            <p>{{post.aboutUser}}</p>
            <p>Email: <a href="mailto:{{post.newUser}}?subject=Connecting%20through%20ShoutOut&amp;body=Hey%2C%20I'm%20%5Benter-name%5D%2C%20I%20saw%20your%20shout%20on%20shoutout%20and%20found%20it%20interesting%2C%20how%20about%20we%20get%20in%20touch%3F" target="_blank">{{post.newUser}}</a></p>
            <p>Born on: {{post.userDOB}}</p>
            <p>Gender: {{post.gender}}</p>
        </div>
    </div>
    <span style="display: none;" class="post-time">{{post.postTime}}</span>
</div>

Since post was a JSON object, the variables in it are referenced the way usual JSON object keys are referenced.

 

We’ll now look at their respective JS files.

app/components/post-item.js

import Ember from 'ember';

export default Ember.Component.extend({
   classNames: ['row'],
   willRender: function () {
      console.log('Post rendered!')
   }
});

New Stuff!

  1. classNames: [‘row’], by default, your components are rendered inside a div tag generated by ember. You can add classes to that tag using the classNames property of a component.
  2. tagName: ‘li’, although not used here, even though there were multiple opportunities of using it, this property of a component does exactly what you might guess. By default, the tag that ember contains your component code in is a DIV tag, you can use this property to change that.
  3. willRender(), it is a component lifecycle hook that executes immediately before a component will be rendered. So in my case, if my app has 10 posts, the post-item template is getting rendered 10 times, and this function will be executed 10 times. There are many more lifecycle functions. Unfortunately, you’ll have to google that up.

app/components/post-feed.js

import Ember from 'ember';

export default Ember.Component.extend({
   postStatus: 'loading',
   classNames: ['row'],
   didRender: function () {
      let secondLastPostTime = $(".post-item:nth-last-child(2) .row .post-time").text();
      let lastPost = $(".post-item:last");
      let lastPostTime = $(".post-item:last .row .post-time").text();

      if(lastPostTime>secondLastPostTime){
         $(".post-item:last").remove();
         lastPost.css('display','none');
         $(".post-feed").prepend(lastPost);
         lastPost.slideDown(500);
      }
      $(document).ready(function(){
         $('.tooltipped').tooltip({delay: 50});
      });
   }
});

There’s some extra stuff here, that you don’t need to know right now, so focus on only that I’m going to mention:

New Stuff!

  1. didRender(), is it another ember component lifecycle hook that executes right after a component was rendered. In my case, the post feed will be rendered only when the page is loaded, or a new post is added.

app/components/post-input.js

import Ember from 'ember';

export default Ember.Component.extend({
   postTitle: '',
   postBody: '',
   actions: {
      submitPost(){
         let title = this.get('postTitle');
         let body = this.get('postBody');
         this.set('postTitle','');
         this.set('postBody','');
         if(title.length>0 && body.length>0){
            this.sendAction('action',title,body);
         }
         else{
            Materialize.toast('Both post title and body need to be entered.',3000);
         }
         //console.log(title)
      }
   }
});

Now this is where things start to get interesting.

New Stuff!

  1. Data-bindings, remember in it’s respective template files, we had postTitle bound to an input helper and postBody bound to a textarea helper? This is where it is accessible. On submitting the form, the action submitPost was executed. Inside this function, we can get() values that were bound to helpers in that template.
  2. sendAction(‘action’,title,body), scroll up and see that in the index.hbs template, you’ll see, it has an attribute named action and it invokes a function called addPost. Now we’ll see what it does and how it’s handled, and why whatever it does, wasn’t done right in this file.

app/routes/index.js 

import Ember from 'ember';

export default Ember.Route.extend({
   beforeModel: function () {
      let userdata = Cookies.getJSON('userdata');
      if(userdata){
         //load some data into the index template
      }
      else{
         //this.transitionTo('profile');
         //console.log('no user');
      }
   },
   model(){
      return this.store.query('post-item',{orderBy:'postTime', async: true});
   },
   actions: {
      addPost(title,body){
         let userdata = Cookies.getJSON('userdata');
         this.store.createRecord('post-item',{
            title: title,
            body: body,

            userFullName: userdata.userFullName,
            gender: userdata.gender,
            newUser: userdata.newUser,
            aboutUser: userdata.aboutUser,
            userDOB: userdata.userDOB
         }).save();
         console.log(title)
      }
   }
});

New Stuff!

  1. Route file, this file is the main file that handles all the functionality under a certain route with the same path name, unless a seperate pathname is specified in the router.js.
  2. beforeModel(), this route lifecycle hook executes before the data for this route is fetched by the model() function.
  3. model(), this function gets the data into a model associated with the app. We’ll discuss models soon.
  4. actions{}, you have seen this in multiple files by now. actions{}, specifies the functions this router can perform. In index.hbs, the post-input component sent an action via the sendAction() method with two parameters, that action was received by the router, and transferred to the addPost(), method with the same parameters.
  5. transitionTo(), in the beforeModel(), transitionTo() has been commented out here for tutorial reasons, but you should know, in case you want to change the route programmatically instead of having the use click on a link-to helper, you can use transitionTo(‘route-name’) function as specified.

 

Section D – Learning about models

You can learn all you need about ember.js models here.

Here are some of the important parts.

Models are objects that represent the underlying data that your application presents to the user. Different apps will have very different models, depending on what problems they’re trying to solve.

For example, a photo sharing application might have a Photo model to represent a particular photo, and a PhotoAlbum that represents a group of photos. In contrast, an online shopping app would probably have different models, like ShoppingCart, Invoice, or LineItem.

Models tend to be persistent. That means the user does not expect model data to be lost when they close their browser window. To make sure no data is lost, if the user makes changes to a model, you need to store the model data somewhere that it will not be lost.

Typically, most models are loaded from and saved to a server that uses a database to store data. Usually you will send JSON representations of models back and forth to an HTTP server that you have written. However, Ember makes it easy to use other durable storage, such as saving to the user’s hard disk with IndexedDB, or hosted storage solutions that let you avoid writing and hosting your own servers.

Ember Data, included by default when you create a new application, is a library that integrates tightly with Ember to make it easy to retrieve models from your server as JSON, save updates back to the server, and create new models in the browser.

Thanks to its use of the adapter pattern, Ember Data can be configured to work with many different kinds of backends. There is an entire ecosystem of adapters that allow your Ember app to talk to different types of servers without you writing any networking code.

This is how you use ember-cli to generate a model:

ember g model my-model key1:string key2:number key3:date key4:one-of-the-4-data-types

This is how our model looks like:

import DS from 'ember-data';

export default DS.Model.extend({
   title: DS.attr('string'),
   body: DS.attr('string'),
   userFullName: DS.attr('string'),
   gender: DS.attr('string'),
   newUser: DS.attr('string'),
   aboutUser: DS.attr('string'),
   userDOB: DS.attr('string'),
   postTime: DS.attr('number',{
      defaultValue: function () {
         return new Date().getTime()*(-1);
      }
   })
});

It’s not hard to guess how this may have been generated, however, postTime needs to be hand-typed anyway.

Part IV – Getting it over with

By now, your app is pretty much ready. However, if you never used Firebase, you probably got stuck with it earlier, and here we are, back to it.

Let’s get started!

  1. Go to https://www.firebase.com/signup/ and sign up.
  2. Once logged in, create your new app. If you name your add something like myfirstemberapp, your firebase URL would be myfirstemberapp.firebaseio.com, and that’s why choosing project names or URLs here would be like choosing usernames.
  3. Get the URL you just created and paste it where you were asked you in Part I.
  4. That is literally it.

Now you have the ability to share posts in real-time with other users and sync it in a firebase DB all with just this much effort.

Part V – Conclusion

So, did your app work? If not, what went wrong? If yes, congratulations! Did you have any difficulty? Where so? How do you think I can improve this tutorial? I will improve and expand it further anyway actually. Till then, feedback is welcome. 🙂

A glimpse of undefined behavior in C

Reblogged from “A glimpse of undefined behavior in C” at Christopher Cole’s blog, “Christopher Cole” .

Hey! Today I was practicing my first year CS201 programming language, C, when I came across a puzzling situation. Several lines of the following code gave different output on different compilers. Which also differed from what the output should logically be.

#include
int main()
{
        int i=5;
        printf("%d %d %d\n",i,++i,i++); //7 7 5
        i=5;
        printf("%d %d %d\n",i,i++,++i); //7 6 7
        i=5;
        printf("%d %d %d\n",i,++i,++i); //7 7 7
        i=5;
        printf("%d %d %d\n",i,i++,i++); //7 6 5
        i=5;
        printf("%d %d %d\n",i++,i++,i); //6 5 7
        i=1;
        printf("%d %d %d\n",i++,i++,i); //2 1 3
        return 0;
}

And so I started googling the possible reasons for that happening. Several stack exchange pages told me that this is an “Undefined Behaviour” that happens in C and C++. But why would it be undefined? What really goes on behind the scenes? Asking my friends for help on facebook led me to the aforementioned blog post that breaks the program down to assembly language which helped me understand what was really going on. I’ve reblogged that post here. Hope it helps. Also, I should mention that this didn’t help me understand WHY it was happening. I merely assumed that it was happening because of the way the compiler processes the code.

Here is the reblogged post.

A few weeks ago a coworker of mine stopped by my desk with a coding question. We’d recently been quizzing each other over our C knowledge, so I smiled and braced myself for the hell which was clearly to come.

He wrote a few lines of code up on the whiteboard and asked what the program output:

#include
int main(){
int i = 0;
int a[] = {10,20,30};

int r = 1 * a[i++] + 2 * a[i++] + 3 * a[i++];
printf("%d\n", r);
return 0;
}

It seemed pretty straightforward. I explained the order of operator precedence – postfix binds before multiplication which binds before addition and also that multiplication and addition’s associativity was left to right, so I grabbed the marker and started writing out the arithmetic.

int r = 1 * a[i++] + 2 * a[i++] + 3 * a[i++];
// = a[0] + 2 * a[1] + 3 * a[2];
// = 10 + 40 + 90;
// = 140

After I smugly scribbled down the answer, my coworker replied a simple “nope”. I thought for a few minutes, and was stumped. I couldn’t quite remember the order of the postfix operators’ associativity. Furthermore, I knew that wouldn’t even change the order of evaluation here as associativity rules only apply between operators of the same precedence level, but thought I’d give it a shot and walk through the arithmetic as if the postfix operators were all evaluated right to left.

int r = 1 * a[i++] + 2 * a[i++] + 3 * a[i++];
// = a[2] + 2 * a[1] + 3 * a[0];
// = 30 + 40 + 30;
// = 100

Again, my coworker replied it was still wrong. At this point I threw up my hands and asked what the answer was. It turned out that this small sample was actually reduced from a larger code snippet he’d put together. To verify his question, he’d compiled and run the larger sample but was surprised to see it not behave as he’d thought. After reducing the unexpected behavior to this illuminating example, he’d compiled it with gcc 4.7.3 and it output a startling result: “60″.

At this point I was intrigued. I remembered that, in C, the order of function argument evaluation was undefined, so we thought maybe the postfix operators were just being evaluated in some random non-left-to-right order. Still convinced that postfix had a higher operator precedence than addition and multiplication, we quickly proved to ourselves that there was no order we could evaluate the i++’s such that the three elements of the array were added/multiplied together to get “60″.

Now I was hooked. My first thought was to look at the disassembly of the snippet and try and track down what was actually going on. I compiled the sample with debugging symbols and after a quick objdump we had the source-annotated x86_64 disassembly:

Disassembly of section .text:

0000000000000000 :
#include

int main(){
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 83 ec 20 sub $0x20,%rsp
int i = 0;
8: c7 45 e8 00 00 00 00 movl $0x0,-0x18(%rbp)
int a[] = {10,20,30};
f: c7 45 f0 0a 00 00 00 movl $0xa,-0x10(%rbp)
16: c7 45 f4 14 00 00 00 movl $0x14,-0xc(%rbp)
1d: c7 45 f8 1e 00 00 00 movl $0x1e,-0x8(%rbp)
int r = 1 * a[i++] + 2 * a[i++] + 3 * a[i++];
24: 8b 45 e8 mov -0x18(%rbp),%eax
27: 48 98 cltq
29: 8b 54 85 f0 mov -0x10(%rbp,%rax,4),%edx
2d: 8b 45 e8 mov -0x18(%rbp),%eax
30: 48 98 cltq
32: 8b 44 85 f0 mov -0x10(%rbp,%rax,4),%eax
36: 01 c0 add %eax,%eax
38: 8d 0c 02 lea (%rdx,%rax,1),%ecx
3b: 8b 45 e8 mov -0x18(%rbp),%eax
3e: 48 98 cltq
40: 8b 54 85 f0 mov -0x10(%rbp,%rax,4),%edx
44: 89 d0 mov %edx,%eax
46: 01 c0 add %eax,%eax
48: 01 d0 add %edx,%eax
4a: 01 c8 add %ecx,%eax
4c: 89 45 ec mov %eax,-0x14(%rbp)
4f: 83 45 e8 01 addl $0x1,-0x18(%rbp)
53: 83 45 e8 01 addl $0x1,-0x18(%rbp)
57: 83 45 e8 01 addl $0x1,-0x18(%rbp)
printf("%d\n", r);
5b: 8b 45 ec mov -0x14(%rbp),%eax
5e: 89 c6 mov %eax,%esi
60: bf 00 00 00 00 mov $0x0,%edi
65: b8 00 00 00 00 mov $0x0,%eax
6a: e8 00 00 00 00 callq 6f 
return 0;
6f: b8 00 00 00 00 mov $0x0,%eax
}
74: c9 leaveq
75: c3 retq

The first few and last few instructions just set up the stack frame, initial variable values, and do the printf call and return from main, so we really only cared about instructions 0×24 through 0×57. That’s where the interesting behavior was. Let’s walk through the instructions a few at a time:

24: 8b 45 e8 mov -0x18(%rbp),%eax
27: 48 98 cltq
29: 8b 54 85 f0 mov -0x10(%rbp,%rax,4),%edx

The first three instructions were as we expected. First, it loads the value of i (0) into register eax, sign-extends it to 64 bits, then loads a[0] into register edx. The 1 * was obviously optimized out by the compiler, but everything looked normal here. The next few started out much the same:

2d: 8b 45 e8 mov -0x18(%rbp),%eax
30: 48 98 cltq
32: 8b 44 85 f0 mov -0x10(%rbp,%rax,4),%eax
36: 01 c0 add %eax,%eax
38: 8d 0c 02 lea (%rdx,%rax,1),%ecx

The first mov loads the value of i (still 0) into eax, sign-extends it to 64-bits, then loads a[0] into eax. That’s intersting – we expected the i++ to have been performed before these three instructions again, but maybe the last two instructions will do some sort of assembly magic to get us to the expected result (2 * a[1]). The two instructions add eax to itself, effectively performing 2 * a[0], then add that result to the previous computation and stores it in ecx. At this point the instructions have evaluated a[0] + 2 * a[0]. Things are starting to look a little strange but again, maybe there’s some compiler magic going on.

3b: 8b 45 e8 mov -0x18(%rbp),%eax
3e: 48 98 cltq
40: 8b 54 85 f0 mov -0x10(%rbp,%rax,4),%edx
44: 89 d0 mov %edx,%eax

These next few instructions are starting to look pretty familiar. They load the value of i (still 0), sign extend it to 64-bits, load a[0] into edx, then copy edx into eax. Hmm, ok let’s take a look at a few more:

46: 01 c0 add %eax,%eax
48: 01 d0 add %edx,%eax
4a: 01 c8 add %ecx,%eax
4c: 89 45 ec mov %eax,-0x14(%rbp)

Here, it adds a[0] to itself 3 times, adds it the previous computation, then stores it into variable ‘r’. Now that’s wild – our variable r now contains a[0] + 2 * a[0] + 3 * a[0]. Sure enough, that’s what the program output: “60″. But what happened to those postfix operations? They’re all there at the end:

4f: 83 45 e8 01 addl $0x1,-0x18(%rbp)
53: 83 45 e8 01 addl $0x1,-0x18(%rbp)
57: 83 45 e8 01 addl $0x1,-0x18(%rbp)

It seemed our compiled version of the code just seemed completely wrong! Why had the postfix operations been thrown down at the end after the assignment had already happened? With my faith in reality dwindling, I decided to go straight to the source. No, not the compiler’s source – that’s just an implementation – I grabbed the C11 language specification.

The issue lay within the details of the postfix operations. In our case, we were thrice performing a postfix increment to our array index in a single expression. When evaluating a postfix operator it returns the initial value of the variable. The assignment of the new value back to the variable is known as a side effect. It turns out that side effects are only defined to have been committed between sequence points. See section 5.1.2.3 of the standard for the specifics of where sequence points are defined, but in our case our expression exhibits undefined behavior. It’s entirely up to the compiler when the side-effect of the assignment of the new value back to the variable is performed with respect to the other parts of the expression.

In the end, we both learned a bit more about the C language. It’s well-known best practice to avoid constructing complex expressions with prefix/postfix operators, and this is a great example of why that is the case.

The sample program and the output on my computer.
The sample program and the output on my computer.

Google Camera now on the play store!

Google Camera
For those who’ve been waiting since ages, Google Camera is finally on the play store for all devices running Android 4.4.x!
Google has made a number of improvements and refinements here, introducing a much cleaner interface “that gets out of your way” with a prominent shutter button. A brand new Lens Blur mode promises to achieve “SLR-like photos” offering a shallow depth of field.
Google says, “Lens Blur replaces the need for a large optical system with computer vision algorithms and optimization techniques that are run entirely on the mobile device, simulating a larger lens and aperture in order to creating a 3D model of the world.”. The company also posted details on how the Lens Blur came to be on their ‘Research at Google’ Google+ account.

I’ll present you with the Google Play description of the app and share what I found out from the app.

The Google Play description of the app says:

Google Camera snaps quick and easy photos and videos, and has creative picture modes like Photo Sphere, Lens Blur and Panorama.
Features:

  • Photo Spheres for immersive 360º views
  • Lens Blur mode for SLR-like photos with shallow depth of field
  • Panorama mode with high resolution
  • 100% viewfinder for getting the maximum resolution from the sensor (no dropped pixels)
  • Updated UI that gets out of your way and is centered on an extra large capture button
  • Works on phones and tablets running Android 4.4+ KitKat

Let’s compare this with what I saw.Main screenApp menu
When you first start the app, it opens in the expected camera mode. The menu shows 5 different modes. Camera, Video, Lens Blur, PhotoSphere and Panorama! When the first time you start the Lens Blur, Panorama or the Photosphere modes, you’ll be greeted with a short explanation of how to use it. The UI as you can see, follows the Google design guidelines, (Duh! Google App!) and looks very modern. For those who have used the Nexus camera app and Nexus devices might think that this might not be very different, but it is, you’ll again need to get to know the location of all the menus and stuff.

  • The photosphere feature is well known of course to all Nexus users or whoever managed to use the Nexus camera app. So I can’t say there’s any significant improvement here, for good photospheres, you still need a tripod or something.
  • Lens Blur! Frankly, that’s new, and it works reasonably good! If you’re going to Lens Blur a pic of your plate for Instagram, it’s perfect, since the instructions say that it’s best for photos of objects closer than 5 feet. It’ll need a bit more work, but it’s absolutely great, once again, the quality of the lens blur depends on how well the user handles it.

Lens Blur

  • Now there’s something new in the Video mode. On setting video mode, it’ll recommend Panoyou to change turn off auto-rotation lock and then turns the layout to landscape mode itself! If you didn’t listen to the people saying that videos are meant to be shot in landscape mode, now listen to Google!
  • The panorama mode really does take hi-res pics! But then, users of HTC, Sony or Samsung smartphone, or other popular brands like LG and Motorola, they all have already used High resolution panoramas already. So, nothing exciting here, except that the way this app takes panos is new. Perhaps better!
  • Umm, generally all major brands have camera apps with  a “100% viewfinder for getting the maximum resolution from the sensor (no dropped pixels)”. So I don’t really know what’s special there.
  • For the next part, you can already see how large the capture button is. The app really gets out of your way to let you do your thing. Even though a large capture button is easier to click and all, but it looks… too big? Yeah. Too big. Could have brought that area to better use!
  • And of course, the last part is nothing to brag about, Google knows it’s a limitation and is presenting it that way. (By adding it under “features”. Really?)

Overall, this is one great camera app! Fast, fluid, modern, has a way too big capture button. Everything that you need! And of course! The brand you amazing Lens Blur! Haha! Just kidding, it’s a good app, try it!

Sources:
Google Camera on the Play Store
The Google Research Blog
The Verge

How to install Catalyst-legacy driver in Windows 8.1? ATI Radeon 4000 Series and earlier.

Welcome Ideabusters!

This time, after a long time, a legit and full fledged article is posted here,
now, I understand a lot of you might be in utter desperation, so i’ll save you the time and tell you how I did it.

Firstly, I did all this to play Minecraft. On windows 8.1.
Let me tell you my basic and relevant to this case specs:
GPU: ATI Mobility Radeon HD 4650
… that’s all that’s needed actually, you don’t need the CPU, RAM, HDD, etc.

How I encountered the problem?
I was just done installing Windows 8.1 and was installing stuff I backed up, and then I started installing minecraft. Went smooth as anything the installation did. But when I began to play it, it didn’t run! It CRASHED! Now here is a list of things I found out from the crash report, I googled and I found out through all the means I could:

And the last search gave me relief.

What happened is, on windows 8.1, there is no support for legacy ATI cards. So what I had to do it, manually install the driver from Device manager.

Won’t go into details about what I did if not asked for. So if you’ve tried everything and still nothing helps, try googling the things I googled, or read on, this will probably fix it for you.

The following text article is from Microsoft Answers, here.

– Install all components of the driver normally (Catalyst Control Center etc.)
-> The graphics driver itself will fail – you need to install it manually using the Device Manager!

– Open the Device Manager (right click on Start-Icon in left corner), go to “Graphics Card”
– Right click on the card and select “Update driver…” from the context menu (first entry)
– Click on “Search for a driver on the computer” (second entry)
– Click “Select driver from list”
– Click on the “Device…” button in the right corner
– Select the driver file (*.inf) from the extracted ATI folder. In my case, this was C:AMDSupport13-1-legacy_vista_win7_win8_64_dd_cccPackagesDriversDisplayW86A_INF.
There are a few different files, it seems the dialog will choose the right one if you simple select one of them… TRY IT FIRST! Otherwise you could try to read the .inf files (they are just plain text files – maybe you’ll find your chipset in there…
– Click on OK, the dialog will now show one or two entries, which should have the name of your graphics card – select one of them
– Click on Next – the screen(s) will go black and flicker, you will hear the device connection/disconnection sounds several times. Don’t worry, everythings works as intended! 🙂
– The driver should now be ready – restart your system, and you should now be able to control your graphics settings using the Catalyst Control Center.

– Tip: Save this trick somewhere, it will save you lots of headaches the next time you need to install windows! I figured it out painfully at least twice! 🙂

I hope this helped you, it sure did help me! Good day gents! 😀 Be sure to comment and provide feedback for others and myself!

MINECRAFT 101: Everything a Beginner needs to know

Welcome fellow Minecrafters and beginners.

Before you continue reading, i’ll tell you why should you read this post.
1. Cuz I am fairly experienced and can actually tell you everything you need to know about the game.
2. I have hosted servers and played on multiplayer a lot and even used Dropbox for syncing data across players, so this means I know what i’ll be talking about.
3. Cuz this is a ‘no-bullshit’ blog.

Again before you continue, I must say, I wont talk about any issues related to Cracked Minecraft applications you might have downloaded via torrent sites. I’ll jump to what happens after you start the game.

You can download the game from Minecrafts official website if you want to buy it.

And If you want to learn everything in bulk, that requires too much to go through all the articles, visit MinecraftWiki.

Minecraft
Minecraft Title Screen

I suggest you to play the Creative Mode game to understand how most Blocks work, how the NPC Villages and its people work , how the Minecraft Weather System works. Later you may try a Survival mode game to learn about crafting things. Since you won’t know what you can actually craft, you can see a Crafting Guide.

The GameModes
1. Survival
2. Creative
3. Hardcore
4. Adventure (Multiplayer Only as far as I know).

1. SURVIVAL MODE

Basically, in this mode, you gather resources – kill animals for food and wool, dig for coal, iron, and other rare resources, chop trees for wood, craft stuff to build better things, and more complex mechanisms and try not to die. You can use tools for acquiring resources, or simply bare hands, but that’ll take a longer time.

Survival Mode in Minecraft.
Survival Mode in Minecraft.

2. CREATIVE MODE

Infinite Resources, Infinite Health! Only way to die here is to fall in the VOID or use the ‘/kill’ command. (Did I tell you that there are ‘THREE Dimensions” in Minecraft?) You can use this mode to create pixel art masterpieces! You can find a humongous amount of these on the internet.

Flying in Creative Mode
Flying in Creative Mode

3. HARDCORE MODE

For players who know what they are dealing with, and for players who have killed an EnderDragon in single player without cheats. This is hardcore in the literal sense. You will notice that the hearts in the Life Bar look different. If you die, the game data, that is, the world will be deleted. You have only one shot and surviving this mode.

Hardcore Mode in Minecraft
Hardcore Mode in Minecraft

4. ADVENTURE MODE

This is Ultimate shit. Only for multiplayer. You need specific tools for specific tasks! You can’t collect all resources with your hands unlike the other modes. Recommended only for the elite of elites! You need a village to spend the night to survive and… there’s a lot of deal here, I recommend you to read the NPC Villages Wiki and Adventure Mode for this. Its looks the same as Survival, except for the difference already mentioned.

DIMENSIONS IN MINECRAFT

There are 3 dimensions in Minecraft.

1. Overworld
2. Nether
3. End

1. Overworld

This is the usual Earth, the place where you spawn, where you collect resources and live in biomes.

Extreme hills biome in the overworld.
Extreme hills biome in the overworld.

2. Nether

This is hell, literally, hell in minecraft! Here you find Zombie Pigmen, Oozing Lava and The Void on two sides of the dimension! You enter the Nether by making a Nether Portal. You can make a nether portal by creating an Obsidian Block Frame with a 3×2 blank on the inside and lighting up the inside on fire. Here is a YouTube Tutorial on making a Nether Portal. My recommendation, get decent Iron or Diamond Armor and Weapons and if needed, Tools of Iron or Diamond. P.S: Lava flows like water here. And Nether creatures aren’t harmed by lava.

The Burning Nether
The Burning Nether

3. End

This is… well… another dimension. It has endermen and one enderdragon ‎that looks amazingly cool and is incredibly hard to beat on survival! You can reach the end by finding an end portal in a stronghold, which are increadibly hard to find, but could be found in the overworld. Even then you’ll need 12 Eyes of Ender to activate the portal which you can craft in this way.

The End Dimension with the Sexy Enderdragon.
The End Dimension with the Sexy Enderdragon.
A Stronghold with a Sexy Fountain.
A Stronghold with a Sexy Fountain.
An End Portal in a Stronghold
An End Portal in a Stronghold

BIOMES IN MINECRAFT

Minecraft features a large range of biomes. Now on the MinecraftWiki website, there is nothing much that should be very complicated to you. So i’ll share a direct link to the Biomes Page.

However, here is a list of the biomes and the things found in them…
1. Forest: Oak and Birch TreesFlowers,Wolves,Mushrooms
2. Desert: SandCactiDead Bushes,SandstoneSugar CaneDesert wells,Desert Temple,NPC Villages 
3. Plains: Tall GrassGrass,FlowersNPC VillagesHorses
4. Swampland: Witch HutsOak TreesGrass,VinesLily Pads,ClayMushrooms,Slimes
5. Jungle: Jungle Trees,Jungle Temples,FernsFlowers,VinesOcelots,Cocoa Pods,Chickens
6. Ice Plains (Tundra): SnowSnowfall,Oak TreesIce
7. Taiga: SnowSnowfall,IceSpruce Trees,FlowersWolves
8. Extreme Hills: Oak Trees,FlowersEmerald OreMonster Egg
9. Ocean: WaterSandClay,DirtSquid
10. Mushroom Island: MushroomsHuge Mushrooms,Mycelium,Mooshrooms
11. Hell (The Nether): Magma Cubes,Netherrack,GlowstoneSoul SandNether Brick,GravelQuartz,GhastsBlazes,Zombie Pigmen,Nether Fortress,Wither Skeletons
12. Sky (The End): End Stone,Endermen,ObsidianEnder CrystalsEnder Dragon

KEYBOARD CONTROLS

Survival/Hardcore/Adventure/Creative Mode Controls
W – Front
A – Left
S – Back
D – Right
E – Use Inventory
Q – Throw Equipped Item
T – Chat/Talk
TAB – See online players on multiplayer games.
SPACE – Jump/Float
SHIFT – Crouch
Left Click – Attack/Dig(when pressed and held)
Right Click – Use Held/Pointed Item/Attack with bow(hold to use with more power)
1-9 – Equip Item in hand on boxes 1-9
Mouse Scroll Wheel – Scroll Through Items 1-9
W(double tap and hold) – Sprint (Doesn’t work if food bar is at 3 units of lower)
W(double tap and hold) + Space – Long Jump
F1 – Toggle UI
F2 – Take a Screenshot (saved at C:/Users/<username>/AppData/Roaming/.minecraft/Screenshots/)
F3 – Toggle Location and Memory details.
F4 – I don’t know. Nothing much happened when I pressed it!
F5 – Toggle Camera between First Person, Third Person and Face Viewing angle.
F6 – I don’t know what this does as well!
F7 – Nada! Not here too.
F8 – Same here Johnny! No clue.
F9 – Get Sherlock here! We still don’t know what this does!
F10 – Houston, we don’t have a clue.
F11 – FULLSCREEN! Minecraft is destined to be played fullscreen!
F12 – No clues again…

Creative Mode Only Controls

Space(Double Tap and Hold) – Fly Up/Stop Flying
Shift – Fly Down

MINECRAFT TIPS AND TRICKS!

Fighting Tips:
1.  You know how to sprint, when you want to attack something at a distance, don’t simply walk to it. You can inflict much more damage, in some cases, achieve a 1-hit kill if you sprint-attack at it. How to do it? Simple, Sprint directly towards it and attack with perfect timing, improper timing will result in you overshooting through the target or you being hit, right timing will inflict more damage and knockback, which means if you have enough of the food bar left, you can again sprint and attack if it’s not dead already.
2. When you go to a fight, always take 2 swords, since I am assuming you’re a beginner, you dont have enough Iron by now. Even if you do, always have a backup sword. You never know how many enemies you come across.
3. See an Enderman? You can do these things, If you’re alone, and it’s attacking you, either run to somewhere with plently of light, place torches as fast as you can all around you on the ground and keep sword ready, and if you really have to fight it, aim for the legs. You can piss off an enderman by looking at it with your crosshair on it. But for some reason, they scare me even in creative mode.
4. Try to use enchanted swords whenever you can. And when fighting in a team, fight back to back when surrounded. If you try to fight together, you might end up hitting each other.
5. Armor Up before a battle, if you are dead sure you’re gonna die, you should’nt be going. If you think you have a chance, armor up the best you can! Look at my damn armor!

Complete Diamond and Enchanted Equipment
Complete Diamond and Enchanted Equipment

6. This one seems important for the many of you. I see that most beginners take damage while trying to kill a creeper. There is a technique to kill it without taking damage due to explosion. Also, killing it without an explosion would drop a piece of gunpowder which with other ingredients can be used to make TNT. Here’s how to kill it.
>When you spot one/multiple creeper, focus on one while trying to stay away from others, DO NOT APPROACH them if your food bar is less than 6 cuz you’ll need to sprint in the process.
>Sprint towards the one you focused on and attack it, and immediately run backwards while facing it, carefully paying attention that there is no creeper behind you or near you and you are sufficiently away from it. Reason? When you are close to a creeper, it’ll try to explode as close to you as it can to inflict maximum damage, before exploding it’ll give you about 1-1.5 seconds and it makes a hiss-ing noise in that time, multiple failures in this will help you time your “sprint-attack” perfectly, after that, you’ll be almost always succesful, and always wear an armor before facing them, else if they explode, you’ll die in one attempt.
>When you see it stopped “hissing”, sprint forward again, notice the presence of any other present creepers and sprint at it tactically so that you can attack it, yet maintain distance from the other ones. After a couple of attempts, you’ll do it just fine.

Building tips:
1.
Never build a building too big. And even if you do, place too many torches across it. Torches help to avoid monsters. Also, if you don’t place torches well enough, monsters will spawn INSIDE your massive building, and if creepers spawn, be ready for trouble. See our building!

The Gigantic Castle we built, its only tall, not that big as we want to think.
The Gigantic Castle we built, its only tall, not that big as we want to think.

2. Build trap and killing mechanisms around your house. Like the one i’ve built. These will help you to save yourselves. The one i’ve built needs redstone to work. Read about redstone here. See, the castle is surrounded by double layer of fences!

When it is disabled.
When it is disabled.
When it is active!
When it is active!

3. Don’t stop your imagination, most real world logic doesn’t apply to minecraft, you are free you blow your minds out! P.S.- Sand and Gravel unlike every other block(except Lava and Water blocks) don’t stick in mid air.

Don't stop Imagining! Presenting out rail-roller-coaster!
Don’t stop Imagining! Presenting out rail-roller-coaster!

COMING UP NEXT!

1. More Tips and Tricks.
2. Additional Minecraft get-arounds!

Why do you need to backup, and POPULAR BACKUP SERVICES…

Hello! Before I continue, I as always tell you,
WHY SHOULD YOU READ THIS…
» Cuz I’m an average user. I don’t use them too little, not do I over-depend on them. I use them enough to be well acquainted with them, and I use them only when I need to.

Hey everyone, I’m posting something after a long time, but you’re not interested in this I’m sure, so I’ll cut to the chase.

[If you’re interested only in services that help you to backup data, still down and look for “Backup Services” ]

Have you ever wished that, “I wish I had a pic of that…”? I have, a couple years ago, when I didn’t have a camera(I never had a camera, only a camera phone that I got in 2011), I wish I could rejoice that memory, I wish I had images if that, at times on great occasions I even asked my neighbours if they got a camera, if they even had, my parents didn’t allow me. Sigh.
This taught me, over time, how important it was to have those images. Now everything I said about images, applies to videos, music, movies, documents, and every piece of data I’ve ever had!

I lost a lot of data due to accidental deletion, data corruption wasn’t a big issue for me…

No one wants to lose that cute pic of their pet when it was just born, it the pic of their little princes and princesses who just won a fancy dress competition. Memories are way too valuable for people like me, and many of those out there.

You can say I have an OCD about this. I don’t delete a single pic or video I’ve ever taken, accidentally or intentionally.

Cuz you never know if your best friend today turns an enemy tomorrow!

What I’m saying is, life is so damn fucking unpredictable that you just can’t know what moment you might never experience again! You might go one a fishing trip today, to the nearby lake, for a thousandth time… nothing special… you can again visit it tomorrow, and after that. Whenever you want. But you never know if that friend will live to see tomorrow, or if you’ll live, or if a nuke drops nearby. YOU’LL NEVER KNOW!

Life is very unpredictable, treasure every moment.

Now, let’s come to business shall we?

BACKUP SERVICES

Disclaimer: This isn’t a professionalists review, it’s an average user review.

Listing them out:

Dropbox
Box
Google Drive
SugarSync
SkyDrive

Personally speaking, I love Box. No special reason as such. It allows online editing of docs and stuff, that’s the on-the-go BS most services provide. Don’t take me literally, using BS for something is my way of talking. Actually I love box cuz it got me 50 GB on signing in on my android device. And many devices provide free +50GB Dropbox space. Mine did. It’s a Samsung Galaxy Grand Duos. You’ll find a review for that device elsewhere on IdeaBuster. You might like Dropbox better, I mean, not a lot of sites provide free space on adding friends or referrals, do they?
Then comes SugarSync, well, I like it’s app, and especially, the cute logo. (I’m a straight make alright! Even guys think some things are cute!) Plus on slower networks the SugarSync app works better than Dropbox, I haven’t tried Box on the Galaxy Grand yet… Then comes Skydrive, it provides some 7.5 GB or so space. Plus some editing features of Office 365 I think.
Last but not the least, Google Drive. Gives 5GB for free. Good stuff. Deep Google docs integration, and all the Google related goodies!
Wait, did I mention that Facebook uses Dropbox for file sharing in groups? So you could use Dropbox BS in Facebook at some places too! But that’s not a big deal for me… maybe it is for you!
I’ve helped enough now! Go on your jobs! I’m done!

Samsung Galaxy Grand Duos GT I-9082 User Review

Hey people! I thought about writing this long ago, but a little late isn’t that bad, is it.

Now, why should you read this review? Well, there are a gazillion reviews out there, but none written by someone do restricted on budget like me! So here I go.

There are some lower budget phones in the market that claim to deliver way better performance than the grand, I call it bullshit! One fundamental thing you must keep in mind, newer hardware is always better than old hardware. And the hardware on the Canvas 2 is old, regardless of the phone being new.

Starting with the display, the ppi might look low to those who have used high end phones before. But the point is, if you’ve bought a 30k phone before, why the hell would you want the grand? I automatically assume that you’re rich enough to buy a better smartphone. And if you’re the poor man, like me, this is your poor man’s Galaxy S3! A 5 inch tool is what a lot of men don’t have!

So the ppi… it doesn’t bother me, it is nice enough for everything! Multimedia, gaming, browsing, etc.

Performance wise, it’s great! Regardless of what benchmarks say(though the benchmark scores, tested by myself using multiple benchmarking apps, are impressive!) the grand does great! And it blows away competition in Nenamark 2! It can play almost every game! Mind it, I said almost. Though the grand will act erratically occasionally to remind you of the difference between a flagship and it, but it still didn’t bother me. It still remains reliable considering I use it nicely. Nicely doesn’t mean that I don’t use many apps. Already having 124 apps, and still got space!

Obviously it has expandable storage capability, and 4GB of internal memory isn’t a headache for me. I have a 16GB SD card. I store my data there. So stop crying about internal memory.

The user interface is good, multi window is very handy at times! For example, I can text message someone while texting another guy on Facebook without switching applications! (Now we have the chat heads feature, but you get the point.)

The battery doesn’t disappoint, lasts long enough. Plus, the phone doesn’t even heat! At least not irritably!

The cameras, 8 and 2 mp each with full HD recording capability and ZERO SHUTTER LAG show you to take amazing pictures, and especially videos! Damn! Ask me! I’m more of a multimedia guy!

The phone does feel plasticky though, and gave me a scare when I was opening the back cover for the first time! It’s totally plastic, solid plastic though, but I thought it’d break! It didn’t break. The flip cover is classic, I think it’s not so useless, it’s good.

Vodafone users, put your old SIM into this and get 2GB free data! It’s a good deal!

This phone won’t let down a person limited on budget.

But if you’re into android development and can’t live without tweaking it, dump this phone. It’s got close to nil development right now. If you want to know anything and everything about this phone, mail me or comment below.

Thanks for your time.

Word Ruggle : Its like Wordament on Android!

Hi everyone! This time I’ve brought you an app review, for Word Ruggle!

This was suggested by my friend, Soumajeet Basu, and if you’re a fan of word games and if you’ve simply loved Wordament but don’t have a Windows device (or at least can’t regularly connected it to the internet), Word Ruggle is the game for you!

Word Ruggle has a bit different UI than Wordament, but still very similar. There’s still the swiping for words, still the 4×4 grid, still a real time online gameplay with many other players from across the globe! This app is supported across all devices! And you don’t need a high speed internet to play it, 2G works just fine.

About user experience:
Firstly, i’m using this game on the way too old Samsung Galaxy 3 GT-I5801. This device runs it, means any device can. Literally.
The game feels pretty smooth, no noticeable lags damn show processor like the one on my phone, and it doesn’t really get irritating. Now if you aren’t a fan of word games, that’s a different issue, isn’t it?

Summing it up:
Good game, nice UI, smooth functioning, engaging!

On google play:
Word Ruggle on Google Play

Here’s some screenshots:

image

image

image

image

Tell us how you feel about this game.

A tip on overheating laptops.

Laptop overheating is no new problem. It’s been there since the beginning of time…
…of laptops.

So what causes it to overheat?

Firstly, i’m sure your laptop didn’t heat up like it does now when you just bought it and played Assassins Creed 3 on maximum graphics, that it, used your laptop on full load.

So it’s overheating now means there’s a problem that can be fixed.

This is how:

1. Open up your laptop.
If you’re not an expert but still prefer to do it yourself, I’ll recommend googling about how to open your laptop. It’s best to watch a YouTube video on that, if that’s available. Don’t settle for tutorials that aren’t for your model or even a similar one, as some components are always different, look for exactly your model. Or a very similar one if you don’t find it.
AND BE CAREFUL ABOUT WHICH SCREWS YOU PULL OUT FROM WHERE. DO NOT IMPROVISE ON SCREWDRIVERS!
Tip: If it takes more strength than crushing an empty can to open a component, you’re doing it wrong.
You may do step 3 here only or after step 2.

2.  Clean all the dirt using a soft brush and a soft cloth, DO NOT USE CLEANSING LIQUIDS!

3.  Open up the fan. Yes, you can open it up. If your tutorial didn’t tell you how to, look around the laptop motherboard for screws connected to the base. Unscrew them and flip it over, safely. And find a way to open your fan!

Result: You’ll find that there was an amazing amount of dirt stuck up in there! Clean it all up using that brush I told you about! Blow it nice and strong, make sure you dry blow it and if you’re blowing with your mouth, no saliva goes out. Then screw everything back together, it should be good as new!

Self experience:
I tried this once with my Dell Inspiron M5010. I opened and didn’t find a lot of dust around the motherboard, still I cleaned it and fixed it back, the overheating problem didn’t go. Why? Cuz I didn’t open the fan. Later when I did and cleaned it thoroughly, it worked great!

DOSBox 0.74 | How to use it?

This is an awesome tutorial on how to use DOSBox 0.74.

NOTICE: IF YOU ARE USING WINDOWS XP, YOU DO NOT NEED TO USE DOSBOX. WINDOWS XP NATIVELY SUPPORTS 16-BIT APPLICATIONS.

DOSBox is a 16-bit emulator for computer programs. The given below link to a google drive document explains in very high detail with plenty of screenshots on a Windows 7 Ultimate x64 PC. Even if you have an entirely different PC, it wont matter. The tutorial explains what matters. Here’s your link:

DOSBox 0.74 | How to use it?

Just for your info.The compiler used is Borland C++ v5.02. But again, that doesn’t really matter as DOSBox is only concerned with the executables.

%d bloggers like this: