Saturday 17 February 2024

Visual Studio Code - Wow πŸ™€

Why did I not know that I can merely hit [cmd] [p] to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub etc. for a file name ?



How long have I spent manually navigating the folder structure on the left-hand side ?

πŸ™€πŸ™€πŸ™€

Saturday 30 December 2023

Getting started with Python in Jupyter Notebooks

So, as we get ready to start a new year, I'm tinkering with a bunch of new ( to me ) tech toys, including wrangling Python dependencies.

Having spent much of of the past year or so using pip and pyenv to manage Python dependencies, more recently, I've been looking at an alternate solution, Anaconda.

Having downloaded and installed the Mac version of Anaconda - and allowed it to install itself into ~/.zshrc ( as I use Z Shell rather than, say, Bash ), when I start a new Terminal window ( I'm using iTerm 3.4.23 on macOS 14.2.1 ), I automatically open up in a virtual environment called base 

conda env list

# conda environments:
#
base                  *  /Users/hayd/anaconda3

type conda

conda is a shell function from /Users/hayd/.zshrc


This also gives me access to Jupyter : -

type jupyter

jupyter is /Users/hayd/anaconda3/bin/jupyter

jupyter notebook

  _   _          _      _
 | | | |_ __  __| |__ _| |_ ___
 | |_| | '_ \/ _` / _` |  _/ -_)
  \___/| .__/\__,_\__,_|\__\___|
       |_|

Read the migration plan to Notebook 7 to learn about the new features and the actions to take if you are using extensions.

https://jupyter-notebook.readthedocs.io/en/latest/migrate_to_notebook7.html

Please note that updating to Notebook 7 might break some of your extensions.

[W 15:06:56.602 NotebookApp] Loading JupyterLab as a classic notebook (v6) extension.
[I 2023-12-29 15:06:56.605 LabApp] JupyterLab extension loaded from /Users/hayd/anaconda3/lib/python3.11/site-packages/jupyterlab
[I 2023-12-29 15:06:56.605 LabApp] JupyterLab application directory is /Users/hayd/anaconda3/share/jupyter/lab
[I 15:06:57.709 NotebookApp] Serving notebooks from local directory: /Users/hayd
[I 15:06:57.709 NotebookApp] Jupyter Notebook 6.5.4 is running at:
[I 15:06:57.709 NotebookApp] http://localhost:8888/?token=707355ee0dd1f8fd9bf4e7124b83d1126a024cc4606eade0
[I 15:06:57.709 NotebookApp]  or http://127.0.0.1:8888/?token=707355ee0dd1f8fd9bf4e7124b83d1126a024cc4606eade0
[I 15:06:57.709 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:06:57.711 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///Users/hayd/Library/Jupyter/runtime/nbserver-33550-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=707355ee0dd1f8fd9bf4e7124b83d1126a024cc4606eade0
     or http://127.0.0.1:8888/?token=707355ee0dd1f8fd9bf4e7124b83d1126a024cc4606eade0
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.


which automatically opens up a browser tab: -


jupyter notebook list

Currently running servers:
http://localhost:8888/?token=707355ee0dd1f8fd9bf4e7124b8ad1126a024cc4606eade0 :: /Users/hayd


shows me the running notebook, plus it's port AND authentication token :-)

With the Jupyter server running, I quickly created a new Python3 ( pykernel ) notebook: -



and am off to the races: -



For reference, I'm working on watsonx.ai as a coder at present, and am running through some of the Python-based prompt engineering tutorials, and wanted a place to test the generated Python code

This was of use, in terms of getting me started: -



Saturday 4 November 2023

More on macOS SMB sharing

As a follow-up to an earlier post: -


I hit this problem again and referred back to my post, and also to Dan's post: -


digging further into the firewall settings on my Mac mini

Having noticed that smbd did NOT appear in the list returned by 

/usr/libexec/ApplicationFirewall/socketfilterfw —listapps

I looked again at the firewall settings: -


and explicitly added smbd via it's path: -

/usr/sbin/smbd

and also enabled smbd via 

 /usr/libexec/ApplicationFirewall/socketfilterfw --unblockapp /usr/sbin/smbd

Incoming connection to the application is permitted

Now it looks better: -

/usr/libexec/ApplicationFirewall/socketfilterfw --listapps

ALF: total number of apps = 4

1 :  /System/Library/CoreServices/ControlCenter.app
  ( Allow incoming connections )

2 :  /Applications/Firefox.app/Contents/MacOS/updater.app
  ( Allow incoming connections )

3 :  /usr/sbin/smbd
  ( Allow incoming connections )

4 :  /System/Library/CoreServices/UniversalControl.app
  ( Allow incoming connections )

and, even better, I can access the Mac Mini via SMB from other Macs without issues

Nice !

Monday 23 October 2023

Why I can't install jq on Ubuntu 20.04

 A friend asked me why they were unable to install jq onto their Ubuntu 20.04 Linux box - which seems like a perfectly reasonable to do / ask.
 
So I tried ...
 
And failed ...
 
lsb_release -a
 
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:    20.04
Codename:    focal

uname -a

Linux foobar.snafu.com 5.4.0-156-generic #173-Ubuntu SMP Tue Jul 11 07:25:22 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

apt-get update && apt-get upgrade -y
 
apt-get install -y jq

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package jq

Having read the jq download page, which says, in part: -
 
jq is in the official Debian and Ubuntu repositories. Install using sudo apt-get install jq.

I was confused, to say the least ....

And then I remembered to check the Aptitude Package Manager's sources.list file : -

cat /etc/apt/sources.list

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu focal main
# deb-src http://us.archive.ubuntu.com/ubuntu focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu focal-updates main
# deb-src http://us.archive.ubuntu.com/ubuntu focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
# deb-src http://us.archive.ubuntu.com/ubuntu focal universe
# deb-src http://us.archive.ubuntu.com/ubuntu focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
# deb-src http://us.archive.ubuntu.com/ubuntu focal multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu focal-backports main
# deb-src http://us.archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner

deb http://us.archive.ubuntu.com/ubuntu focal-security main
# deb-src http://us.archive.ubuntu.com/ubuntu focal-security main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu focal-security universe
# deb-src http://us.archive.ubuntu.com/ubuntu focal-security multiverse

or, more specifically, looking for the Ubuntu Universe repository : -

cat /etc/apt/sources.list|grep -i universe

## team. Also, please note that software in universe WILL NOT receive any
# deb-src http://us.archive.ubuntu.com/ubuntu focal universe
# deb-src http://us.archive.ubuntu.com/ubuntu focal-updates universe
# deb-src http://us.archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu focal-security universe

which showed that universe wasn't enabled ...

So I backed up the existing /etc/apt/source.list file: -

cp /etc/apt/sources.list /etc/apt/sources.list.ORIG
 
and then added the universe repo: -
 
cat <<EOF >> /etc/apt/sources.list
deb http://us.archive.ubuntu.com/ubuntu focal universe
deb http://us.archive.ubuntu.com/ubuntu focal-updates universe
deb http://us.archive.ubuntu.com/ubuntu focal-security universe
EOF


and tried again: -

apt-get update && apt-get install -y jq

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libjq1 libonig5
The following NEW packages will be installed:
  jq libjq1 libonig5
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 313 kB of archives.
After this operation, 1,062 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 libonig5 amd64 6.9.4-1 [142 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 libjq1 amd64 1.6-1ubuntu0.20.04.1 [121 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 jq amd64 1.6-1ubuntu0.20.04.1 [50.2 kB]
Fetched 313 kB in 1s (440 kB/s)
Selecting previously unselected package libonig5:amd64.
(Reading database ... 108600 files and directories currently installed.)
Preparing to unpack .../libonig5_6.9.4-1_amd64.deb ...
Unpacking libonig5:amd64 (6.9.4-1) ...
Selecting previously unselected package libjq1:amd64.
Preparing to unpack .../libjq1_1.6-1ubuntu0.20.04.1_amd64.deb ...
Unpacking libjq1:amd64 (1.6-1ubuntu0.20.04.1) ...
Selecting previously unselected package jq.
Preparing to unpack .../jq_1.6-1ubuntu0.20.04.1_amd64.deb ...
Unpacking jq (1.6-1ubuntu0.20.04.1) ...
Setting up libonig5:amd64 (6.9.4-1) ...
Setting up libjq1:amd64 (1.6-1ubuntu0.20.04.1) ...
Setting up jq (1.6-1ubuntu0.20.04.1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.12) ...

and now things are happy: -

jq --version

jq-1.6

cat ~/family.json | jq

{
  "friends": [
    {
      "givenName": "Dave",
      "familyName": "Hay"
    },
    {
      "givenName": "Homer",
      "familyName": "Simpson"
    },
    {
      "givenName": "Marge",
      "familyName": "Simpson"
    },
    {
      "givenName": "Lisa",
      "familyName": "Simpson"
    },
    {
      "givenName": "Bart",
      "familyName": "Simpson"
    }
  ]
}

Thursday 15 June 2023

macOS to macOS File Sharing - Don't work, try The IT Crowd

 I use File Sharing between two Macs on the same network, both running the latest macOS 13.4 Ventura.

For some strange reason I wasn't able to access one Mac - a Mini - from the other - a MacBook Pro.

As is always the case, the internet solved it for me: -

Fix File Sharing Not Working in MacOS Ventura

TL;DR; turn it off, and on again

Yes, The IT Crowd strikes again

Having said that, Dan Moren, he of Six Colours, acclaimed author AND MacBreak Weekly host, deserves full thanks for directing me to macOS' built-in firewall tool: -

/usr/libexec/ApplicationFirewall/socketfilterfw --listapps

Solving a file sharing mystery: Why one Mac can’t see another 

Whilst the TIOAOA trick worked this time, who knows what I'll need next time ...


Monday 22 May 2023

On the subject of aliases ...

I'm a super-massive fan of time/labour saving devices, and that goes for command-line tips n' tricks to save me: -

(a) typing more stuff

(b) looking in my notes to remember what I need, in order to type more stuff

Therefore, I've finally got around to creating an alias to create a new branch in a GitHub repo that I've cloned to my Mac.

I've added this alias to ~/.zprofile: -

gitbranch='git fetch origin && git rebase origin/master && git checkout master; git checkout -b $1'

so now I just need to type: -

gitbranch foobar

or: -

gitbranch snafu

in order to create a new branch ...

Which is nice.

Using 1Password to store API keys ...

 Following on from my earlier post: -

Wow, why have I not been using 1Password for my SSH keys before today ? 

I've got a little further, with various API keys now stored in my 1Password vault

This is far simpler, in that the vault entry, of type API Credential, only needs to have a name/title e.g. IBM Cloud API Key and a credential, the actual API key itself.

With that in place, I've then setup an alias to retrieve/display the API key: -

apikey='export APIKEY=$(op item get "IBM Cloud" --field credential) && echo $APIKEY'

in ~/.zprofile, meaning that I just need to run the "command" apikey to ... see my API key.

I will, of course, be leveraging the same API keys in various other scripts/aliases, including things that login to IBM Cloud etc.


Visual Studio Code - Wow πŸ™€

Why did I not know that I can merely hit [cmd] [p]  to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub...