megacolorboy

Abdush Shakoor's Weblog

Writings, experiments & ideas.

Check Ubuntu version

Want to know the current version of your Ubuntu distro? Type this:

lsb_release -r

Save a file

Want to save your work? Type :w

Type :wq! to save your file and quit VIM at the same time.

Using SSH with a private key

Got a .pem key but don't know how to SSH to your server, just do this:

ssh -i name_of_key user@domain -p 22

BONUS: Convert .ppk to .pem key

Recently, I started working from home and as a programmer, it's pretty common to access the company server for development purposes.

Back in the office, I used to access it using PuTTY but now that I'm using a linux machine, I thought of accessing it via Terminal but there's a catch, I can't use .ppk key to access it.

So, I did a little research and figured that I can easily convert it using puttygen

Open up your terminal and type:

sudo apt install putty-tools

Now, convert your private key to PEM format:

puttygen yourprivate.ppk -O private-openssh -o your_new_key.pem

That's it and you're good to go!

Set up reCaptcha in Laravel

I mean, come on, you need to have a reCaptcha in your forms, no matter what.

Here are the steps:

1. Install using Composer

composer require anhskohbo/no-captcha

2. Add provider and alias to configuration

Open your config/app.php file and add this to your providers array:

<?php
Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class,
?>

And this to your aliases array:

<?php
'NoCaptcha' => Anhskohbo\NoCaptcha\Facades\NoCaptcha::class,
?>

3. Publish configuration

php artisan vendor:publish --provider="Anhskohbo\NoCaptcha\NoCaptchaServiceProvider"

4. Add sitekey and secret key to .env file

Open your .env file and add this:

NOCAPTCHA_SITEKEY=yoursitekey
NOCAPTCHA_SECRET=yoursecret

How to use it?

Now, you can use it in your validator using like this:

<?php
$validate = Validator::make(Input::all(),[
    'g-recaptcha-response' => 'required|captcha'
]);
?>

Clear all lines

  1. Switch to normal mode by pressing ESC key
  2. Press gg and it will take you to first line of the file.
  3. Then type dG and it will clear all the lines from start to the end of the file.

Find files containing specific text

This helped me a lot whenever I'm in a remote server trying to find a keyword or specific text amongst a bunch of files.

This command will save you a lot of time:

grep -rwn [path] -e 'pattern'
  • r stands for recursion
  • n displays the line number
  • w matches the whole word

Refer to man find pages for more info.

View the filesize in human-readable format

Wanted to view the size of a file in terminal but don't understand the number of bytes displayed? No worries, just type this command and it'll display the size of the in human-readable format:

du -sh filename.ext

Zip a file

This comes in handy especially whenever you want to download multiples files from a server or take backups.

zip [option] output_file input1 input2

For example: if you want to zip an entire directory with it's file contents, just do this:

zip -r myfiles.zip folder/