SSH to Windows 10 using private key

It took waaaay to long to make everything work.

  • Create the service and key pairs via this link
  • Make sure that the logs are generated to debug any issues via this link
  • The administrators_authorized_keys file should contain the public key generated in the first step and the permissions should only have the Administrators group for Read and Read & Execute

How many authors in that git project?

I’ve been spending a lot of time on the FixPix Home project and recently have discovered a similar project – chaiNNer, which is open source (GPL 3.0) and, though targeted at a different audience, looks also like a very impressive piece of work.

So I was wondering how many developers have been working on chaiNNer and for how long.

Here’s a quick Linux/Mac one-liner I wrote to determine how many developers contributed to a git project and also a quick glimpse to the relative contribution of each:

$git log | grep Author | sed "s/<.*>$//" | sort | uniq -c | sort -nr
    580 Author: Michael Schmidt
    466 Author: Joey Ballentine
     83 Author: theflyingzamboni
     14 Author: Alex Dodge
     13 Author: dependabot[bot]
      4 Author: Harisreedhar
      3 Author: Jackson Ly
      2 Author: Zarxrax
      2 Author: Sryvkver
      2 Author: BigBoyBarney
      1 Author: xpsychonauticon
      1 Author: emarron
      1 Author: JustNoon
      1 Author: EzoGaming

Calculating how long since the project has been started using a one-liner is also possible with some bash tricks, but would take longer than the time I can allocate for it right now – maybe in a future post. For now this will suffice:

$git log | tail | grep Date
Date:   Tue Sep 7 17:58:15 2021 -0500

Which means they’ve had a about year’s head start in R&D time over FixPix Home 🙂

I got ChatGPT into an endless loop

Luckily, the developers stop the output after a certain point.
This was after I asked about an example of a flawed mathematical proof

Me:
Can you provide an example where x^2-x^2=0 is not true?

ChatGPT:

Sure, here is an example where x^2-x^2=0 is not true:

Let x=2

Then, x^2-x^2=4-4=0

In this case, x^2-x^2 does equal 0. However, if we choose a different value for x, the equation x^2-x^2=0 may not hold true. For example:

Let x=3

Then, x^2-x^2=9-9=0

In this case, x^2-x^2 does equal 0. However, if we choose a different value for x, the equation x^2-x^2=0 may not hold true. For example:

Let x=4

Then, x^2-x^2=16-16=0

In this case, x^2-x^2 does equal 0. However, if we choose a different value for x, the equation x^2-x^2=0 may not hold true. For example:

Let x=5

Then, x^2-x^2=25-25=0

In this case, x^2-x^2 does equal 0. However, if we choose a different value for x, the equation x^2-x^2=0 may not hold true. For example:

Let x=6

Then, x^2-x^2=36-36=0

In this case, x^2-x^2 does equal 0. However, if we choose a different value for x, the equation x^2-x^2=0 may not hold true. For example:

Let x=7

Then, x^2-x^2=49-49=0

In this case, x^2-x^2 does equal 0. However, if we choose a different value for x, the equation x^2-x^2=0 may not hold true. For example:

Let x=8

Then, x^2-x^2=64-64=0

In this case, x^2-x^2 does equal 0. However, if we choose a different value for x, the equation x^2-x^2=0 may not hold true. For example:

Let x=9

Then, x^2-x^2=81-81=0

In this case, x^2-x^2 does equal 0. However, if we choose a different value for x, the equation x^2-x^2=0 may not hold true. For example:

Let x=10

Then, x^2-x^2=100-100=0

In this case, x^2-x^2 does equal 0. However, if we choose a different value for x, the equation x^2-x^2=0 may not hold true. For example:

Let x=11

Then, x^2-x^2=121-121=0

In this case, x^2-x^2 does equal 0. However, if we choose a different value for x, the equation x^2-x^2=0 may not hold true. For example:

Let x=12

Then, x^2-x^2=144-144=0

In this case, x^2-x^2 does equal 0. However, if we choose a different


——-

Bitnami WordPress stuck when trying to save post

There can be many reasons why this can happen. In my case I couldn’t locate the change that was made in WordPress that caused the issue. The only major change since the last time a post was added was a WordPress update, but that didn’t strike me as being the reason as it wasn’t a major version.

Be that as it may, what solved the issue for me was this link – to summarize, change the following lines in wp-config.php

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');

to

define('WP_SITEURL', 'http://DOMAIN/');
define('WP_HOME', 'http://DOMAIN/');

of course, replace DOMAIN with the primary domain for your WordPress app.

an alternative method is here, though I haven’t tried it

Inaccessible variables in Python

when you code in many languages, you usually need to dig a bit to find answers to questions that are not immediately obvious in a specific language. Mine was whether closures can simulate real private variables in python (i.e that really can’t be accessed as opposed to the __ mangling method).

I decided to test if this would work with closures, as shown below

def outer(a,b):
    class this:
        pass
    
    #--------------------------
    # real private variables and methods go here
    this.a = a
    this.b = b
    
    def sum_():
        return this.a + this.b
    
    def product_():
        return this.a * this.b
    
    def set_nums_(a, b):
        this.a, this.b = a, b
    
    #--------------------------
    # public variables and methods go here
    class inner:
        def get_nums(self):
            return this.a, this.b
        
        def set_nums(self, a, b):
            set_nums_(a,b)
        
        def sum(self):
            return sum_()
        
        def product(self):
            return product_()
    
    return inner()

and the result:

>>> x = outer(5,3)
>>> x.get_nums()
(5, 3)
>>> x.set_nums(5,4)
>>> x.get_nums()
(5, 4)
>>> x.product()
20
>>> x
<__main__.outer..inner object at 0x0000023C581E21C0>
>>>

Yay! seems like it works.

Of course, a bit of further digging showed that every python object has the __closure__ property through which you can access the closure for that object, and changing the values of the “private” variables above (bypassing the set_nums method) just becomes a matter of:

>>> loophole = x.sum.__closure__[0].cell_contents.__closure__[0].cell_contents
>>> loophole
<class '__main__.outer.<locals>.this'>
>>> loophole.a = 8
>>> loophole.b = 9
>>> x.get_nums()
(8, 9)
>>>

AWS Lambda with Docker – revisited

There are various ways to leverage docker to develop AWS lambda serverless functions. One recent method is to deploy Python Lambda functions with container images (as specified here).

Another method is to develop the Lambda package from within an Amazon Linux docker container and then upload it to AWS Lambda (more details here). A summary of how to do this is described below and will work for any platform where you can install Docker.

Open a command prompt and type:

docker pull lambci/lambda

next, type:

docker run -it lambci/lambda:build-python3.8 bash

This will install the environment to run Python 3.8 code and open a shell prompt so you can start working. The first thing recommended to do when getting the bash prompt is yum update

when you exit the shell, you can always re-enter by typing:

docker start -i container_name

(replace container_name with the container name of given to the image named lambci/lambda:build-python3.8, which can be seen via docker ps -a)

Linux on Windows 10 via Docker

Wanting to run Linux command line under windows usually brings you to one of two options:

  1. Install WSL (Windows Subsystem for Linux) – the main advantage here is performance optimizations made by Microsoft to take the most advantage of the hardware and OS infrastructure.
  2. Install Docker for Windows 10 and then create a Linux container which you can run and get the command line prompt from

There are other options such as running a full graphical virtual machine like VirtualBox, VMWare and the like, but our focus will be getting a quick Linux command line prompt from Windows.

My personal preference is using option 2, mainly due to it being easy to install and the ability to easily create multiple sandboxed instances and easily use them for different purposes.

The following describes how to install the latest Ubuntu version and run it as a docker container.

  1. If you haven’t already done so, install Docker for Windows
  2. open a command prompt and type:
    docker pull ubuntu
  3. next, type:
    docker images
    copy the image id of the repository named ubuntu
  4. suppose the image id of the repository you copied was f6a191f19b5f, type:
    docker run -it --name=ubuntu-container f6a191f19b5f /bin/sh
  5. that’s it, you have the root prompt on the latest Ubuntu running on your Windows system!
  6. After you exit the ubuntu container, you can always enter it again by typing from the command prompt:
    docker start -i ubuntu-container