How to install a package in terminal without “Do you want to continue [Y/n]?” prompt?

Well when you want to install something you would normally do:

sudo apt-get install yourPackageName

In the manual when you type man apt-get there is a part that has been said:

 -y, --yes, --assume-yes

           Automatic yes to prompts; assume "yes" as answer to all prompts and
           run non-interactively. If an undesirable situation, such as
           changing a held package, trying to install a unauthenticated
           package or removing an essential package occurs then apt-get will
           abort. Configuration Item: APT::Get::Assume-Yes.

So to skip the YES part all we we need to do is:

sudo apt-get install -y yourPackageName

Enjoy installing without YES. ;-)

Undo git commits that have already been pushed to upstream branch

Sometimes you make your history dirty as what I did today and had for commits+merge just to push 1 commit. well don’t look at me like that it happens sometime. I’m not a machine!

First you should reset your local branch to where you want with its corresponding sha1 hash as below (you should put your sha1 instead of mine ):


git reset --hard abd000b3ce70557f0

Check that tip of the HEAD is in the place you want to. Now you have to delete the remote branch and recreate it from your local branch. For that you need to have delete permission on your remote repo. set the below configuration:


git config --global receive.denyDeletes false

OK now in your local system delete your desired branch as below (in my case it is hotfix):


git push origin :hotfix

You should see a message as below:


To root@172.*.*.*:/var/local/xxxx/local_core.repo
- [deleted]         hotfix

You now need to push to remote repository from where you reset your head (in my case abd000b3ce70557f0):


git push origin abd000b3ce70557f0:refs/heads/hotfix

Well done! You should have a clean repo now. ;-)

Browser view for HTML file from vim

Are you a big FAN of vim. Do you spend a lot of time in vim and editing HTML files. OK then. So if you want to preview HTML file from vim continue reading.

Create a .vimrc file in your ~ (home) directory in case you don’t have it. Paste the following code inside of the file:

nnoremap <C-g> :!google-chrome %<CR> " browser preview with ctrl-p
nnoremap <C-f> :!firefox %<CR> " browser preview with ctrl-o
nnoremap <C-c> :!chromium-browser %<CR> " browser preview with ctrl-c

Now all you need to do is to source your file or type bash and then zsh again. Now all you need to do is for example press CTRL+f for firefox and preview your HTML file.

It has its own drawback though. Every time you press CTRL+f/g/c a new tab will be opened.

How to remove index.php in Yii

Intro

The purpose of removing index.php is to make URLs nicer and more user-friendly. It doesn’t affect your way of doing things. The difference would be:

http://www.bugx.ir/index.php/display/demo

to

http://www.bugx.ir/display/demo

 

It’s obvious that users feel more comfortable with the second one.

Remove index.php in Yii – Howto

You should be aware that handling URLs and mapping a URL to another is a matter of apache rewrite rules rather than Yii. What we want to do is to tell Yii to hide index.php in URLs and tell Apache rewrite module to map URLs.

You should enable rewrite module in apache. In ubuntu you simply need to use a2enmod:  sudo a2enmod rewrite.

Now restart you apache with:  sudo service apache2 restart

Create a .htaccess file in your root directory and paste the following code in your newly created file:

Options+FollowSymLinks
IndexIgnore*/*
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

The above command turns RewriteEngine on and checks if requested resource is not file or directory then maps that request to index.php.

Now all you need to do is to hide index.php in Yii. Go to YourYiiProject/Protected/Config/main.php and go to UrlManager section (Uncomment this part in case it’s commented) and add the highlighted line to your project:


'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),

Voila! Your done. Enjoy your clean URLs. ;-)