Wednesday, November 29, 2023

2.2 - Odd occurrences in an array

Odd Occurrences in an Array

Problem

A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired.

Write a function:

def solution(A)

that, given an array A consisting of N integers fulfilling the above conditions, returns the value of the unpaired element.

For example, given array A such that:

A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9

the function should return 7, as explained in the next slide.

Write an efficient algorithm for the following assumptions:

N is an odd integer within the range [1..1,000,000];

each element of array A is an integer within the range [1..1,000,000,000];

all but one of the values in A occur an even number of times.

Example

For example, in array A such that:

A[0] = 9 A[1] = 3 A[2] = 9

A[3] = 3 A[4] = 9 A[5] = 7

A[6] = 9

the elements at indexes 0 and 2 have value 9,

the elements at indexes 1 and 3 have value 3,

the elements at indexes 4 and 6 have value 9,

the element at index 5 has value 7 and is unpaired.

Trick: Use of Key-Value Pair and a Set

The Key-Value pair in the heading could be a dictionary (dict) in Python (or HashMap in Java).

We would need to traverse the input array once and maintain two data structures (a dict and a set).

Dict named counts: would contain the elements as keys

Set named odds: would contain the elements whose number of occurrences are found to be odd.

Note during the program’s lifetime, size of set ‘odds’ would change but by the end of iteration, there would be only one element in it.

Java Based Code of a Variant of The Solution From My Friend Rohit

import java.util.*; 
class Solution { 
 public int solution(int[] A) { 
  Map<Integer, Integer> integerMap = new HashMap<Integer, Integer>(); 
  for (int i = 0; i < A.length; A++)) {
   if (!integerMap.containsKey(A[i])) { 
    integerMap.put(A[i], 1); 
   } 
   else { 
    int count = integerMap.get(A[i]);      	 
    integerMap.put(A[i], count + 1); 
  }
  int missingNumber = 0; 
  for (Map.Entry<Integer, Integer> map : integerMap.entrySet()) 
  { 
   if (map.getValue() % 2 == 1) { 
    missingNumber = map.getKey(); 
  } 
  return missingNumber; 
 }
}  

In Python Code

def solution(A):
    counts = dict()
    odds = set()

    for i in A:
        if i in counts:
            counts[i] += 1
        else:
            counts[i] = 1

        if counts[i] % 2 == 1:
            odds.add(i)
        else:
            odds.remove(i)

    return odds.pop()  

Time Complexity

Detected time complexity:

O(N) or O(N*log(N))

Test Cases

-simple1

simple test n=5

-extreme_single_item

[42]

-small1

small random test n=201

- medium1

medium random test n=2,001

big1

big random test n=999,999, multiple repetitions

-big2

big random test n=999,999

Tags: Technology,Algorithms,

2.1 - Cyclic rotation (Problem of Arrays)

Cyclic Rotation

Problem

An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place).

The goal is to rotate array A K times; that is, each element of A will be shifted to the right K times.

Write a function:

def solution(A, K)

that, given an array A consisting of N integers and an integer K, returns the array A rotated K times.

Assume that:

N and K are integers within the range [0..100];

each element of array A is an integer within the range [−1,000..1,000].

In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

Example

For example, given

A = [3, 8, 9, 7, 6]

K = 3

the function should return [9, 7, 6, 3, 8]. Three rotations were made:

[3, 8, 9, 7, 6] -> [6, 3, 8, 9, 7]

[6, 3, 8, 9, 7] -> [7, 6, 3, 8, 9]

[7, 6, 3, 8, 9] -> [9, 7, 6, 3, 8]

For another example, given

A = [0, 0, 0]

K = 1

the function should return [0, 0, 0]

Given

A = [1, 2, 3, 4]

K = 4

the function should return [1, 2, 3, 4]

The Modulus Trick

Instead of writing code to move each element multiple times towards their final state, we move each element once to their final position.

We swap the elements using the following formula:

B[ (i+K) % len(A) ] = A[i]

Note: % is the modulus operator that basically returns the remainder from the division operation (as in long division method)

In Code

def solution(A, K):
    rtn = [0 for i in A]

    for i in range(len(A)):
        rtn[(i + K) % len(A)] = A[i]
    return rtn

Test Cases

print(solution([1,2,3], 1))

print(solution([3, 8, 9, 7, 6], 3))

print(solution([0, 0, 0], 1))

[3, 1, 2]

[9, 7, 6, 3, 8]

[0, 0, 0]

Other Test Case Types

-extreme_empty

empty array

-single

one element, 0 <= K <= 5

-double

two elements, K <= N

-small1

small functional tests, K < N

-small_random_all_rotations

small random sequence, all rotations, N = 15

-medium_random

medium random sequence, N = 100

-maximal

maximal N and K

Tags: Algorithms,Technology,

Tuesday, November 28, 2023

Binary Gap (Problem of Iterations) - Lesson in Algorithms Analysis and Design

Binary Gap

Find longest sequence of zeros in binary representation of an integer.

Problem

A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.

For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps. The number 32 has binary representation 100000 and has no binary gaps.

Write a function:

def solution(N)

that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.

Write an efficient algorithm for the following assumptions:

N is an integer within the range [1..2,147,483,647].

Example

For example, given N = 1041

The function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5.

Given N = 32

The function should return 0, because N has binary representation '100000' and thus no binary gaps.

Ideas For Code

Step 1: A binary gap can be represented using the RegEx:

1(0+)1

But this pattern would not be suffice because it would not work for a binary like: 10001001

As here the second one is part of two Binary Gaps (First ‘10001’ and second ‘1001’).

So we reduce the pattern to: 10+

This is to prevent overlap between binary gaps we want to capture.

Step 2: Find all such patterns in the binary of the integer

Step 3: Check if there is a closing one at the end

Step 4: Store the lengths of all such binary gaps

Step 5: Return the maximum length

Python Code (Version 1)

import re

pattern = re.compile("10+")

def solution(N):

    n = str(bin(N))[2:]
    matches = re.finditer(pattern, n)
    matches_ = []
    lengths = []
    for i in matches:
        if(len(n) > i.span()[1]):
            if(n[i.span()[1]] == '1'):
                matches_.append(i.group())
                lengths.append(i.group().count('0'))

    if len(lengths) > 0:
        rtn = max(lengths)
    else:
        rtn = 0
    return rtn  

Can we do better?

Here in the Step 5 and 6: Where we want to print the maximum length

Here the Space Complexity is of the order of n, O(n) (number of binary gaps in input)

Step 5: Instead of storing all the lengths, we can simply store the maximum length across all the binary gaps.

Step 6: Return the maximum length obtained in Step 5

Also, there is added Time Complexity of finding the maximum length from all the accumulated lengths.

Python Code (Version 2)

import re

pattern = re.compile("10+")

def solution(N):

    n = str(bin(N))[2:]
    matches = re.finditer(pattern, n)
    matches_ = []
    
    max_length = 0

    for i in matches:
        if(len(n) > i.span()[1]):
            if(n[i.span()[1]] == '1'):
                matches_.append(i.group())
                if i.group().count('0') > max_length:
                    max_length = i.group().count('0')

    return max_length

Test Cases

- extremes

n=1, n=5=101_2 and n=2147483647=2**31-1

- trailing_zeroes

n=6=110_2 and n=328=101001000_2

- power_of_2

n=5=101_2, n=16=2**4 and n=1024=2**10

- simple1

n=9=1001_2 and n=11=1011_2

- medium1

n=51712=110010100000000_2 and n=20=10100_2

- large1

n=6291457=11000000000000000000001_2

Test Results

print("Testing...")

print(solution(1041))

print(solution(15))

print(solution(32))

print(solution(1))

print(solution(2147483647))

print(solution(6291457))

print(solution(74901729))

print(solution(805306373))

print(solution(1376796946))

print(solution(1073741825))

print(solution(1610612737))

Testing...

5

0

0

0

0

20

4

25

5

29

28

Future Scope

  • How can we implement the same thing in JavaScript?
  • How can we implement the same thing in Java?

Homework

Generate 10 random natural numbers and return the maximum number generated.

Tags: Algorithms,Technology

Monday, November 27, 2023

Psychology of Money (by Morgan Housel) - Summary

Translate this page:

Before we begin to summarize the book... 
First, let me tell you a story about a dentist appointment gone horribly awry.

It teaches us something vital about the dangers of giving advice about what to do with your money.
Clarence Hughes went to the dentist in 1931. His mouth was radiating pain.
His dentist put him under crude anesthesia to ease the pain. When Clarence awoke hours later he had 16 fewer teeth and his tonsils removed.

And then everything went wrong. Clarence died a week later from his surgery's complications.

His wife sued the dentist, but not because the surgery went awry. Every surgery risked death in 1931.
Clarence, she said, never consented to the procedures in the first place, and wouldn't if he were asked.

The case wove through courts, but went nowhere. Consent between doctor and patient wasn't black and white in 1931. One court summed up the idea that doctors require freedom to make the best medical decisions: “Without such, we could not enjoy the advancement of science.”

For most of history the ethos of medicine was that the doctor's job was to fix the patient, and what the patient thought about the doctor's treatment plans wasn't relevant. Dr. Jay Katz wrote about the philosophy in his book The Silent World Between Doctor and Patient:Doctors felt that in order to accomplish that objective they were obligated to attend to their patients' physical and emotional needs and to do so on their own authority, without consulting with their patients about the decisions that needed to be made. The idea that patients may also be entitled to sharing the burdens of decisions with their doctors was never part of the ethos of medicine.

This wasn't ego or malice. It was a belief in two points: Every patient wants to be cured.
There is a universal and right way to cure them.
Not requiring patient consent in treatment plans makes sense if you believe in those two points.
But that's not how medicine works.

In the last 50 years medical schools subtly shifted teaching away from treating disease and toward treating patients. That meant laying out the options of treatment plans, and then letting the patient decide the best path forward.

This trend was partly driven by patient-protection laws, partly by Katz's influential book, which argued that patients have wildly different views about what's worth it in medicine, so their beliefs have to be taken into consideration. Katz wrote:It is dangerous nonsense to assert that in the practice of their art and science physicians can rely on their benevolent intentions, their abilities to judge what is the right thing to do ... It is not that easy. Medicine is a complex profession and the interactions between physicians and patients are also complex.

That last line is important. “Medicine is a complex profession and the interactions between physicians and patients are also complex.”
You know what profession is the same? Financial advice.
I can't tell you what to do with your money, because I don't know you.
I don't know what you want. I don't know when you want it. I don't know why you want it.

So I'm not going to tell you what to do with your money. I don't want to treat you like a dentist treated Clarence Hughes.

But doctors and dentists aren't useless, obviously. They have knowledge.
They know the odds. They know what tends to work, even if patients come to different conclusions about what kind of treatment is right for them.
Financial advisors are the same. There are universal truths in money, even if people come to different conclusions about how they want to apply those truths to their own finances.
With that caveat in place, let's look at a few short recommendations that can help you make better decisions with your money.

1.
Go out of your way to find humility when things are going right and forgiveness/compassion when they go wrong. Because it's never as good or as bad as it looks. The world is big and complex. Luck and risk are both real and hard to identify. Do so when judging both yourself andothers. Respect the power of luck and risk and you'll have a better chance of focusing on things you can actually control. You'll also have a better chance of finding the right role models.

2.
Less ego, more wealth. Saving money is the gap between your ego and your income, and wealth is what you don't see. So wealth is created by suppressing what you could buy today in order to have more stuff or more options in the future. No matter how much you earn, you will never build wealth unless you can put a lid on how much fun you can have with your money right now, today.

3.
Manage your money in a way that helps you sleep at night. That's different from saying you should aim to earn the highest returns or save a specific percentage of your income. Some people won't sleep well unless they're earning the highest returns; others will only get a good rest if they're conservatively invested. To each their own. But the foundation of, “does this help me sleep at night?” is the best universal guidepost for all financial decisions.

4.
If you want to do better as an investor, the single most powerful thing you can do is increase your time horizon. Time is the most powerful force in investing. It makes little things grow big and big mistakes fade away. It can't neutralize luck and risk, but it pushes results closer towards what people deserve.

5.
Become OK with a lot of things going wrong. You can be wrong half the time and still make a fortune, because a small minority of things account for the majority of outcomes. No matter what you're doing with your money you should be comfortable with a lot of stuff not working. That's just how the world is. So you should always measure how you've done by looking at your full portfolio, rather than individual investments. It is fine to have a large chunk of poor investments and a few outstanding ones. That's usually the best-case scenario. Judging how you've done by focusing on individual investments makes winners look more brilliant than they were, and losers appear more regrettable than they should.

6.
Use money to gain control over your time, because not having control of your time is such a powerful and universal drag on happiness. The ability to do what you want, when you want, with who you want, for as long as you want to, pays the highest dividend that exists in finance.

7.
Be nicer and less flashy. No one is impressed with your possessions as much as you are. You might think you want a fancy car or a nice watch.
But what you probably want is respect and admiration. And you're more likely to gain those things through kindness and humility than horsepower and chrome.

8.
Save. Just save. You don't need a specific reason to save. It's great to save for a car, or a downpayment, or a medical emergency. But saving for things that are impossible to predict or define is one of the best reasons to save. Everyone's life is a continuous chain of surprises.
Savings that aren't earmarked for anything in particular is a hedge against life's inevitable ability to surprise the hell out of you at the worst possible moment.

9.
Define the cost of success and be ready to pay it. Because nothing worthwhile is free. And remember that most financial costs don't have visible price tags. Uncertainty, doubt, and regret are common costs in the finance world. They're often worth paying. But you have to view them as fees (a price worth paying to get something nice in exchange) rather than fines (a penalty you should avoid).

10.
Worship room for error. A gap between what could happen in the future and what you need to happen in the future in order to do well is what gives you endurance, and endurance is what makes compounding magic over time. Room for error often looks like a conservative hedge, but if it keeps you in the game it can pay for itself many times over.

11.
Avoid the extreme ends of financial decisions. Everyone's goals and desires will change over time, and the more extreme your past decisions were the more you may regret them as you evolve.

12.
You should like risk because it pays off over time. But you should be paranoid of ruinous risk because it prevents you from taking futurerisks that will pay off over time.

13.
Define the game you're playing, and make sure your actions are not being influenced by people playing a different game.

14.
Respect the mess. Smart, informed, and reasonable people can disagree in finance, because people have vastly different goals and desires. There is no single right answer; just the answer that works for you.

Thank you!
Tags: Book Summary,Finance,

Friday, November 24, 2023

Hour One With SQLite Database

What does SQLite database contain?

SQLite Database has data stored in it in the form of tables.

What does a table contain?

It contains rows and columns.

A row is also called a record or tuple.

A column is also called an attribute.

Let's say we have a table called 'marks'.

What all columns can table of marks contain?

1. Year

2. Class

3. Subject

4. Marks

Four Basic Types of Operations We Do in Databases

Assuming you have a database with you:

Insert: To add or create a new record or tuple in your database.

Select: To read a records or tuples present in the database.

Update: To change an existing record or tuple in your database.

Delete: To remove or delete a record or tuple from the database.

Can be remembered using the acronym: CRUD for Create, Read, Update, Delete

Single File For Storing a Database

Note: SQLite uses a single file for storing data related a database. For example: we have two databases with us and there names are 'marks.db' and 'sharks.db'.

(base) ashish@ashish:~/Desktop/ws/sqlite_db$ ls

marks.csv marks.db sharks.db

(base) ashish@ashish:~/Desktop/ws/sqlite_db$

Creating a Database file and Creating a Table

(base) ashish@ashish:~$ sqlite3 sharks.db

# Here, sqlit3 is your application and sharks.db is the filename for that application to open.

SQLite version 3.39.3 2022-09-05 11:02:23
Enter '.help' for usage hints.

sqlite> CREATE TABLE sharks(id integer NOT NULL, name text NOT NULL, sharktype text NOT NULL, length integer NOT NULL);

INSERT INTO sharks VALUES (1, 'Sammy', 'Greenland Shark', 427);
INSERT INTO sharks VALUES (2, 'Alyoshka', 'Great White Shark', 600);
INSERT INTO sharks VALUES (3, 'Himari', 'Megaladon', 1800);

sqlite> select * from sharks;


1|Sammy|Greenland Shark|427
2|Alyoshka|Great White Shark|600
3|Himari|Megaladon|1800    

sqlite>

(base) ashish@ashish:~/Desktop/ws/sqlite_db$ sqlite3 sharks.db

SQLite version 3.39.3 2022-09-05 11:02:23

Enter '.help' for usage hints.

sqlite> .schema sharks

CREATE TABLE sharks(id integer NOT NULL, name text NOT NULL, sharktype text NOT NULL, length integer NOT NULL);

sqlite>

Viewing the Structure of a Table

Exploring a Database file

(base) ashish@ashish:~/Desktop/ws/sqlite_db$ sqlite3 sharks.db

SQLite version 3.39.3 2022-09-05 11:02:23

Enter '.help' for usage hints.

sqlite> .tables

sharks

sqlite> select * from sharks;

1|Sammy|Greenland Shark|427

2|Alyoshka|Great White Shark|600

3|Himari|Megaladon|1800

sqlite> ^Z

[3]+ Stopped sqlite3 sharks.db

(base) ashish@ashish:~/Desktop/ws/sqlite_db$ sqlite3 marks.db

SQLite version 3.39.3 2022-09-05 11:02:23

Enter '.help' for usage hints.

sqlite> .tables

marks

sqlite> select * from marks;

2023|8|english|75

2023|8|math|85

2023|8|computer|90

2022|7|english|90

2022|7|math|85

2022|7|computer|95

2023|8|physics|99

2023|8|chemistry|97

2023|8|biology|95

sqlite>

Import a CSV file

(base) ashish@ashish:~/Desktop/ws/sqlite_db$ sqlite3 marks.db
SQLite version 3.39.3 2022-09-05 11:02:23
Enter '.help' for usage hints.
sqlite>
sqlite> .tables
sqlite> .mode csv
sqlite> .import ./marks.csv marks

First line in marks.csv should contain the header with column names.

sqlite> .tables

marks

sqlite>

sqlite> select * from marks;

2023,8,english,75

2023,8,math,80

2023,8,computer,90

2022,7,english,90

2022,7,math,85

2022,7,computer,95

sqlite>

Inserting a single row

sqlite> .schema marks

CREATE TABLE IF NOT EXISTS 'marks' ('year' TEXT, 'class' TEXT, 'subject' TEXT, 'marks' TEXT);

sqlite>

sqlite> insert into marks (year, class, subject, marks) values (2023, 8, 'sanskrit', 90);

sqlite> select * from marks;

2023|8|english|75

2023|8|math|80

2023|8|computer|90

2022|7|english|90

2022|7|math|85

2022|7|computer|95

2023|8|sanskrit|90

sqlite>

Inserting multiple rows

sqlite> insert into marks (year, class, subject, marks) values (2023, 8, 'physics', 99), (2023, 8, 'chemistry', '97'), (2023, 8, 'biology', 95);

sqlite> select * from marks;

2023|8|english|75

2023|8|math|80

2023|8|computer|90

2022|7|english|90

2022|7|math|85

2022|7|computer|95

2023|8|sanskrit|90

2023|8|physics|99

2023|8|chemistry|97

2023|8|biology|95

Selection and Filtering

sqlite> select * from marks where marks > 90;

2022|7|computer|95

2023|8|physics|99

2023|8|chemistry|97

2023|8|biology|95

sqlite> select * from marks where class = 8;

2023|8|english|75

2023|8|math|80

2023|8|computer|90

2023|8|sanskrit|90

2023|8|physics|99

2023|8|chemistry|97

2023|8|biology|95

Update

sqlite> select * from marks where class = 8 and subject = 'math';

2023|8|math|80

sqlite>

sqlite> update marks set marks = marks + 5 where class = 8 and subject = 'math';

sqlite> select * from marks where class = 8 and subject = 'math';

2023|8|math|85

Deleting a record

sqlite> select count(*) from marks where subject = 'sanskrit';

1

sqlite> select * from marks where subject = 'sanskrit';

2023|8|sanskrit|90

sqlite> delete from marks where subject = 'sanskrit';

sqlite> select * from marks where subject = 'sanskrit';

sqlite> select count(*) from marks where subject = 'sanskrit';

0

sqlite>

Cursor

Row Num

0:ID

1:Name

2:SharkType

3:Length

0

1

Sammy

Greenland Shark

427

1

2

Alyoshka

Great White Shark

600

2

3

Himari

Megaladon

1800

[0][0]

[0][1]

[0][2]

[0][3]

[1][0]

[1][1]

[1][2]

[1][3]

[2][0]

[2][1]

[2][2]

[2][3]

A cursor allows us to iterate over a table.

And, a table can be viewed as a list of rows.

And, a row can be viewed as a tuple of cells.

In Code (Part 1)

import sqlite3

conn = sqlite3.connect('sharks.db')

print('Opened database successfully')

cursor = conn.execute('SELECT id, name, sharktype, length FROM sharks')

for row in cursor:

print('ID = ', row[0])

print('NAME = ', row[1])

print('SHARKTYPE = ', row[2])

print('LENGTH = ', row[3])

print('\n')

print('Operation done successfully')

conn.close()

Output

Opened database successfully

ID = 1

NAME = Sammy

SHARKTYPE = Greenland Shark

LENGTH = 427

ID = 2

NAME = Alyoshka

SHARKTYPE = Great White Shark

LENGTH = 600

ID = 3

NAME = Himari

SHARKTYPE = Megaladon

LENGTH = 1800

Operation done successfully

Tags: Technology,Database,

Know Your Linux Hardware Using inxi

On Ubuntu

(base) ashish@ashish:~$ inxi Command 'inxi' not found, but can be installed with: sudo apt install inxi (base) ashish@ashish:~$ inxi CPU: dual core Intel Core i5-4300U (-MT MCP-) speed/min/max: 798/800/2900 MHz Kernel: 6.2.0-37-generic x86_64 Up: 2h 16m Mem: 3127.7/7624.3 MiB (41.0%) Storage: 223.57 GiB (45.9% used) Procs: 241 Shell: Bash inxi: 3.3.13 (base) ashish@ashish:~$ inxi -Fxz System: Kernel: 6.2.0-37-generic x86_64 bits: 64 compiler: N/A Desktop: GNOME 42.9 Distro: Ubuntu 22.04.3 LTS (Jammy Jellyfish) Machine: Type: Laptop System: LENOVO product: 20ARS2C00D v: ThinkPad T440s serial: <superuser required> Mobo: LENOVO model: 20ARS2C00D v: 0B98401 WIN serial: <superuser required> UEFI-[Legacy]: LENOVO v: GJET79WW (2.29 ) date: 09/03/2014 Battery: ID-1: BAT0 charge: 18.0 Wh (98.4%) condition: 18.3/23.2 Wh (79.0%) volts: 12.1 min: 11.1 model: SONY 45N1111 status: Not charging ID-2: BAT1 charge: 1.4 Wh (63.6%) condition: 2.2/23.5 Wh (9.3%) volts: 12.4 min: 11.4 model: LGC 45N1127 status: Charging CPU: Info: dual core model: Intel Core i5-4300U bits: 64 type: MT MCP arch: Haswell rev: 1 cache: L1: 128 KiB L2: 512 KiB L3: 3 MiB Speed (MHz): avg: 1074 high: 1896 min/max: 800/2900 cores: 1: 800 2: 1896 3: 800 4: 800 bogomips: 19953 Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx Graphics: Device-1: Intel Haswell-ULT Integrated Graphics vendor: Lenovo driver: i915 v: kernel bus-ID: 00:02.0 Device-2: Lite-On Integrated Camera type: USB driver: uvcvideo bus-ID: 2-8:2 Display: x11 server: X.Org v: 1.21.1.4 driver: X: loaded: modesetting unloaded: fbdev,vesa gpu: i915 resolution: 1600x900~60Hz OpenGL: renderer: Mesa Intel HD Graphics 4400 (HSW GT2) v: 4.6 Mesa 23.0.4-0ubuntu1~22.04.1 direct render: Yes Audio: Device-1: Intel Haswell-ULT HD Audio vendor: Lenovo driver: snd_hda_intel v: kernel bus-ID: 00:03.0 Device-2: Intel 8 Series HD Audio vendor: Lenovo driver: snd_hda_intel v: kernel bus-ID: 00:1b.0 Sound Server-1: ALSA v: k6.2.0-37-generic running: yes Sound Server-2: PulseAudio v: 15.99.1 running: yes Sound Server-3: PipeWire v: 0.3.48 running: yes Network: Device-1: Intel Ethernet I218-LM vendor: Lenovo ThinkPad X240 driver: e1000e v: kernel port: 3080 bus-ID: 00:19.0 IF: enp0s25 state: down mac: <filter> Device-2: Intel Wireless 7260 driver: iwlwifi v: kernel bus-ID: 03:00.0 IF: wlp3s0 state: up mac: <filter> Drives: Local Storage: total: 223.57 GiB used: 102.66 GiB (45.9%) ID-1: /dev/sda vendor: Western Digital model: WDS240G2G0A-00JH30 size: 223.57 GiB Partition: ID-1: / size: 218.51 GiB used: 102.65 GiB (47.0%) fs: ext4 dev: /dev/sda3 ID-2: /boot/efi size: 512 MiB used: 6.1 MiB (1.2%) fs: vfat dev: /dev/sda2 Swap: ID-1: swap-1 type: file size: 2 GiB used: 0 KiB (0.0%) file: /swapfile Sensors: System Temperatures: cpu: 45.0 C mobo: N/A Fan Speeds (RPM): fan-1: 0 Info: Processes: 240 Uptime: 2h 17m Memory: 7.45 GiB used: 3.09 GiB (41.5%) Init: systemd runlevel: 5 Compilers: gcc: 11.4.0 Packages: 2138 Shell: Bash v: 5.1.16 inxi: 3.3.13 $ free -h total used free shared buff/cache available Mem: 7.4Gi 2.3Gi 1.5Gi 473Mi 3.6Gi 4.4Gi Swap: 2.0Gi 0B 2.0Gi (base) ashish@ashish:~$ --- --- --- --- ---

On Termux on Android Tablet PC by Samsung

$ inxi Use of uninitialized value $sc_freq_max[0] in join or string at /data/data/com.termux/files/usr/bin/inxi line 10313. CPU: 2x 6-core AArch64 (-MT MCP AMP-) speed/min/max: 961/614:1229/2002 MHz Kernel: 4.14.199-27204164-abX205XXU3CWI3 aarch64 Up: 17m Mem: 1.65/2.45 GiB (67.4%) Storage: 15.52 GiB/Total N/A Procs: 2 Shell: Bash inxi: 3.3.31 $ inxi -Fxz System: Kernel: 4.14.199-27204164-abX205XXU3CWI3 arch: aarch64 bits: 64 compiler: N/A Console: pty pts/0 Distro: Android Machine: Type: ARM System: UNISOC T618 Use of uninitialized value in string eq at /data/data/com.termux/files/usr/bin/inxi line 10234. inxi line 10313. CPU: Info: 2x 6-core model: AArch64 bits: 64 type: MT MCP AMP arch: aarch64 rev: 0 Speed (MHz): avg: 961 high: 2002 min/max: 614:1229/2002 boost: disabled cores: 1: 614 2: 614 3: 614 4: 614 5: 614 6: 614 7: 2002 8: 2002 bogomips: 416 Features: Use -f option to see features Graphics: Message: No ARM data found for this feature. Display: server: No display server data found. Headless machine? tty: 80x40 API: N/A Message: No API data available in console. Headless machine? Audio: Message: No ARM data found for this feature. Network: Message: No ARM data found for this feature. Drives: Local Storage: total: 0 KiB used: 15.52 GiB Partition: ID-1: / size: 3.68 GiB used: 3.66 GiB (99.5%) fs: ext4 dev: /dev/dm-4 ID-2: /cache size: 303.1 MiB used: 26 MiB (8.6%) fs: ext4 dev: /dev/mmcblk0p52 Swap: Alert: No swap data was found. Sensors: Src: lm-sensors Missing: Required tool sensors not installed. Check --recommends Info: Processes: 2 Uptime: 18m Memory: total: N/A available: 2.45 GiB used: 1.65 GiB (67.3%) Init: N/A Compilers: N/A Packages: 61 Shell: Bash v: 5.0.18 inxi: 3.3.31 $
Tags: Technology,Linux,

Thursday, November 9, 2023

Zen Mind, Beginner's Mind (Book Summary)

It is wisdom which is seeking for wisdom. The practice of Zen mind is beginner's mind. The innocence of the first inquiry—what am I?—is needed throughout Zen practice. The mind of the beginner is empty, free of the habits of the expert, ready to accept, to doubt, and open to all the possibilities. It is the kind of mind which can see things as they are, which step by step and in a flash can realize the original nature of everything. This practice of Zen mind is found throughout the book. Directly or by inference, every section of the book concerns the question of how to maintain beginner's mind through your meditation and in your life. This is an ancient way of teaching, using the simplest language and the situations of everyday life. This means the student should teach himself. Beginner's mind was a favorite expression of Dogen-zenji's. The calligraphy of the frontispiece, also by Suzuki-roshi, reads shoshin, or beginner's mind.

PROLOGUE

Beginner's mind: “In the beginner's mind there are many possibilities, but in the expert's there are few.”

PART ONE: Right Practice

Zazen practice is the direct expression of our true nature. Strictly speaking, for a human being, there is no other practice than this practice; there is no other way of life than this way of life. POSTURE “These forms are not the means of obtaining the right state of mind. To take this posture is itself to have the right state of mind. There is no need to obtain some special state of mind.” BREATHING “What we call 'I' is just a swinging door which moves when we inhale and when we exhale.” CONTROL “To give your sheep or cow a large, spacious meadow is the way to control him.” MIND WAVES “Because we enjoy all aspects of life as an unfolding of big mind, we do not care for any excessive joy. So we have imperturbable composure.” MIND WEEDS “You should rather be grateful for the weeds you have in your mind, because eventually they will enrich your practice.” THE MARROW OF ZEN “In the zazen posture, your mind and body have great power to accept things as they are, whether agreeable or disagreeable.” NO DUALISM “To stop your mind does not mean to stop the activities of mind. It means your mind pervades your whole body. With your full mind you form the mudra in your hands.” BOWING “Bowing is a very serious practice. You should be prepared to bow, even in your last moment. Even though it is impossible to get rid of our self-centered desires, we have to do it. Our true nature wants us to.” NOTHING SPECIAL “If you continue this simple practice every day, you will obtain some wonderful power. Before you attain it, it is something wonderful, but after you attain it, it is nothing special.”

PART TWO: Right Attitude

The point we emphasize is strong confidence in our original nature. SINGLE-MINDED WAY “Even if the sun were to rise from the west, the Bodhisattva has only one way.” REPETITION “If you lose the spirit of repetition, your practice will become quite difficult.” ZEN AND EXCITEMENT “Zen is not some kind of excitement, but concentration on our usual everyday routine.” RIGHT EFFORT “If your practice is good, you may become proud of it. What you do is good, but something more is added to it. Pride is extra. Right effort is to get rid of something extra.” NO TRACE “When you do something, you should burn yourself completely, like a good bonfire, leaving no trace of yourself.” GOD GIVING “'To give is nonattachment,' that is, just not to attach to anything is to give.” MISTAKES IN PRACTICE “It is when your practice is rather greedy that you become discouraged with it. So you should be grateful that you have a sign or warning signal to show you the weak point in your practice.” LIMITING YOUR ACTIVITY “Usually when someone believes in a particular religion, his attitude becomes more and more a sharp angle pointing away from himself. In our way the point of the angle is always towards ourselves.” STUDY YOURSELF “To have some deep feeling about Buddhism is not the point; we just do what we should do, like eating supper and going to bed. This is Buddhism.” TO POLISH A TILE “When you become you, Zen becomes Zen. When you are you, you see things as they are, and you become one with your surroundings.” CONSTANCY “People who know the state of emptiness will always be able to dissolve their problems by constancy.” COMMUNICATION “Without any intentional, fancy way of adjusting yourself, to express yourself as you are is the most important thing.” NEGATIVE AND POSITIVE “Big mind is something to express, not something to figure out. Big mind is something you have, not something to seek for.” NIRVANA, THE WATERFALL “Our life and death are the same thing. When we realize this fact, we have no fear of death anymore, nor actual difficulty in our life.”

PART THREE: Right Understanding

Our understanding of Buddhism is not just an intellectual understanding. True understanding is actual practice itself. TRADITIONAL ZEN SPIRIT “If you are trying to attain enlightenment, you are creating and being driven by karma, and you are wasting your time on your black cushion.” TRANSIENCY “We should find perfect existence through imperfect existence.” THE QUALITY OF BEING “When you do something, if you fix your mind on the activity with some confidence, the quality of your state of mind is the activity itself. When you are concentrated on the quality of your being, you are prepared for the activity.” NATURALNESS “Moment after moment, everyone comes out from nothingness. This is the true joy of life.” EMPTINESS “When you study Buddhism you should have a general house cleaning of your mind.” READINESS, MINDFULNESS “It is the readiness of the mind that is wisdom.” BELIEVING IN NOTHING “In our everyday life our thinking is ninety-nine percent self-centered. 'Why do I have suffering? Why do I have trouble?' ” ATTACHMENT, NONATTACHMENT “That we are attached to some beauty is also Buddha's activity.” CALMNESS “For Zen students a weed is a treasure.” EXPERIENCE, NOT PHILOSOPHY “There is something blasphemous in talking about how Buddhism is perfect as a philosophy or teaching without knowing what it actually is.” ORIGINAL BUDDHISM “Actually, we are not the Soto school at all. We are just Buddhists. We are not even Zen Buddhists. If we understand this point, we are truly Buddhists.” BEYOND CONSCIOUSNESS “To realize pure mind in your delusion is practice. If you try to expel the delusion it will only persist the more. Just say, 'Oh, this is just delusion,' and do not be bothered by it.” BUDDHA'S ENLIGHTENMENT “If you take pride in your attainment or become discouraged because of your idealistic effort, your practice will confine you by a thick wall.”
Tags: Buddhism,Psychology,Emotional Intelligence,

Sunday, November 5, 2023

Taoism Books (Nov 2023)

1.
Tao Te Ching
Laozi, 1970

2.
Tao: The Watercourse Way
Alan Watts, 1975

3.
Taoism: An Essential Guide
Eva Wong, 2011

4.
The Tao of Pooh
Benjamin Hoff, 1982

5.
365 Tao: Daily Meditations
Deng Ming-Dao, 1992

6.
Change Your Thoughts - Change Your Life: Living the Wisdom of the Tao
Wayne Dyer, 2007

7.
Zhuangzi
Chuang-Tzu, 1996

8.
The Secret of the Golden Flower: A Chinese Book of Life
2003

9.
The Tao of Physics
Fritjof Capra, 1975

10.
Taoism for Beginners: Understanding and Applying Taoist History, Concepts, and Practices
Elizabeth Reninger, 2020

11.
The Te of Piglet
Benjamin Hoff, 1992

12.
Lieh-tzu: A Taoist Guide to Practical Living
1995

13.
Cultivating Stillness: A Taoist Manual for Transforming Body and Mind
1992

14.
Way of Chuang Tzu
Thomas Merton, 1965

15.
Tao Te Ching: A Book about the Way and the Power of the Way
Ursula K. Le Guin, 1997

16.
Nourishing the Essence of Life: The Outer, Inner, and Secret Teachings of Taoism
2004

17.
The Essential Koran
Thomas Cleary, 1991

18.
Sufism and Taoism: A Comparative Study of Key Philosophical Concepts
Toshihiko Izutsu, 1983

19.
The I Ching: Or, Book of Changes
1950

20.
The Art of War
Sun Tzu, 2015

21.
Seven Taoist Masters: A Folk Novel of China
1990

22.
Be Water, My Friend: The Teachings of Bruce Lee
Shannon Lee, 2020

23.
Taoism for Beginners: A Guide to Balanced Living
C. Alexander Simpkins, 2021

24.
The Taoist experience
Livia Kohn, 1993

25.
The secret of secrets
Osho, 1982

26.
Awakening to the Tao
Liu Yiming, 1988

27.
The Eternal Tao Te Ching: The Philosophical Masterwork of Taoism and Its Relevance Today
Benjamin Hoff, 2021

28.
Hua Hu Ching: Teachings of Lao Tzu
Laozi, 1979

29.
Chuang tsu: Inner chapters
Chuang-Tzu, 1974

30.
Chronicles of Tao: The Secret Life of a Taoist Master
Deng Ming-Dao, 1993

31.
Everyday Tao: Living with Balance and Harmony
Deng Ming-Dao, 1996

32.
The tao is silent
Raymond Smullyan, 1977

33.
Taoist Yoga: Alchemy and Immortality
Pi Chʻen Chao, 1971

34.
Finding a Life of Harmony and Balance: A Taoist Master's Path to Wisdom
Kaiguo Chen, 2020

35.
The Way of Zen
Alan Watts, 1957

36.
Taoist secrets of love
Mantak Chia, 1984

37.
Tao Te Ching: With Over 150 Photographs by Jane English
Laozi

38.
Practicing the Tao Te Ching: 81 Steps on the Way
Solala Towler, 2016

39.
The Texts of Taoism
James Legge, 1891

40.
Living the Wisdom of the Tao: The Complete Tao Te Ching and Affirmations
Wayne Dyer, 2008

41.
Taoism: The Fundamental Books: Tao Te Ching, Lieh TzÅ­, Chuang TzÅ­
Laozi

42.
I Ching

43.
The Inner Teachings of Taoism
Liu Yiming

44.
The Taoist Classics, Volume Four: The Collected Translations of Thomas Cleary
Thomas Cleary, 2000

45.
Absolute Tao
Osho, 2012

46.
Confucianism & Taoism
Julia Ching, 1994

47.
Tao: The Pathless Path
Osho, 1979

48.
Taoism For Dummies
Jonathan Herman, 2013

49.
Tao Te Ching (New Edition with Commentary)
Laozi

50.
Tao Der Fuhrung
John Heider, 1985

51.
China Root: Taoism, Ch'an, and Original Zen
David Hinton, 2020

Stoicism Books (Nov 2023)

1. 
Meditations
Marcus Aurelius, 2000

2.
The Daily Stoic
Ryan Holiday, 2016

3.
Epistulae Morales ad Lucilium
Lucius Annaeus Seneca, 2021

4.
How to Think Like a Roman Emperor: The Stoic Philosophy of Marcus Aurelius
Donald Robertson, 2019

5.
How to Be a Stoic: Using Ancient Philosophy to Live a Modern Life
Massimo Pigliucci, 2017

6.
The Daily Stoic: 366 Meditations on Wisdom, Perseverance, and the Art of Living
Ryan Holiday, 2016

7.
A Guide to the Good Life: The Ancient Art of Stoic Joy
William Braxton Irvine, 2008

8.
Lives of the Stoics: The Art of Living from Zeno to Marcus Aurelius
Ryan Holiday, 2020

9.
The Little Book of Stoicism: Timeless Wisdom to Gain Resilience, Confidence, and Calmness
Jonas Salzgeber, 2019

10.
The inner citadel
Pierre Hadot, 1998

11.
Stoicism and the Art of Happiness: Practical Wisdom for Everyday Life
Donald Robertson, 2018

12.
The Obstacle Is the Way
Ryan Holiday, 2014

13.
On the Shortness of Life
Lucius Annaeus Seneca, 2003

14.
Discourses and selected writings
Epictetus, 2008

15.
Stoicism for Inner Peace
Einzelgänger, 2021

16.
The Art of Living
Epictetus

17.
The Practicing Stoic
Ward Farnsworth, 2018

18.
Lessons in Stoicism: What Ancient Philosophers Teach Us about How to Live
John Sellars, 2019

19.
Ego Is the Enemy
Ryan Holiday, 2016

20.
How to Be a Stoic
Massimo Pigliucci, 2017

21.
Enchiridion of Epictetus
Epictetus, 2007

22.
The Cambridge Companion to the Stoics
2003

23.
Discipline Is Destiny: The Power of Self-Control
Ryan Holiday, 2022

24.
Discourses of Epictetus
Epictetus, 1535

25.
The Stoic Challenge: A Philosopher's Guide to Becoming Tougher, Calmer, and More Resilient
William Braxton Irvine, 2019

26.
A new stoicism
Lawrence C. Becker, 1998

27.
A Handbook for New Stoics: How to Thrive in a World Out of Your Control—52 Week-by-Week Lessons
Massimo Pigliucci

28.
That One Should Disdain Hardships: The Teachings of a Roman Stoic
Gaius Musonius Rufus

29.
365 Ways to be More Stoic: A Day-by-day Guide to Practical Stoicism
Tim LeBon, 2022

30.
Stoic Classics Collection: Marcus Aurelius's Meditations, Epictetus's Enchiridion, Seneca's on the Happy Life
Epictetus

31.
Courage Is Calling: Fortune Favors the Brave
Ryan Holiday, 2021

32.
A Field Guide to a Happy Life: 53 Brief Lessons for Living
Massimo Pigliucci, 2020

33.
The Daily Stoic Journal: 366 Days of Writing and Reflection on the Art of Living
Ryan Holiday, 2017

34.
The Discourses
Epictetus

35.
The Art of Living: The Classical Mannual on Virtue, Happiness, and Effectiveness
1995

36.
The Beginner's Guide to Stoicism: Tools for Emotional Resilience and Positivity
Matthew J. van Natta, 2019

37.
The stoics
Mark Holowchak, 2008

38.
How to Live a Good Life: A Guide to Choosing Your Personal Philosophy
2020

39.
Stillness Is the Key
Ryan Holiday, 2019

40.
Stoicism: Introduction to the Stoic Way of Life
James Ryan, 2017

41.
The Stoics
Epictetus

42.
Journal Like a Stoic: A 90-Day Stoicism Program to Live with Greater Acceptance, Less Judgment, and Deeper Intentionality (Includes Teachings of Marcus Aurelius)
Brittany Polat, 2022

43.
Aristotle and the Stoics
Harry Sandbach, 1975

44.
Courage Under Fire: Testing Epictetus's Doctrines in a Laboratory of Human Behavior
James Stockdale, 1993

45.
Stoicism: Mastery - Mastering the Stoic Way of Life
James Ryan, 2017

46.
How To Be a Stoic
2017

47.
Discipline Is Destiny: A NEW YORK TIMES BESTSELLER
Ryan Holiday, 2022

48.
Letters on Ethics: To Lucilius
Lucius Annaeus Seneca

49.
The Manual: A Philosopher's Guide to Life
Epictetus

50.
Stoicism and Emotion
Margaret Graver, 2007

51.
Discourses and Selected Writings of Epictetus (19th Century Classics Illustrated Edition)
Epictetus