Tuesday, January 11, 2022

Wordle solver

 Solving problems with code - why?

In some way or form solving any problem with code is a fun activity for me. I find joy in finding an algorithmic way to reach the solution.

Soo.. this is a simple solver for this fun little puzzle I found: 

Solver uses python, selenium, nltk for words, and wordfreq to identify words with higher frequency as a key to pick the next candidate.
It is generally fun to watch it solve. Enjoy.



Sunday, September 15, 2019

NextCloud Experience

Goals

Primary goal, since I have a windows machine, is to install nextcloud so that the data directory is exposed in a windows directory.

I have a regular backup for the windows directory that takes care of failure situations.
It is not perfect, but I wish to avoid an in-vm or in-docker-volume data directory that keeps growing and rather have a share on which it is visible.
I suppose if I was ALL linux or ALL mac etc this may be less tricky.

Primary troubles:

1. Docker on windows: 
  • The amount of control on volume bind mounts from inside docker is limited.
  • Nextcloud is very particular about the data directory, it wants specifically 0770 permission owned by www-data.
Between these two I did not find a way to setup the data directory in a windows drive.

2. SQLite and windows shared folders: 
I like sqlite, for home use it is enough, I have been using it in owncloud for a few years without issues.
SQLite driver or whatever, seems to have a problem running in linux but accessing a windows mount.
For example, if you setup a linux in virtualbox, setup nextcloud, and if you share a windows folder and place the data directory, sqlite calls will fail.
So, either drop sqlite or place sqlite inside native volumes.

Solution

  • Virtualbox shared folder ownership:
    • Windows and docker cannot manage permissions volume bind so nextcloud fails.
    • Solution:
      • Run ubuntu in a virtualbox and override the uid,gid of Virtualbox shared folder using a simple fstab declaration.
      • Ubuntu has technically abstracted the drive as a linux drive with appropriate permissions.
  • Run Docker compose in ubuntu and bind mount the shared folder
  • Run postgres to avoid the sqlite pitfall. I really don't care about the db side since data is what I am worried about.

Tricky item:

When you first login to nextcloud it configures it as well. This also adds trusted host as to the ip you are coming in from.
If you launch browser from your *windows* host, then it is logged as trusted host.
This is good because otherwise it is fairly painful to edit the config inside nextcloud to add another trusted host as there is no admin UI for this.

Now you can place nextcloud behind nginx or other proxy before exposing it to internet - one more abstraction layer.

Outcome:

  • Windows host can now see the files users in my home are placing into the data drive and this is backed up regularly.
  • I can also share readonly shares of large libraries of music and videos across all the users.
Overall diagram:



The geeky bits:

1. Docker compose file. I cobbled this from the examples. Obviously password and host etc are to be configured to good security.

version: '2'

volumes:
    nc_root:
    nc_config:
    postgres_db:


services:
  db:
    image: postgres:alpine
    restart: always
    expose:
        - "5432"
    volumes:
        - postgres_db:/var/lib/postgresql/data
    env_file:
        - db.env
    networks:
        - mynetwork

  app:
    image: nextcloud
    networks:
        mynetwork:
            aliases:
            - nccloud.local.lan
    container_name: nccloud
    ports:
        - 8123:80
    volumes:
        - nc_root:/var/www/html
        - nc_config:/var/www/html/config
        - /media/sf_docker_nc_data:/var/www/html/data
    restart: always
    environment:
        - POSTGRES_HOST=db
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=password
        - POSTGRES_PORT=5432
        - POSTGRES_DB=nextcloud

    env_file:
        - db.env
    depends_on:
        - db
networks:
    mynetwork:
        driver: bridge

2. /etc/fstab entry to mount the shared folder with appropriate uid and gid. uid 33 and gid 33 are for www-data (which also happens to be provisioned by default in ubuntu with the same uid/gid combo).

docker_nc_data /media/sf_docker_nc_data  vboxsf uid=33,gid=33,umask=077 0 0


3. Added this to start and stop the service

# /etc/systemd/system/nextcloud-docker-compose.service

[Unit]
Description=Docker Compose Start of NextCloud
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/nextcloud/DockerNC
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target

Enable this with: systemctl enable nextcloud-docker-compose

4. Some reference commands that make life easy:

#follow logs when docker compose starts - good to see what is going on
sudo docker-compose logs --follow
# good for clean up and leave no trace.
sudo docker volume prune
#good for snooping around in the vm
sudo docker exec -it  nccloud bash

The end.

Friday, August 28, 2015

Why markup when you can excel? :)

What-a-concept.. first I write a bit of glue code to make Excel-to-Wiki, now the other way around
This was, however, a bit trickier.
The path followed was to convert wiki markup to HTML and parse HTML table elements to generate Excel.
I am using a fine library called py-wikimarkup which appears to work quite well in the conversion to HTML.

Note that this is now trivially wrapped in a web service that can round trip between Excel and Wiki markup all day long.
If anyone has any interest in the webservice I can post that up here as well.

Wiki To Excel project: https://github.com/venkman69/WikiToExcel

Enjoy!
N
PS: The other direction: http://techybabble.blogspot.com/2015/07/excel-to-wiki-markup.html

Thursday, July 30, 2015

Excel to Wiki Markup

After some digging, it looks like openpyxl and some slightly unorthodox inspection of the excel file's structure (gleaned from internet searches) offer a way to extract cell and font styling information.
The wiki markup being what it is, still feels like writing on a stone tablet considering tools we have nowadays. To make life slightly more liveable in the wiki world, I wrote a converter that supports the styling information.

Guess what, I am yet to see one excel to wiki converter that maintains the styling information. I know my code has a ways to go, but it is a far better effort than treating it just as data. Seriously, without simple background colors etc, excel sheets just look like matrix. And that thrown into wiki shows up even more ugly.

Anyhoo, cutting to chase, here's the github link: https://github.com/venkman69/ExcelToWiki
And it is also available from PyPi so you should be able to pip install it as well: https://pypi.python.org/pypi/exceltowiki

Enjoy,
N
PS: The other direction: http://techybabble.blogspot.com/2015/08/why-markup-when-you-can-excel.html

Tuesday, June 30, 2015

Store and Retrieve passwords in a Script using Mac KeyChains

Store a password into the mac keychain:

The following command stores a password into the keychain

security add-generic-password -a <username> -s <appname, friendly name> -p <password> -A -U


Retrieve the password from the mac keychain:

And this outputs the password to the stdout:
security find-generic-password -s <appname, friendly name> -g -w

Thursday, May 21, 2015

MAC to Linux dircolors does not work

Going from MAC to Linux over ssh the dircolors command does not work

When you test dircolors command with simply typing dircolors it gives:
$ dircolors
LS_COLORS='';
export LS_COLORS

The cause is that the discolors is inspecting the TERM variable and the TERM as reported is:

$ echo $TERM
xterm-256color

The fix to get around this is to add the line into the .dir_colors for this terminal type
TERM xterm
TERM xterm-256color
TERM xterm-color
TERM xterm-debian
TERM rxvt

Notes: 

  • The $HOME/.dir_colors can be your custom color setup. 
  • You can typically get a vanilla copy from /etc/dircolors
  • If not, you can run the following command to print the database of dircolors into this file.
    dircolors -p > ~/.dir_colors
  • Next, add the following into your .profile, .bash_profile etc. wherever appropriate.
    eval `dircolors -b ~/.dir_colors`
    alias ls='ls --color=always'
Now, 'ls' command will appropriately color the entries and it will work when ssh'ing from a mac.

Thursday, April 9, 2015

How to setup remote debug with WebLogic and Eclipse

Setup remote debug with WebLogic and Eclipse

As always there is the clean way, and the one-off way.
We will see how to setup debug for weblogic using the clean way which is to leverage all the built-in items already present but not clear that they are.

<domain>/bin/setDomainEnv.sh has interesting items: 

  • First there is the debugFlag="true"
  • Then there is DEBUG_ PORT="8453"
  • Then you will also see:
JAVA_DEBUG="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=${DEBUG_PORT},server=y,suspend=n -Djava.compiler=NONE

So the clean answer lies somewhere between these three. Also while there is the command line option as well (as you can see at the bottom of the setDomainEnv.sh).

Note: In production mode the debug is disabled by default by unsetting the flag. We can however get around this by re-setting the flag after this piece of code.

So here are the steps

Set the debug Flag

After around line number 203 in setDomainEnv.sh add the lines (ignore echo if you don't want the noise). This will also get around the production mode issue mentioned above

Add after this block (around Line 203):
if [ "${PRODUCTION_MODE}" = "true" ] ; then
        debugFlag="false"
        export debugFlag
        testConsoleFlag="false"
        export testConsoleFlag
        iterativeDevFlag="false"
        export iterativeDevFlag
        logErrorsToConsoleFlag="false"
        export logErrorsToConsoleFlag
fi
echo "Setting debug flag"
export debugFlag="true"

If you are not using just the Admin Server:

If your deployment is using a specific managed server, then you can modify the above as:
if [ "${SERVER_NAME}" = "mgdserver1" ] ; then
      echo "Setting debug flag for mgdserver1"
      export debugFlag="true"
fi

If you have to remote debug more than one managed server

The above block also allows you to specify a different port number for this server. And you can duplicate the same block for each of your servers if needed.
if [ "${SERVER_NAME}" = "mgdserver1" ] ; then
      echo "Setting debug flag for mgdserver1 and port to 8454"
      export debugFlag="true"
      export DEBUG_PORT="8454"
fi

Eclipse setup

In Eclipse the setup is simple.
  • Right click on the Project containing the deployed items. Select "Debug as">"Debug Configurations"
  • Locate "Remote Java Application" in the list on the left
  • Create a new configuration with hostname and debug port of the weblogic server