Show log of MySQL when running query in rails

When you run query to select, update, insert… in ruby, you can show log realtime when query is running.

First, go to MySQL and run:

show variables like '%log%';

And find record with variable_name =  general_log_file and get its value. In case, value is /var/lib/mysql/OFF016.log

mysql

Then, set

set global general_log = 1;

Then, open terminal and run:

sudo tailf <value>

In case is:

sudo tailf /var/lib/mysql/OFF016.log

Error: “#1071 – Specified key was too long; max key length is 767 bytes” when import mysql db

When import db to MySQL, if it has error: #1071 – Specified key was too long; max key length is 767 bytes.

Go SQL command to run some query to fix it.

use my_database_name;

set global innodb_large_prefix=on;

set global innodb_file_format=Barracuda;

set global innodb_file_per_table=true;

And import again. 🙂

=================================

You can also watch video to fix it easily:

Fixed: 767 bytes error video

Paperclip AV Transcoder can not upload video

When use gem paperclip-av-transcoder to upload video and get error:

Av::UnableToDetect - Unable to detect any supported library:
  av (0.9.0) lib/av/cli.rb:10:in `initialize'
  av (0.9.0) lib/av.rb:24:in `cli'
  paperclip-av-transcoder (0.6.4) lib/paperclip/paperclip_processors/transcoder.rb:14:in `initialize'

=> May be your computer missing ffmpeg and libav-tools

To install them:

// libav-tools
sudo apt-get install libav-tools

// ffmpeg
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get install ffmpeg gstreamer0.10-ffmpeg

====================================================================

And if after install them, we get error:

Av::CommandError - error while running command avconv -loglevel quiet -i

Let’s uninstall them and reinstall ffmpeg static build

// Uninstall  
sudo apt-get remove ffmpeg  
sudo apt-get purge libav-tools

// install ffmpeg static build
wget http://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz
tar xf ffmpeg-git-64bit-static.tar.xz
cd ffmpeg-git-64bit-static
sudo mv ff* qt-faststart /usr/bin/

Can’t show group chat Skype in Ubuntu 14.04

I installed Skype in Ubuntu 14.04,  but when I logged in to Skype, I only show and chat with my friends and can’t show any groups, I fixed it by the way:

Open chat box with any my friend and type:

/dumpmsnp   #show details about your connection

And I showed log:

System: MSNP: Connection Data:
 * Status: LoggedOut

Ref:It’s LoggedOut   => It is problem

To solve it, type:

/msnp24

Then log out and restart Skype. After that, type again:

/dumpmsnp 

And I see:

System: MSNP: Connection Data (MSNP24):
 * Status: LoggedIn

And I also see all my groups in Skype, and the issue was solved.

Ref:  https://community.skype.com/t5/Mac-archive/New-chat-groups-not-showing-up-in-client/td-p/3206434

[ActiveAdmin] Conditionally show buttons on show page

For customize buttons in page show in ActiveAdmin, we use:

First, we remove the default buttons from the show page:

# Remove the buttons from the show page
config.action_items.delete_if { |item| item.display_on?(:show) }

Then, add Edit button with conditions

# Add Edit Button with conditional, in show page
action_item :edit,  only: [ :show ] do
  if condition # (Ex: product.is_published?)
    link_to "Edit Product", edit_product_path(resource)
  end
end

And, add Delete button

# and our Delete Button
action_item :delete,  only: [ :show ] do
  link_to "Delete", resource_path(resource), method: :delete, 
      data: { confirm: I18n.t('active_admin.delete_confirmation') }
end

Gem schedule “whenever”

Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.

Installation

$ gem install whenever

Or with Bundler in your Gemfile.

gem 'whenever', :require => false

 

Getting started

$ cd /apps/my-project
$ wheneverize .

This will create an initial config/schedule.rb file for you.

Show example code in page: https://github.com/javan/whenever

Notes:

– When add new schedule in schedule.rb file => Update schedule by:

whenever -i
OR
whenever --update-crontab

*** Remmember add RAILS_ENV=production or RAILS_ENV=development

– To show all schedule is active:

crontab -l

– To edit schedule was generated and is active:

crontab -e

edit and save.

Format when define schedule

Ex:

every '4 10 * * *' do
 rake "daily:save_diff"
end
* * * * * *
| | | | | |
| | | | | +-- Year              (range: 1900-3000)
| | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month  (range: 1-31)
| +---------- Hour              (range: 0-23, 1 in our example)
+------------ Minute            (range: 0-59, 10 in our example)

Get Error: FATAL: Peer authentication failed for user “postgres” when use “rake db:create”

1. Open the file pg_hba.conf for Ubuntu it will be in /etc/postgresql/9.x/main and change this line:

local      all     postgres      peer

to

local      all     postgres       trust

2. Restart the postgreSQL server

sudo service postgresql restart

3. Login into psql and set your password

ALTER USER postgres WITH PASSWORD '<new_password>';

4. Finally change the pg_hba.conf from

local      all      postgres      trust

to

local      all      postgres         md5

and restart PostgreSQL server.

After restarting the postgresql server, you can access it with your own password

NoteAuthentication methods details:

trust – anyone who can connect to the server is authorized to access the database

peer – use client’s operating system user name as database user name to access it.

md5 – password-base authentication