Articles in the Computer category

Python Partial For Classes

Partial sets up frozen arguments to functions. For example:

def power(x, y):
    return x ** y
# Partial implementation
from functools import partial
square = partial(power, y=2)
square(3) # Returns 9

Using partial in classes in the same way, will require passing the class instance as one of the parameters …

Python Timeit with Partial

The timeit module provides an easy way to time python code. I use it to check if a new code implementation runs faster than an older implementation.

Example usage of this is:

import timeit

timeit.timeit('list(range(100))')

def greet():
    print('Hello World')

timeit.timeit(greet, number=4)

Timeit …

Working With A Bad Codebase

I've worked with codebases that have made me frustrated. Some of the **features** I've seen include:

  • Naming the variables returned by a function $this and $return.
  • Having different languages in the same project. For example, I got one which had PHP, Python, Perl, JavaScript (node in the backend) and c …

Vimwiki Website Deployment using Git Hooks

I use vimwiki to keep a track of my notes. This includes book summaries, linux commands, recipes and miscellanous content. It's an amazing vim plugin that provides easy access and navigation to the content. This however works well only within vim.

I occasionally need to access these notes outside vim …

Huion 420 driver setup

I bought the Huion 420 because I wanted to experiment with graphics tablet and drawing on linux. I chose this primarily because of its cost. Out of the box, the device worked on my archlinux setup, however it behaved more like a mouse, with pressure sensitivity not detected. I did …

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_numbers = (n …

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 cached properties …

Sway Window Manager

Wayland is a display server that should work as a replacement for X. I've been thinking of trying it out for some time now. Detailed information about wayland and its history can be found in this article. The differences between xorg and wayland can be found here or in this …

Page 1 / 5 »