Direct sow

I have add success with sowing the following seeds directly in the ground

  • Gourds (after soaking the seeds for 24 hours)
  • Okra
  • Leafy veggies such as Kale (mid march), Arugula, Collards, Mustard etc
  • Cilantro (after crushing the seeds into two)

No seedlings next year

Most of my seedlings (except peppers and tomatoes) have died out by now due to over exposure to sun. I won’t be growing any seedlings next year. The important learning with seedlings is that seedlings need to be gradually exposed to the sun. They need to be first exposed indirectly to the sunlight for a week and then couple of hours directly for a week or two before moving them out in full direct sun.

It’s much easier and cheaper to just buy seedlings from Raleigh’s farmer’s market. For gourd seeds will buy them from Etsy, have found a good vendor TommorrowSeeds there.

Dead gourds

Looks like all of my gourd seedlings died because of over exposure to sun. Next year will remember to plant the gourd seeds directly instead of growing seedlings. Also another important lesson about planting gourd seeds is to soak them in water for 24 hours before planting them into the soil.

Farming 2021

Vegetable beds

Built some vegetable beds this year as there wasn’t much else to do because of covid. Planning on becoming a weekend farmer this year.

I tried growing seedlings (indoors) for some herbs, peppers, tomatoes, eggplants, bitter gourd, bottle gourd. The important lessons learnt this year are

  • Start the seedling process in end of Feb or 1st week of March
  • Grow seedlings indoors for peppers and all of the gourds. Everything else is pain and did not survive.
  • It’s much cheaper to buy seedlings for all of the herbs, tomatoes, eggplants from the farmer’s market in the last two weeks of April and probably first week of May.

The only thing left for me to plan now is collards, lettuce, beans and okra. Will probably get them planted tomorrow.

Building an interpreter in RUST

Just finished going through “Writing An Interpreter In Go“. However instead of implementing the interpreter in Go, I decided to implement it in RUST. This was one of the most satisfying software projects that I worked on in a while. I must say that I just love RUST as a systems programming language.

The important RUST features that I used to get this project done are

  • Enums as data types
  • Box
  • Rc
  • RefCell
  • Lots of recursion

RUST enables you to write the code in a declarative manner which makes the code really compact and easy to understand

OpenDNS

Cisco has a great product called OpenDNS that enables you to control the websites that can be reached from home your network. If you have Google wifi at home, you can use OpenDNS to block gaming websites like Roblox.

Wireless issues on Lenovo Flex running FC 33

I purchased a Lenovo Flex couple of months ago and installed Fedora 33 on it. Was really frustrated with the wifi on the laptop. The realtek wireless drivers merged in the official kernel suck big time.

Trying out a solution, hope will work (and it did not)

sudo nmcli con reload wlp2s0

The above command to restart the wireless seems to have helped. Also following are the wireless kernel modules that are currently loaded

lsmod | grep rt
rtl88x2ce            3018752  0
rtw_8822ce             16384  0
rtw_8822c             471040  1 rtw_8822ce
rtw_pci                28672  1 rtw_8822ce
rtw_core              212992  2 rtw_8822c,rtw_pci
mac80211             1081344  2 rtw_core,rtw_pci

Shifted binary search

 
public static int shiftedBinarySearch(int[] array, int target) {
    return shiftedSearch(array, 0, array.length - 1, target);
}

public static int binarySearch(int[] array, int startIdx, int endIdx, int target) {
        int midIdx = (startIdx + endIdx) / 2;

        if (startIdx > endIdx || endIdx >= array.length) {
            return -1;
        }

        if (startIdx == endIdx) {
            if (array[midIdx] == target) {
                return midIdx;
            } else {
                return -1;
            }
        }

        int result = -1;
        if (target <= array[midIdx]) {
            result = binarySearch(array, startIdx, midIdx, target);
        } else {
            result = binarySearch(array, midIdx + 1, endIdx, target);
        }

        return result;
    }

    public static int shiftedSearch(int[] array, int startIdx, int endIdx, int target) {

        if (startIdx > endIdx || endIdx >= array.length) {
            return -1;
        }

        if (array[startIdx] == target) {
            return startIdx;
        }

        if (array[endIdx] == target) {
            return endIdx;
        }

        int result = -1;
        int midIdx = (startIdx + endIdx) / 2;


        if (array[startIdx] > array[midIdx]) {
            result = shiftedSearch(array, startIdx, midIdx, target);
            if (result != -1) {
                return result;
            }
        }

        if (array[midIdx + 1] < array[endIdx]) {
            result = binarySearch(array, midIdx + 1, endIdx, target);
            if (result != -1) {
                return result;
            }
        }


        if (array[startIdx] < array[midIdx]) {
            result = binarySearch(array, startIdx, midIdx, target);
            if (result != -1) {
                return result;
            }
        }


        if (array[endIdx] < array[midIdx + 1]) {
            result = shiftedSearch(array, midIdx + 1, endIdx, target);
            if (result != -1) {
                return result;
            }
        }
        return result;
    }

Lowest Common Manager

#!/bin/python3

class OrgChart:

    def __init__(self, name, manager):
        self.name = name
        self.manager = manager
        self.directReports = []

    def __repr__(self):
        return f'{self.name}'


def getLowestCommonManager(topManager, reportOne, reportTwo):
    report_one_manager = reportOne.manager
    report_one_chain = list()
    while report_one_manager:
        report_one_chain.append(report_one_manager)
        report_one_manager = report_one_manager.manager

    report_two_manager = reportTwo.manager
    report_two_chain = list()
    while report_two_manager:
        report_two_chain.append(report_two_manager)
        report_two_manager = report_two_manager.manager

    report_one_chain.reverse()
    report_two_chain.reverse()
    common_manager = None
    for a, b in zip(report_one_chain, report_two_chain):
        if a == b:
            common_manager = a
        else:
            break

    return common_manager


if __name__ == '__main__':
    org = [
        {"directReports": ["B", "C"], "id": "A", "name": "A"},
        {"directReports": ["D", "E"], "id": "B", "name": "B"},
        {"directReports": ["F", "G"], "id": "C", "name": "C"},
        {"directReports": ["H", "I"], "id": "D", "name": "D"},
        {"directReports": [], "id": "E", "name": "E"},
        {"directReports": [], "id": "F", "name": "F"},
        {"directReports": [], "id": "G", "name": "G"},
        {"directReports": [], "id": "H", "name": "H"},
        {"directReports": [], "id": "I", "name": "I"}
    ]

    top_manager = None
    members = {}
    for member in org:
        name = member['name']
        if name not in members:
            member_obj = OrgChart(name, None)
            top_manager = member_obj
            members[name] = member_obj

        member_obj = members[name]

        for direct_report in member['directReports']:

            if not direct_report in members:
                direct_report_obj = OrgChart(direct_report, member_obj)
                direct_report_obj.name = direct_report
                members[direct_report] = direct_report_obj
            else:
                direct_report_obj = members[direct_report]

            member_obj.directReports.append(direct_report_obj)

    print(getLowestCommonManager(top_manager, members['F'], members['H']))

Longest Peak

package com.vishpat.practice.ds.array;

enum States {
    UNKNOWN,
    ASCENDING,
    DESCENDING
}

public class LongestPeak {
    public static int longestPeak(int[] array) {
        States currentState = States.UNKNOWN;
        States prevState = States.UNKNOWN;
        int longestSize = 0;
        int ascendingStartIdx = -1;
        int descendingEndIdx = -1;

        if (array.length < 3) {
            return 0;
        }

        for (int i = 0; i < array.length - 1; i++) {
            prevState = currentState;

            if (array[i + 1] > array[i]) {
                switch (prevState) {
                    case UNKNOWN:
                        currentState = States.ASCENDING;
                        ascendingStartIdx = i;
                        break;
                    case ASCENDING:
                        currentState = States.ASCENDING;
                        break;
                    case DESCENDING:
                        currentState = States.ASCENDING;
                        ascendingStartIdx = i;
                        break;
                }
            }

            if (array[i + 1] < array[i]) {
                switch (prevState) {
                    case UNKNOWN:
                        currentState = States.DESCENDING;
                        break;
                    case ASCENDING:
                        currentState = States.DESCENDING;
                        descendingEndIdx = i + 1;
                        break;
                    case DESCENDING:
                        currentState = States.DESCENDING;
                        descendingEndIdx = i + 1;
                        break;
                }
            }

            if (ascendingStartIdx >= 0 && descendingEndIdx >= 0 &&
                ascendingStartIdx < descendingEndIdx) {
                int size = descendingEndIdx - ascendingStartIdx + 1;
                if (size > longestSize && size > 2) {
                    longestSize = size;
                }
            }
        }
        return longestSize;
    }
}