Monday 27 November 2017

Make a list element active when included using php include


Often there is a requirement to make a menu element active when we import something using php include. Its quite simple and this is how its done.

<? php include "includes/sidebar.php"; ?>   

(sidebar.php): 

<ul id="sidebar">
  <li><a href="link1.html">Link1</a></li>
  <li><a href="link2.html">Link2</a></li>
  <li><a href="link3.html">Link3</a></li>
  <li><a href="link4.html">Link4</a></li>
</ul>

CSS:

ul#sidebar > li.active {
 background-color:#6495ED;
 color:#fff;
}

Javascript (jQUery solutuion): 


//current url being access
 var cur_href = window.location.href;
 $(document).ready(function(){
  $("#sidebar li a").each(function(){
   //get current href link
   var cur_attr =$(this).attr('href');  
   //save into regex
   var regex = new RegExp(cur_attr,"ig");
   //test if current link and current href matched
   if(regex.test(cur_href)) {
    $(this).parent().addClass('active'); //if yes then addClass 'active'
   } else {
    $(this).parent().removeClass('active'); //else removeClass 'active'
   }
  });
 });

This will make current menu link active in sidebar.

Mongo error "Two many open files", mongod server does'nt start

Solution 1(temporary and tested):

If you're using bash, ulimit -n will only display the soft limit. To get the hard limit, you need to do ulimit -Hn.

On my system, I see this:

$ ulimit -n
1024  

 Set ulimit value to new value as following:
 
 $ ulimit -Hn
4096


ulimit -n <value> (this will only set for current session, better do it in a screen mode and run it in background)

 More info: Here

Solution 2(permanent and not tested):

Modify /etc/security/limits.conf with what you need. Example:

user soft nproc 64000

Restart machine to make the changes effective.

More info: Here

Resolve gedit open issue when opening from remote machine

What happens is  sometimes when we try  to ssh into a system and open gedit in that machine(remote) everything seems fine until we try to  type something or save into that file or even we cannot open other files using Open menu in file tab.

So the solution here is:

Use nautilus/gedit on local machine

1. Open a nautilus file browser window and select "connect to server" from the menu in the top panel.

2. Enter in the server(remote) info (use ssh:// or sftp:// for ssh connections).

3. Enter password and there you go. You will be connected to the remote machine and now your gedit works fine.


Courtesy: this answer from ask ubuntu is where I found the solution.





Friday 17 November 2017

Burn an image file(ISO) to CD/DVD in linux


There are plenty of tools available in open source to burn an ISO file to CD/DVD. But, that has to get you through the hassle of downloading and installing the tools.

In most of  the linux derivatives, you can burn the ISO file to disc in command line itse ilf. All you have to do is execute the following command in your terminal and you are all good to go.


$ growisofs -dvd-compat -Z /dev/sr0=/Path_to_iso_file

Example


$ growisofs -dvd-compat -Z /dev/sr0=/home/user_name/Downloads/LinuxMint.iso

Hope this helps ;)


Monday 6 November 2017

Handling error "You probably tried to upload a file that is too large. Please refer to documentation for a workaround for this limit."


Handling error "You probably tried to upload a file that is too large. Please refer to documentation for a workaround for this limit."

Usually, we come across such errors when we try to import a large file in to mysql through phpmyadmin. This is because there is a pre-defined file limit in php for file upload which is 2MB.

You may change the file upload limit as per your requirement by changing php configuration following the below steps :

1. Navigate to apache2 directory and open php.ini file using vi or vim editor.


root@user-B85M-D3H:~# vim /etc/php5/apache2/php.ini 

2. Change the values of the following lines to as per your requirement.(I am changing the limit to 120 MB here)

&nbsp;upload_max_filesize 120M //file size
&nbsp;post_max_size 120M
&nbsp;max_execution_time 200
&nbsp;max_input_time 200

3. Please ensure that the max_execution_time, max_input_time should always be greater than upload_max_filesize and post_max_size.

4. Once you make the changes, save the file and restart the apache server using the command :

service apache2 restart  

Hope this helps. Happy coding!