Pages

How to setup an SSH Key and connect to ubuntu server

  1. Create SSH Key using
    ssh-keygen

  2. Copy .pub key to server
    ssh-copy-id username@remote_host

  3. Validate previous steps by connecting to server
    ssh username@remote_host

  4. disable password authentication
  5. enable firewall

How to run Django Server from VSCode

 Hi Noonari, 

Here is how  I did it.


Step 1. Install following plugins

  • Python (by microsoft)
  • Live Server
Step 2. Set python version to your virtual env by following these steps in bullets in order
  1. Press `CTRL+SHIFT+P`
    This will open a command pallet in vscode.
  2. Set the python version by selecting if it is visible in the dropdowns or by typing it like
    `Python > <path-to-venv>/bin/python`
  3. create launch.json (normally it is automatically created when you press run button so first press run and see if it runs or not and then check or create launch.json)
  4. add this as contents of launch.json
    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Django",
                "type": "python",
                "request": "launch",
       
                "program": "${workspaceFolder}/monolith/manage.py",
                "args": [
                    "runserver",
                    "--noreload"
                ],
                "django": true,
                "justMyCode": true
            }
        ]
    }
Step 3. Run and test.

Beautifying your Terminal in Linux

 Hi Noonari, long time no see.

So this is about how you can increase your productivity by reducing clutter in your terminal. It may not be up to your test in future but trust me when I am writing this for you, this had mind blowing productivity results. 

  1. So here's the deal. You are deep in the repositories. And here you have to write some crazy long command on terminal. What would happen, it will jump to new line and destroy your readability. Here is how you can reduce the path of entire set of directories to just current directory.
                add PROMPT_DIRTRIM=1 to your .bashrc file.



  2. you also need to install fish. As this is going to be amazing for your future self. Then fish_config to open browser based configuration of fish.


  3. You need to find something in terminal for example a command that you ran but you do not know what it was. What you would normally do is press CTRL+r and keep on pressing them until you find it, right? Now you do not have to do this. But just press CTRL+r once and scroll through the commands with arrow keys using this

      
    git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install

With this today's lecture ends. Now remember Noonari, you will keep on receiving more of these for you to use in future. I will keep on typing that I can for you here. Stay sharp and stay hungry. Thats how you got this much of success in career.

How to increase swap size in Ubuntu? (works for all Ubuntu Flavors)

Here we will see how we can increase the SwapSize  in Ubuntu!

  1. Open Terminal
  2. Enter "sudo swapon --show"
    1. This is show you the details of current swap size
  3. Enter "df -h"
    1. This is to see how much disk space you have.
  4. Now Turn the swap off using "sudo swapoff -a"
    1. This will allow us to write to swap file without being interrupted by File in Use error
  5. This is the important part and requires some knowledge if you want to understand what is going on under the hood. But high level understanding here is as follows:
    1. If have xyz GB of ram, your swap file size will be XYZ GB + 2GB at the minimum. In my case, I had 16GB of Ram on Laptop, but current swap file was of 2GB only. When created automatically using the command that follows, it made 27GB in SwapFile.
    2. Enter "sudo dd if=/dev/zero of=/swapfile bs=5M count=5120 status=progress"
    3. Wait for the entire process to end.
  6. Now lets give this file root only permissions: "sudo chmod 600 /swapfile"
  7. Now mark this file as swap space file: "sudo mkswap /swapfile"
  8.  Now make this file permanent so that restart of system doesn't revert it to previous state: 
    1. "echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab"
  9. Now turn the swap back on using "sudo swapon /swapfile"
  10. Use HTOP to see change in swap size.

What is difference between queryset and get_queryset?

In your example, overriding queryset and get_queryset have the same effect. I would slightly favour setting get_queryset because it's more verbose.
When you set queryset, the queryset is created only once, when you start your server. On the other hand, the get_queryset method is called for every request.
That means that get_queryset is useful if you want to adjust the query dynamically. For example, you could return objects that belong to the current user:
class IndexView(generic.ListView):
    def get_queryset(self):
        """Returns Polls that belong to the current user"""
        return Poll.active.filter(user=self.request.user).order_by('-pub_date')[:5]
Another example where get_queryset is useful is when you want to filter based on a callable, for example, return today's polls:
class IndexView(generic.ListView):
    def get_queryset(self):
        """Returns Polls that were created today"""
        return Poll.active.filter(pub_date=date.today())
If you tried to do the same thing by setting queryset, then date.today() would only be called once, when the view was loaded, and the view would display incorrect results after a while.
class IndexView(generic.ListView):
    # don't do this!
    queryset = Poll.active.filter(pub_date=date.today())

How to enable minimize action on Ubuntu 18.04

This quick tutorial shows you how to enable ‘Minimize on click’, the feather that minimize the running application window when you clicking on the icon in left launcher.
While Settings and Gnome Tweaks utilities do not provide an option to toggle the action, you can enable the feature with Dconf Editor.
1. Search for and install dconf editor in Ubuntu Software:
install-dconf-editor
2. Then launch the tool and navigate to org -> gnome -> shell -> extensions -> dash-to-dock. Scroll download, and click go to settings for click-action.
dconf-clickaction
3. Finally disable default setting and choose “minimize” as its value from drop-down menu:
clickaction-minimize
That’s it.

Privacy Policy

This app doesn't record any user data. It doesn't require any special permissions. It is also free and is developed for fun.