Monday, December 21, 2015

Backup and Restore MySQL Database

10:04 PM Posted by Unknown , No comments

The quick snippet of how backup and restore MySQL database using mysqldump:
Backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
Restore: # mysql -u root -p[root_password] [database_name] < dumpfilename.sql
Backup MySQL database 
1. Backup a single database:
# mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
2. Backup multiple databases:
# mysqldump -u root -p[root_password] --databases [database_1] [database_2] > database_1_and_2.sql
3. Backup all the databases:
# mysqldump -u root -p[root_password] --all-databases > /tmp/all-database.sql
4. Backup a specific table:
# mysqldump -u root -p[root_password] database_name table_name > /tmp/database_table.sql
Restore MySQL database 
1. Restore a database
# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
2. Backup a local database and restore to remote server using single command:
# mysqldump -u root -p[root_password] database_name | mysql -u root -p[root_password] --host=remote-server -C database_name1

Wednesday, December 16, 2015

Solr DataImporter using Mongodb

6:15 PM Posted by Unknown , No comments

1. Get required libraries
Download following .jar files:
- solr-mongo-importer-1.0.0.jar (https://github.com/downloads/james75/SolrMongoImporter/solr-mongo-importer-1.0.0.jar)
- mongo-2.10.1.jar (http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.10.1/mongo-java-driver-2.10.1.jar)
save these files into
solr/contrib/dataimporthandler/lib/
2. Configure solrconfig.xml
<lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />
<lib dir="../../../dist/" regex="solr-dataimporthandler-.*\.jar" />
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">  
   <lst name="defaults">
      <str name="config">data-config.xml</str>
   </lst>
</requestHandler>
 3. Configure data-config.xml
 <?xml version="1.0"?>
 <dataConfig>
   <dataSource name="mymongodb" type="MongoDataSource" database="MongodbDatabaseName" />
   <document name="data">
   <!-- if query="" then it imports everything -->
    <entity name="users"
            processor="MongoEntityProcessor"
            query=""
            collection="users" 
            datasource="mymongodb"
            transformer="MongoMapperTransformer"> 
      <field column="id" name="id" mongoField="_id" /> 
      <!--<field column="_id" name="id" />-->

      <entity name="company"
              processor="MongoEntityProcessor"
              query="{'_id':'${users.id}'}"
              collection="company" 
              datasource="mymongodb"
              transformer="MongoMapperTransformer"> 
         <field column="company" name="company" mongoField="company"/> 
      </entity>

      <entity name="biodata"
              processor="MongoEntityProcessor"
              query="{'_id':'${users.id}'}"
              collection="users" 
              datasource="mymongodb"
              transformer="script:biodataTransformer">
      </entity>

    </entity> 
  </document> 
<script><![CDATA[
function biodataTransformer(row){
  if(row.get('biodata') !== null){
    var biodata = row.get('biodata')
    if(biodata.get("age") !== null){
      row.put("biodata_age", biodata.get("age").toString());
    }
    if(biodata.get("height") !== null){
      row.put("biodata_height", biodata.get("height").toString());
    }                
  }                 
  return row; 
}
]]></script>
</dataConfig>
4. Configure schema.xml
Define the fields you want to index in schema.xml
5. Import mongodb data into solr with outer join
Fire up solr and go to dataimport tab and execute data import.

Saturday, December 5, 2015

How to get long live access token from Facebook (60 days)

5:58 PM Posted by Unknown No comments
As of July 2015 you can now create a 60 day access token easily in Facebook

The first you need to grant permissions to your app to get an access token.

https://developers.facebook.com/tools/accesstoken/

Copy User Token and paste it to EXISTING_ACCESS_TOKEN and change your APP_ID and APP_SECRET


https://graph.facebook.com/oauth/access_token?             
    client_id=APP_ID&
    client_secret=APP_SECRET&
    grant_type=fb_exchange_token&
    fb_exchange_token=EXISTING_ACCESS_TOKEN 

Thursday, December 3, 2015

The best Material Design Frameworks for the Web

11:38 PM Posted by Unknown , No comments
In an attempt to bring Material design to the Web user interface, many third party (not from Google) web UI frameworks have come to existence recently. In this post I will be doing a roundup of these Material Design Web UI frameworks. Some of these frameworks are themes based on the popular web UI framework, Bootstrap.

1. Materialize

materialze-framework-material-design
Materialize is a modern responsive front-end framework based on Material Design. For use in your web projects, it provides an option of both CSS as well as source SCSS files, along with JavaScript, material design icons and Roboto font. Included components are basic ones such as grids, forms, buttons, navbar and cards. Materialize is available on GitHub as well.

2. Material UI

material-ui-css-framework
Material UI is a CSS Framework and a Set of React Components that implement Google’s Material Design. It provides support for components such as Buttons, Dialog, Dropwdown menu, Icon buttons, Inputs, Switches, Toolbar and more. You can find Material UI on GitHub too.

3. Paper Bootswatch for Bootstrap

paper-bootstrap-material-design-theme
Paper is a bootswatch theme for the Bootstrap framework. It includes all the components that Bootstrap provides but in a Material design skin.

4. Bootstrap Material

bootstrap-material-design
Similar to Paper, Bootstrap Material is another theme for Bootstrap framework and provides all the components included in Bootstrap. On top of that, it also includes support for 740 original Material design icons from the Google Material Design Icons repository.

5. Leaf BETA

leaf-meterial-css-framework
Leaf is CSS framework developed by Kim Korte based on the Google’s material design. While still in beta, it has extensive list of components such as buttons, cards, sliders, menu, tabs etc. It includes icons by Icomoon, instead of the original Material design icons. Leaf is also available onGitHub and is open for contributions and feedback.

6. MUI CSS Framework

mui-meterial-css-framework
MUI is a lightweight HTML, CSS and JS framework for building sites following Google’s Material Design guidelines. MUI is designed from the ground up to be fast, small and developer friendly. By design it only includes the basic components you need to build a site that follows Google’s Material Design guidelines. MUI CSS/JS has no external dependencies. MUI is also available onGitHub and is open for contributions.

7. Polymer Project

google-polymer-paper-material
Google’s Polymer Project is a web framework and their embodiment of material design for the web. While still in “developer preview”, most of the components (a very extensive set) are quite mature. Polymer aims to support all major modern browsers such as IE (10+), Chrome, Safari, and Firefox. Extensive set of documentation and getting started guide is available at the Polymer Project.

Thursday, November 26, 2015

How to create a valid RSS feed in Rails

6:28 PM Posted by Unknown 1 comment

Step 1

Create a new method in the posts controller.
app/controllers/blog_articles_controller.rb
class PostsController < ApplicationController

  ...

  def feed
    @posts = Post.all.order('created_at DESC').limit(20)
    respond_to do |format|
      format.rss { render :layout => false }
    end
  end

end

Step 2

Add a "view" for the feed.

Create the file
app/views/posts/feed.rss.builder
xml.instruct!
 
xml.rss :version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do
 
  xml.channel do
 
    xml.title 'Feed title'
    xml.description 'Feed description'
    xml.link root_url
    xml.language 'en'
    xml.tag! 'atom:link', :rel => 'self', :type => 'application/rss+xml', :href => feed_url
 
    for post in @posts
      xml.item do
        xml.title post.title
        xml.link post_url(post)
        xml.pubDate(post.created_at.rfc2822)
        xml.guid post_url(post)
        xml.description post.description
      end
    end
 
  end
 
end

Step 3

Add a route to /feed in the router file.

Edit
config/routes.rb

Add
get 'feed' => 'posts#feed'

Step 4

Add the following entry in the head section of your site template.

Edit
views/layouts/application.html.erb

Add a line like
<link href="https://www.your_website.com/feed?format=rss" rel="alternate" title="Your website RSS Feed" type="application/rss+xml"></link>
Then you can check Feed Validator for Atom and RSS here:  http://feedvalidator.org

Sunday, November 22, 2015

How to install Solr 5.3.1 on Ubuntu 14.04

7:25 PM Posted by Unknown No comments

Step 1: Installing Java

Solr requires Java, so we will install it if you didn't install it before

First, use apt-get to install python-software-properties:

sudo apt-get install python-software-properties

Install the latest version of Java 8 instead of using the default-jdk or default-jre packages

sudo add-apt-repository ppa:webupd8team/java

You will need to press ENTER to accept adding the repository to your index.

Update the source list and install Java8:
sudo apt-get update 
sudo apt-get install oracle-java8-installer

Step 2: Installing Solr

We will begin by downloading the Sorl distribution
wget http://apache.mirror1.spango.com/lucene/solr/5.3.1/solr-5.3.1.tgz

Extract the service installation file: 

tar xzf solr-5.3.1.tgz solr-5.3.1/bin/install_solr_service.sh --strip-components=2 

Install Solr as a service using the script: 

bash ./install_solr_service.sh solr-5.3.1.tgz

Check if the server is running: 

sudo service solr status

Step 3: Creating a Collection

Solr canhave mutiple collections, so you can create a collection by browser at this address: http://localhost:8983/solr/#/~cores or by command:

sudo su - solr -c "/opt/solr/bin/solr create -c collection_name -n data_driven_schema_configs"
Note: Options of solr service
/etc/init.d/solr {start|stop|restart|status} 
Or
sudo service solr  {start|stop|restart|status}