Leetcode SQL 50 - Another two

I had so much fun doing that first easy one, I did two more! First I tackled 584. Find Customer Referee The problem: Find the names of the customer that are not referred by the customer with id = 2. Return the result table in any order. The solution: select name from Customer where referee_id != 2 or referee_id is null; Pretty self explanatory. Since there were nulls in the referee_id column, we needed to also allow if there were nulls. Then I did 1148. Article Views I The problem: Write a solution to find all the authors that viewed at least one of their own articles. Return the result table sorted by id in ascending order. The solution: select distinct author_id as id from Views where author_id = viewer_id order by author_id; Of course I missed the order requirement the first time around, but luckily it was easily fixed the second time it was run. I use distinct since there were possible duplicates, though didn't test to see if that was the case. That will make it slower, so only

Leetcode SQL 50

I picked a nice easy SQL one today, and it was far easier than I expected! 1757. Recyclable and Low Fat Products The problem: Write a solution to find the ids of products that are both low fat and recyclable. Return the result table in any order.  The solution: select product_id from Products where low_fats = 'Y' and recyclable='Y'; Not much else to say, except I wish SQL was always this easy!

Various System Stuff

 Typically I'll set up an instance, and get everything working as I like, and then promptly forget everything about it until the next time I need to create an instance from scratch. This is great for memory space, but terrible in that I waste a lot of time trying to figure out where everything is! So to combat this in the future, this blog post is mostly for future me. This relates almost exclusively to the Amazon Linux 2 AMI. If you run other flavors of linux, your mileage may vary! First, I can rarely remember the names of running services. To list running services: systemctl --type=service --state=running The result is a list where I can see, for example, the crontab is called crond. I know this can be looked up elsewhere, but usually I've made a change like to the global environment variables, and need to restart the crontab. Restarting is systemctl restart <servicename>. I get this order wrong because it used to be service <servicename> restart. Related to this

VIM tab autocomplete for .class files

 VIM tab autocomplete for .class files Super frustrating to track this down on a new instance at AWS. The instance is using the Amazon Linux 2 AMI, and Google (or Chat GPT) didn't help find the settings file. I'm adding this blog post so that in the future, I can find it here! This is the file location: /usr/share/bash-completion/bash_completion The line to edit (I just searched in vim for class): _install_xspec '*.@(o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)' vi vim gvim rvim view rview rgvim rgview gview emacs xemacs sxemacs kate kwrite Obviously, I just need to remove "class" from that list. We no longer name files with .class, mostly because of this issue! All the legacy code, however, that we use for dealing with older systems does. 

Leetcode 75: 1768. Merge Strings Alternately

In this blog post, we'll examine a problem from Leetcode - "Merge Strings Alternately". We'll walk through a PHP solution and break it down for better understanding. The problem asks to merge two strings by adding letters in alternating order, starting with the first string. If one string is longer than the other, the additional letters should be appended to the end of the merged string. The PHP solution given below does exactly that: class Solution {     /**      * @param String $word1      * @param String $word2      * @return String      */     function mergeAlternately($word1, $word2) {         $word1Length = strlen($word1);         $word2Length = strlen($word2);         $output = '';         $remainder = '';         $loopLength = min($word1Length, $word2Length);         if ($word1Length > $word2Length) {             $remainder = substr($word1, $word2Length);         } else if ($word1Length < $word2Length) {             $remainder = substr($w

Leetcode Two Sum Problem in three different languages

  The problem from  Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Example: Input: nums = [2,7,11,15], target = 9  Output: [0,1]  Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. First, let's attack this using Python, and then we'll do the same with Java and compare the differences in the solutions. PYTHON Problem-solving: We can solve this problem by using a hash table in Python. First, we will iterate over the array nums and check if the difference between the target and the current element of nums exists in the hash table. If it does, we return the indices of the current element and the difference. Otherwise, we add the current element of nums and its index to the hash table. Steps: Initialize an empty hash table. Loop through t

Defending Against Ettercap Attacks: A Brief Overview

  Ettercap, a popular and powerful suite of tools for network auditing and man-in-the-middle attacks, is one threat that consistently demands attention. This blog post will explore two scenarios where Ettercap attacks might occur and discuss how to effectively defend against and detect these intrusions. Scenario 1: ARP Poisoning One of the most common uses for Ettercap is ARP poisoning, a technique where the attacker manipulates the Address Resolution Protocol (ARP) to intercept data between two devices on a local area network (LAN). This allows the attacker to eavesdrop on or even alter communications. Defending Against ARP Poisoning: Static ARP entries: To prevent ARP poisoning, you can configure static ARP entries for critical devices. This ensures that their MAC addresses are not susceptible to manipulation. However, this method can be cumbersome in large networks. ARP monitoring tools: Implementing ARP monitoring tools like Arpwatch or XArp can help detect suspicious ARP activitie