Isues w/ caching in Incognito mode

I've noticed that Incognito mode retain cache from the previous session, it just don't collect any new cache while in incognito.

I usually clear the cache/cookies then go into incognito, or run a different browser profile, or a different browser all together.

This works for me well !!

Adobe flash player installation in ubuntu chromium browser

For Chromium browser versions greater than 34, to use flash one must install Pepper flash.

For Ubuntu 14.04 or newer, run

sudo apt-get install pepperflashplugin-nonfree
sudo update-pepperflashplugin-nonfree --status 
# to see what version of Pepper Flash you have installed.
sudo update-pepperflashplugin-nonfree --install
# If there is a newer version available

For old users, you can run the below commands to add the PPA and install Pepper flash in any Ubuntu version above 12.04

sudo apt-add-repository ppa:skunk/pepper-flash
s...

Adobe flash player installation in Ubuntu

This is to install adobe flash player in Ubuntu 14.04 or higher. This works for Firefox browser.

If you have a 32-bit OS, run

sudo apt-get update
sudo apt-get install flashplugin-installer

Make sure each of the commands executed successfully.

If you have 64-bit OS,

Open “Software & Updates” from unity dash, and enable the partners repository under "Other Software” tab. Once done, run the below commands to install flash

sudo apt-get update
sudo apt-get purge adobe-flash{plugin,-properties-gtk}  (preferred)
sudo apt-get insta...

Copy remote folder to local

To copy a folder in the remote server to your local machine,

scp -r username@IPaddres:/remote/directory/path /local/folder/

In case you wish to copy in your current local directory

scp -r username@IPaddres:/remote/directory/path/ .

Retrieve SQL query in Rails 2.x

The method is construct_finder_sql(options) (lib/active_record/base.rb:1681) you will have to use send because it is private.

sql = Item.send :construct_finder_sql, :select => :all, :include => [:categories, :prices], :conditions => conditions

sql = ActionType.send :construct_finder_sql, :select => 'hosted, top_action_type, count(*) as count', :group => 'hosted, top_action_type'

gmail hack

The below hack might come in handy for testing when a unique account is required.

You can throw '.'s into gmail email addresses and they all end up at the same address on gmail.

All the below email addresses end up as same.
abc@gmail.com
ab.c@gmail.com
a.b.c@gmail.com

You can also use '+' with gmail email address, and it’ll get to your account.

abc+something-gmail-ignores@gmail.com
abc@gmail.com
end up the same

/etc/resolvconf/update.d/libc: Warning: /etc/resolv.conf is not a symbolic link to /run/resolvconf/resolv.conf

Use following command and answer YES to enable dynamic updates:

sudo dpkg-reconfigure resolvconf

Do a system restart after that.

unable to run package setup for sublime text

I've encountered the following error after installing Sublimetext2 from source on my ubuntu machine. The error says

unable to run package setup with list of packages

in a dialog box when sublime text is opened.

The issue is because of missing permissions and to resolve the issue, run the below command.

sudo chown -R user-name /home/user-name/.config/sublime-text-2/

SUDO not working

sudo: /etc/sudoers is mode 0640, should be 0440?

When a similar message appears when you try to run sudo on your machine, the problem is likely with the permissions of /etc/sudoers file.

Try running

pkexec chmod 0440 /etc/sudoers

The command asks for password. Check if it ran successfully by typing

echo $?

Upon successful execution, sudo should be working on your machine.

Is my kernel 32 bit or 64 bit

uname -a

or


uname -m

x86_64 ==> 64-bit kernel
i686 ==> 32-bit kernel

Open Nautilus with root privileges

gksudo nautilus

aletrnatively,

sudo nautilus

Find text in linux files

grep -rnw 'directory' -e "text-to-search"

-r is recursive, -n is line number and -w stands match the whole word.

grep --include={*.c,*.h} -rnw 'directory' -e "pattern"

This will only search through the files which have .c or .h extensions.

grep --exclude=*.o -rnw 'directory' -e "pattern"

Above will exclude searching all the files ending with .o extension.

ssh login without password

Nothing new .. just a note to self about how easy this is

> ssh-keygen [Enter] [Enter] [Enter]
> ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote-host
> ssh user@remote-host

Network manager says wired network device not managed

If you have any trouble in accessing internet using your wired connection and while troubleshooting, if your network manager says that "device is not managed", open the terminal and follow the below steps to fix the issue.

sudo vim /etc/NetworkManager/NetworkManager.conf

change the line managed=false to managed=true

sudo service network-manager restart

Find Class of a variable in Javascript

As we have object.class method in Ruby, to check the class of a variable in Javascript, here is the snippet

var ss = "some string";
alert (typeof ss);  #=> string
alert (typeof pp);  #=> undefined

mysql formatted select results

To get formatted results for select statements use \G as a suffix for the query.

select * from table_name\G

difference between attr_accessor and initialize

attr_accessor is used to create setter and getter methods for instance variables so that they can be accessed outside the class. initialize is the special method in ruby that gets called when an object is instantiated.

class Birthday
 attr_accessor :name
 
 def initialize age, gender
   @age = age
   self.gender = gender
 end
end

bday = Birthday.new "30", "Male"
puts bday.name # nil as initializer dont have name. yields results if set in before step like bday.name = "Bob"
puts bday.age    # undefined method `age`  as no attr_reader def...

calling super in initialize

class Person    
    def initialize(name)
        @name = name
    end    
end

class Employee < Person
end

emp = Employee.new # throws error wrong number of arguments

emp = Employee.new("foo") # parent class initialize method is called

class Employee < Person
    def initialize(name, designation)
        super(name)
        @designation = designation
    end
end

emp = Employee.new("foo", "bar")

Create class names from strings

"foo_and_bars".classify                      # => "FooAndBar" #String
"foo_and_bars".classify.constantize    # => "FooAndBar" #Class

# in case of singular names
"business".classify                             # => "Busines"
"business".camelize                           # => "Business"
"business".camelize.constantize         #=> "Business" #Class     

what is ./ and ../ in linux

In linux, we often see the use of ./ or ../ before a file name. Here is the explanation for the same

.  Current Directory
.. Parent Directory

./filename  # referring to file name in current directory
../filename # referring to file name in parent directory

deploying wordpress blog in rails application

1.First of all make sure that your server can parse both php and rails application.

  1. Make a blog directory in side the public folder of rails application.

  2. Deploy all WordPress content inside blog directory.

  3. Configure your database connection at wp-config.php file .

5.Then just paste the following code in the apache config file

<VirtualHost ...>
      ServerName ...
      DocumentRoot ...
      <Location /blog>
         PassengerEnabled off
         <IfModule mod_rewrite.c>
           RewriteEngine On
           RewriteBase /...

Clearing out old Rails session records from a MySQL database

To delete sessions based on a hard coded cut-off date:

DELETE FROM sessions WHERE updated_at < STR_TO_DATE('23.05.2013',GET_FORMAT(DATE,'EUR'));

Replacing cut-off date with period of inactivity

DELETE FROM sessions WHERE updated_at < DATE_SUB(CURDATE(), INTERVAL 30 DAY);

You can as well create a rake task and set up a cron job for automatic clearing

SomeModel.connection.execute 'DELETE FROM sessions WHERE updated_at < DATE_SUB(NOW(), INTERVAL 24 HOUR)'

change string encoding in ruby

# Ruby 1.9
string_in_utf8_encoding = string_in_latin1_encoding.encode('UTF-8')

#Ruby 1.8
gem install iconv

require 'iconv'
string_in_utf8_encoding = Iconv.conv("UTF8", "LATIN1", string_in_latin1_encoding)

However, if you want to let Ruby 1.9 stay smart about its transcoding while still providing backward compatibility, you will just need to write code for each version. Here’s an example of how this was done

if "".respond_to?(:encode!)
  def normalize_builtin_encoding(text)
    text.encode!("ISO-8859-1")
  end
else
  require ...