Wednesday, 14 September 2016

Piwik database using Ruby script in Rails Framework

Ruby script for connecting Piwik Database in rails


One of my client I have two different application/Framework 1.Piwik: Which is used as a Analytic framework for tracking all the activites of a web sites and you can store your analytic data in your server basic need for using piwik it's free and easy to integrate with any application and it is provide very good support if you are a paid customer but it's available free also .

So why we need to integrate that PIWIK database in Rails ! Actually we had a requirement to show Analytic dashboard of piwik for some of the Account holder so our Admin maually create the client app on Piwik and we populating that piwik token and other stuff via connecting the Piwik database .

require 'mysql'
module Piwik
#--------------query for piwik database for getting token of user-----------
def piwik_tokens
!connection_piwik.nil? ? @rs = connection_piwik.query('select login, token_auth from enbake_piwik_user;') : "#{["Connect-Piwik-Sever"]}"
!@rs.nil? ? result : ["Connect-Piwik-Sever"]
end
#--------------------query for site_ids for clients dashboard----------------
def piwik_site_ids
!connection_piwik.nil? ? @rs = connection_piwik.query("select name, idsite from enbake_piwik_site;") : "#{["Connect-Piwik-Sever"]}"
!@rs.nil? ? result : ["Connect-Piwik-Sever"]
end
#----------------creating connection for piwik database with mysql adapter-------
private
def connection_piwik
Mysql.new('localhost', 'root', 'a', 'enbake')
rescue Mysql::Error => e
# Print the error.
puts "ERROR #{e.errno} (#{e.sqlstate}): #{e.error}"
puts "Can't connect to the MySQL database specified."
# Signal an error
ensure
end
#---------------------------data for dropdown-----------------------
def result
@data = Array.new
@rs.each do |f|
f[0] = "#{f[0]}-#{f[1]}"
@data = @data << f
end
connection_piwik.close
@data
end
end
view raw piwik.rb hosted with ❤ by GitHub

Easy way to create dump of mongodb database Raw

Dump from MogoDB server :)


Below method are used for creating dump of mongodb database..

mongodump --host xxx.xxx.xx.xxx --port xxxx --out /home/enbake/Documents/

mongodump --host [localhost] --port [portno] --out /home/enbake/Documents/

Below method are used for restore dump into local mongodb database..

mongorestore -d mydatabase /home/enbake/Documents/mydatabase_backup

mongorestore -d [local-database-name] [path-of-dump-folder]

view raw mongodump.md hosted with ❤ by GitHub

Installing node version in centos 7 ( Digital Ocean )

Below are the some command which is use-full if you Installing node version in centos 7

su -

yum install gcc-c++ openssl-devel

cd /usr/local/src

$ wget https://raw.github.com/isaacs/nave/master/nave.sh

$ chmod +x nave.sh

$ ./nave.sh install 0.8.8

$ ./nave.sh use 0.8.8

$ node -v v0.8.8


Showing uploaded File in Iframe using Javascript


$(document).on("input",".upload", function(){
var src = $(this).val();
src = src.replace("watch?v=", "v/");
src = src.replace("video/", "embed/video/");
var abc="<iframe src='my_source' width='452' height='345' scrolling='no' frameborder='no' target='_top' allowFullScreen></iframe>".replace(/my_source/g,src);
if (src.match(/(youtube|youtu|vimeo|veoh|dailymotion|kickstarter|metacafe)\.(com|be)\/((watch\?v=([-\w]+))|(video\/([-\w]+))|(projects\/([-\w]+)\/([-\w]+))|([-\w]+))/)) {
$(this).next('#thumbs').empty().append(abc);
}
else if( src.match(/^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.mp4|.MP4|.avi|.AVI|.3gp|.3GP)$/)) {
$(this).next('#thumbs').empty().append(abc);
}
else{$(this).next('#thumbs').empty();}
});
view raw show.js hosted with ❤ by GitHub

Nokogiri ERROR: Failed to build gem native extension.

Problem with Nokogiri Gem in Mac OS

Setup Rails project in Ubuntu system is pretty much easy for me,  one of my friend when I am setup the Rails porject in Mac OS I found some error during intallation which is related to Nokogiri Gem.


Building nokogiri using system libraries.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --use-system-libraries
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --help
    --clean
    --use-system-libraries
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-pkg-config
    --without-pkg-config
    --with-exslt-dir
    --without-exslt-dir
    --with-exslt-include
    --without-exslt-include=${exslt-dir}/include
    --with-exslt-lib
    --without-exslt-lib=${exslt-dir}/lib
    --with-libexslt-config
    --without-libexslt-config
    --with-pkg-config
    --without-pkg-config

extconf failed, exit code 1

Gem files will remain installed in /Users/myuser/projectpath/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.2.rc2 for inspection.
Results logged to /Users/myuser/projectpath/vendor/bundle/ruby/2.0.0/extensions/universal-darwin-13/2.0.0/nokogiri-1.6.2.rc2/gem_make.out
An error occurred while installing nokogiri (1.6.2.rc2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.2.rc2'` succeeds before bundling.
After googling I found a way to resolve that issue .

brew install libxml2
bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2"
bundle install


Happy coding :)


Shell Scripting in Ruby :) Fun time or Free time



#!/usr/bin/ruby -w
#system('ls -la') #=> outputs the output of that command
#system('skype') #open skype using system command.
#http://www.dreamsyssoft.com/ruby-scripting-tutorial/loops-tutorial.php
require 'optparse'
options = {:name => nil, :age => nil}
parser = OptionParser.new do|opts|
opts.banner = "Usage: ruby_linux.rb [options]"
opts.on('-n', '--name name', 'Name') do |name|
options[:name] = name;
end
opts.on('-a', '--age age', 'Age') do |age|
options[:age] = age;
end
opts.on('-h', '--help', 'Displays Help') do
puts opts
exit
end
end
parser.parse!
if options[:name] == nil
print 'Enter Name: '
options[:name] = gets.chomp
end
if options[:age] == nil
print 'Enter Age: '
options[:age] = gets.chomp
end
sayHello = 'Hello ' + options[:name] + ', '
if Integer(options[:age]) == 100
sayAge = 'You are already 100 years old!'
elsif Integer(options[:age]) < 100
sayAge = 'You will be 100 in ' + String(100 - Integer(options[:age])) + ' years!'
else
sayAge = 'You turned 100 ' + String(Integer(options[:age]) - 100) + ' years ago!'
end
puts sayHello + sayAge
view raw ruby_shell.rb hosted with ❤ by GitHub

Creating Page Object in AngularJS


Below are the sample of a page object in AngularJs


'use strict';
var AngularPage = function () {
browser.get('http://www.angularjs.org');
};
AngularPage.prototype = Object.create({}, {
todoText: { get: function () { return element(by.model('todoText')); }},
addButton: { get: function () { return element(by.css('[value="add"]')); }},
yourName: { get: function () { return element(by.model('yourName')); }},
greeting: { get: function () { return element(by.binding('yourName')).getText(); }},
todoList: { get: function () { return element.all(by.repeater('todo in todos')); }},
typeName: { value: function (keys) { return this.yourName.sendKeys(keys); }},
todoAt: { value: function (idx) { return this.todoList.get(idx).getText(); }},
addTodo: { value: function (todo) {
this.todoText.sendKeys(todo);
this.addButton.click();
}}
});
module.exports = AngularPage;
view raw pageObj.js hosted with ❤ by GitHub

Changing the version of pod in MAC EI captain

Below are the basic steps for changing the version of pod in MAC EI captain

1. gem uninstall cocoapods
2. rvm get stable --auto-dotfiles
3. rvm use ruby-2.1.2
4. rvm osx-ssl-certs update all
5. rvm rubygems latest
6. sudo gem sources -r https://rubygems.org/
7. sudo gem sources -a http://rubygems.org/
8. gem install cocoapods -v 1.0.0.beta.1 --pre -V
view raw info.txt hosted with ❤ by GitHub

Auto Rotation Script for Tracker

A simple Test script which help you to rotate the screen via script.

This is usefull for lazy personal who have only one task "RUN TRACKER :)" "not me for me....! ;)"



#!/usr/bin/env python
#To run this script in terminal first to install this dependancy: sudo apt-get install xdotool
#To make it excutable GoTo the file directory and run the command: chmod u+x upwork_tracker_free_time.rb
#Now you just need to run this file using form termial :~ ./upwork_tracker_free_time.rb
#Note: You need to specifiy every on which work space you want to swicth tab currently In code I am only swithching termial
#But you can also switch browser tab or sublim tabs subprocess.call("xdotool key ctrl+Tab" ,shell=True)
#Enjoy :)
import subprocess
import time
subprocess.call("xdotool key ctrl+alt+Up" ,shell=True)
time.sleep(60)
subprocess.call("xdotool key ctrl+alt+Left" ,shell=True)
time.sleep(60)
subprocess.call("xdotool key ctrl+alt+Right" ,shell=True)
time.sleep(60)
subprocess.call("xdotool key ctrl+alt+Left" ,shell=True)
time.sleep(60)
subprocess.call("xdotool key ctrl+alt+Right" ,shell=True)
time.sleep(60)
subprocess.call("xdotool key ctrl+alt+Left" ,shell=True)
time.sleep(60)
subprocess.call("xdotool key ctrl+alt+Right" ,shell=True)
subprocess.call("xdotool key ctrl+alt+Left" ,shell=True)

Salesforce CRM vs. Zoho: A Comparative Analysis

Introduction: Selecting the right customer relationship management (CRM) software is crucial for businesses seeking to streamline their sal...