Tuesday, June 19, 2018

CSS- Creating full width (100% ) container inside fixed width container.

Some times we need to add a full width containers (which spans 100% of window) inside a container which has a fixed width and aligned center.
Like below screenshot.

HTML

 <div class="container" style="width: 750px; margin: 0 auto;">
    <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
    </p>
<div class="row-full">
     --- Full width container ---
</div>

 <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
    </p>

</div>

CSS

<style>
 .row-full{
 width: 100vw;
 position: relative;
 margin-left: -50vw;
 height: 100px;
 left: 50%;
 background-color:red;
}
</style>

Friday, June 8, 2018

SSH- List of Basic SSH Commands

SSH CommandExplanation
lsShow directory contents (list the names of files).
cdChange Directory.
mkdirCreate a new folder (directory).
touchCreate a new file.
rmRemove a file.
catShow contents of a file.
pwdShow current directory (full path to where you are right now).
cpCopy file/folder.
mvMove file/folder.
grepSearch for a specific phrase in file/lines.
findSearch files and directories.
vi/nanoText editors.
historyShow last 50 used commands.
clearClear the terminal screen.
tarCreate & Unpack compressed archives.
wgetDownload files from the internet.
duGet file size.

Wednesday, December 13, 2017

SSH- How to zip a folder via SSH Terminal

This is how you can zip a folder via SSH on your Linux server. Works on Debian and other servers.

zip -r filename.zip foldername/

Tuesday, November 14, 2017

Sunday, November 12, 2017

SSH- Change all files and folders permissions of a directory to 644/755

SSH- Change all files and folders permissions of a directory to 644/755
 
   
find * -type d -print0 | xargs -0 chmod 0755 # for directories
find . -type f -print0 | xargs -0 chmod 0644 # for files



For WordPress -


All files should be 664.
All folders should be 775.
wp-config.php should be 660.
    

Monday, October 30, 2017

SSH- How to create php files in /var/www folder?

SSH- How to create php files in /var/www folder?


-Create the file

sudo touch hello.php

-Open the file

sudo vi hello.php

Enter write mode (we were in command mode initially) by pressing  a  (note that    vi   is case sensitive)

After that, press Esc (to change to command mode) and type :wq Check if everything is fine with
cat hello.php

However, it's probably a better idea to use editors such as vim or nano as work with them is a lot simpler than that.

Wednesday, October 11, 2017

SSH- Useful SSH commands


SSH- Useful SSH commands

1. Access monitor
mysql -u [username] -p; (will prompt for password)
2. Show all databases:
show databases;

3. Access database:
mysql -u [username] -p [database] (will prompt for password)

4.Create new database:
create database [database];

5.Select database:
use [database];

6. Determine what database is in use:
select database();

7. Show all tables:
show tables;

8. Show table structure:
describe [table];


9. List all indexes on a table:
show index from [table];

10. Create new table with columns:
CREATE TABLE [table] ([column] VARCHAR(120), [another-column] DATETIME);

11. Adding a column:
ALTER TABLE [table] ADD COLUMN [column] VARCHAR(120);

12. Adding a column with an unique, auto-incrementing ID:
ALTER TABLE [table] ADD COLUMN [column] int NOT NULL AUTO_INCREMENT PRIMARY KEY;

13. Inserting a record:
INSERT INTO [table] ([column], [column]) VALUES ('[value]', [value]');

14. MySQL function for datetime input:
NOW()

15. Selecting records:
SELECT * FROM [table];

16.Explain records:
EXPLAIN SELECT * FROM [table];

17. Selecting parts of records:
SELECT [column], [another-column] FROM [table];

18. Counting records:
SELECT COUNT([column]) FROM [table];

19.Counting and selecting grouped records:
SELECT *, (SELECT COUNT([column]) FROM [table]) AS count FROM [table] GROUP BY [column];

20. Delete all records in a table:
truncate table [table];

21. Removing table columns:
ALTER TABLE [table] DROP COLUMN [column];

22. Deleting tables:
DROP TABLE [table];

23.Deleting databases:
DROP DATABASE [database];

24. Custom column output names:
SELECT [column] AS [custom-column] FROM [table];

25.  Export a database dump:
mysqldump -u [username] -p [database] > db_backup.sql


26.  Import a database dump (more info here):
mysql -u [username] -p -h localhost [database] < db_backup.sql

27. Logout:
exit;

SSH- How to export/import a MySQL database via SSH

How to export/import a MySQL database via SSH

USERNAME - the MySQL user assigned to your database.
DATABASE - the name of your MySQL database.

1. Exporting a MySQL database

mysqldump -uUSERNAME -p DATABASE > backup.sql

2. Importing a MySQL database

mysql -uUSERNAME -p DATABASE < backup.sql

Wednesday, September 13, 2017

Wordpress- I want to add pagination list of categories

 <?php   
    $args = array(
   'parent' => 0,
   'hide_empty' => 0
 );

$categories = get_categories( $args );
echo $cat =  ceil(count( $categories )/5);   
 ?>
 <?php
  $j=0;
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $posts_per_page = 5;
$offset = ($posts_per_page * $paged) - 5 ;
$args = array(
'orderby' => 'name',
'parent' => 0,
'hide_empty'         => 0,
'number' => $posts_per_page,
'offset' => $offset,
'posts_per_page' => 5,
'paged' => $paged

//'exclude'            => '1,3,24,9'
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
$j++;
 //echo '<a href="' . get_category_link( $category->term_id ) . '">' .       $category->name . '</a><br/>';
 $catname = $category->name;
 $catttid = $category->term_taxonomy_id;
  //}
   ?>

<div class="row"><h3 class="cat-title"><?php echo $catname; ?></h3><hr  class="space" /></div>
  <?php } ?>
  </div></div>
   <!-- #main -->
  </div><!-- #primary -->
  <?php
  $big = 999999999; // need an unlikely integer
    echo '<div class="paginate-links">';
  echo paginate_links( array(
  'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  'format' => '?paged=%#%',
  'prev_text' => __('<<'),
  'next_text' => __('>>'),
  'current' => max( 1, get_query_var('paged') ),
  'total' => $cat
     ) );
echo '</div>';
  ?>

Thursday, August 31, 2017

Magento- Cannot display image inserted by WYSIWYG editor

I finally solved the problem. The cause of the problem is unprocessed shortcodes in the html content, which is the {{ media url="..." }} statement. Before echo this statement, the html content should be process by the processor from helper "cms". Below is the code:


$html_content = $content_from_db['content'];
$html_content = Mage::helper('cms')->getPageTemplateProcessor()->filter($html_content);
echo $html_content;