arundhaj

all that is technology

Python Pipenv quick start guide for managing packages and virtualenv

 

In this video I'm going to show you how to start using pipenv for your python projects.

Pipenv is a packaging tool which automatically creates and manages virtualenv and packages.

# To create a new virtual environment
$ mkdir pipenv-demo && cd pipenv-demo
$ pipenv shell
(venv) $ cat Pipfile

# To install a package and …

Using SQLAlchemy Expression for Partial JSON Update

 

In this article, I'll show how to partially update JSON column using SQLAlchemy expressions in MySQL database.

Say, we have a table named TableName with a JSON column named JsonColumn and the values in this JSON column is in the following format;

{
    "JsonAttribute": 5,
    "AnotherJsonAttribute": "Hello"
}

SQL statement to update …

Progressively adding table rows with Angular

 

I will show how to progressively add new rows to the table as the last row is being edited in Angular

In, app.component.html

<table class="progressive-table">
    <thead>
        <tr>
            <th>KEY</th>
            <th>VALUE</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
    <tr *ngFor="let pair of pairs; let idx = index …

Gambler's Ruin problem simulation

 

Detailed problem statement can be found here Gambler's Ruin

General solution to the problem is;

$1- a_1 = a_1 \sum\limits_{i = 1}^{k-1} \left(\frac{1 - p}{p}\right)^i$

For a fair game of $p = \frac{1}{2}$, $a_1 = \frac{1}{k}$

and, for an unfair game of $p …

Python f-string

 

f-strings is a short for "formatted strings", provides a convenient way to embed expressions inside string literals. This supports more formatting options than the old str.format() method supports.

Few examples;

String operation

>>> name = 'Arunkumar'
>>> f'My name is {name.upper()}'
'My name is ARUNKUMAR'

Float formatting

>>> import math
>>> f …