Articles with the programming tag

Custom snippets in vim

Set up

I use ultisnips for my snippets. To set this up, I have this in vimrc:

call plug#begin('~/.vim/plugged')

Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets' " Snippet support
call plug#end()


let g:UltiSnipsExpandTrigger="<c-e>" " Default is <tab>
let g:UltiSnipsEditSplit="vertical"
let g:UltiSnipsSnippetDirectories=["UltiSnips", "mysnippets"]

This …

Python Generators

Generators are functions that behave like iterators, thus can be used in for loops. For example, a generator that produces even numbers will look like:

def even_numbers(upperlimit):
    current = 0
    while current < upperlimit:
        yield current
        current += 2

Generators are also created using a syntax similar to list comprehension:

even …

Ansible and SSH Port

Hackers and bots try to log into servers all the time. They do this by trying random ssh logins into your server. A deterrent to this is to disable the default ssh port and set it to something else. Also, disable root login as this is the most common user …

Pagination: Review of Django's and Pelican's Implementation

Pagination is the process of dividing up a document into discrete pages (wikipedia). Django and Pelican have similar pagination implementations. This boils down to having a class that has accepts a sliceable object as one of its params, and returns a page containing list of items depending on number of …

Django's Cached Property

I've been trying to understand how django's decorator @cached_property works. Here is the class definition (original source):

# Got from django code base
class cached_property:
    """
    Decorator that converts a method with a single self argument into a
    property cached on the instance.
    Optional ``name`` argument allows you to make …

Testing Asynchronous Calls in VueJS

I frequently use asynchronous calls when coding in vuejs, especially when I get and send data to an online api. Initially, I found it difficult to test the asynchronous calls, but as I learned more, asynchronous tests became painless. I detail the methods I use to test promises and async …

Ansible

Ansible is an automation tool that easens work a lot. I just set it up once and from then on I can forget about configurations and settings for my projects. It's really great for doing repeatable tasks like setting up nginx for subdomains, redeploying django projects, updating the OS, etc …

My First Vim Function

I finally got down to writing my first vim function. It was a gruelling journey but I finally got through it. So I'll write down the problem I had and the fix I finally came up with as my solution.

Problem Statement

I usually keep a to do list of …