Monday, September 02, 2024

raspberry pi not booting, error writing to SD card when reflashing with dd

One of the Raspberry Pis we use for video play-out in the waiting area was not booting. Simplest test was to use the other Pi's SD card and try booting with that one - worked. So, wanted to image that mini SD card to the one which was not booting. 

https://www.cyberciti.biz/faq/unix-linux-dd-create-make-disk-image-commands/
sudo dd if=/dev/sdc conv=sync,noerror bs=64K | gzip -c > my-root.image.gz
took around 45 minutes -
32 GB SD card with 5.5 GB used with df -h, due to gz it became 7.7 GB

Could monitor through watch -
https://www.baeldung.com/linux/dd-monitor-progress

watch -d ls -alh my-root.image.gz

But when trying to write back to the sdcard which was not booting (file system tests showed no errors after 'repairing'), 

sudo su -
# gunzip -c my-root-boot.image.gz | dd of=/dev/sdc status=progress

But after 10 minutes or so,

dd: writing to '/dev/sdc': Input/output error

https://superuser.com/questions/35349/dd-clone-hard-drive-input-output-error-though-chkdsk-says-ok

Tried conv=noerror -

gunzip -c my-root-boot.image.gz | dd of=/dev/sdc conv=noerror status=progress

Still the same error.

Then tried writing the disk image to another (64 GB) mini-sdcard which happened to be here. That worked without errors, and the R Pi booted up fine. So, maybe there are some physical errors, we might need to reformat (full format) and copy the files back (instead of cloning.)

Wednesday, August 28, 2024

displaying info about whether a package is installed or not on Linux command line

Earlier, I had used apt show for info on whether a package is installed or not. Another way - more concise - is to use apt-cache policy - 

$ apt-cache policy unattended-upgrades
unattended-upgrades:
  Installed: 2.3ubuntu0.3
  Candidate: 2.3ubuntu0.3
  Version table:
 *** 2.3ubuntu0.3 500
        500 http://azure.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     2.3 500
        500 http://azure.archive.ubuntu.com/ubuntu focal/main amd64 Packages

Sunday, August 25, 2024

show seek bar when paused - Android mp3 player app

There was a requirement for displaying the seek bar during playback and when paused, for mp3 files playing locally from a Nord CE4 Android phone. Trying out various players, it was not VLC, not simple music player, not the built-in media player - Files by Google alone shows seek bar for audio. The additional problem of "audio stopping when screen turned off" also seems to be fixed after installing this.

Friday, August 23, 2024

Azure - Transition from Azure classic administrator roles to RBAC roles

There was an email from Microsoft, asking admins to transition from Azure classic administrator roles to RBAC roles. 

I checked the "classic admin roles" for all our Microsoft tenants - found that those users who had classic admin roles have already been assigned 'Owner' RBAC roles, so probably nothing further needs to be done.

Thursday, August 22, 2024

Microsoft Azure - enable MFA - multi-factor authentication

Microsoft has sent an email asking Azure admins to enable MFA - multi-factor authentication - for all users of the Azure portal (and Entra, and Intune admin panels).

https://learn.microsoft.com/en-us/entra/identity/authentication/concept-mandatory-multifactor-authentication

But in the document above, they don't give a direct link to enable MFA, nor a direct link to enforce MFA. Probably because there are multiple ways to do it.

After a lot of searches, found the following. First we have to add sign-in methods for the MFA, then we can enable MFA.

Going to portal.azure.com
Home > Users > (my username) > Manage > Authentication methods
came to

https://mysignins.microsoft.com/security-info
 

Here, we can choose "Add sign in method" to add SMS, phone call, Microsoft Authenticator app or "Other authenticator app" like Google Authenticator which uses TOTP (time-based one-time password).

Then to enable or enforce 2FA (two-factor authentication) for admin users, we can go to portal.azure.com
(Just a note: Azure Entra ID is the new name for Azure Active Directory for translating from old tutorials.)

Users > Per user MFA (button on top of the page) > (which redirects to the page https://account.activedirectory.windowsazure.com/usermanagement/multifactorverification.aspx?tenantId=theRelevantTenantID for "legacy experience")

choose the relevant username, and then choose the "Enable" link on the right-hand pane. Confirm that you want to enable MFA for that user, then you are done.

If not "legacy experience", then the per user MFA page has a different look - with buttons to enable, disable or enforce MFA for the selected users, and also User MFA settings:


 

Monday, August 19, 2024

raspberry pi LibreElec Kodi playout issues and solution

Doing playout using Kodi and LibreElec, we had issues of disk corruption when using a FAT32 USB flash drive for the content - the first time we play a playlist there would be no issues, but when we go back to the beginning of the playlist using the page-down key, or using x to stop playback and open the playlist again, there would be random jumps during subsequent playout. 

Tried various workarounds like using a different USB flash drive, shutting down and restarting the Pi between shows (takes 5 minutes), "safely remove" the drive and re-plug it in between shows.

For a more durable solution, tried
(a) adding a powered USB hub for the Lexicon Alpha sound device
(b) using a USB drive formatted with NTFS instead of FAT32

With this configuration, the Pi seems to recognize the Lexicon Alpha without having to plug it in after the Pi boots up as noted in the previous post, and the playlist playout also doesn't skip. So, perhaps both these points helped.

Sunday, August 18, 2024

finding old files and disk space used - with Linux command line

 Following 

https://askubuntu.com/questions/413529/delete-files-older-than-one-year-on-linux

 and 

https://stackoverflow.com/questions/17419337/calculate-total-used-disk-space-by-files-older-than-180-days-using-find

 sudo su -

cd /the/relevant/directory

 find . -type f  -printf '%s\n' | wc -l  # for just the total number of files

find . -type f -mtime +365 -printf '%s\n' | wc -l  # for the number of files older than a year

find . -type f -mtime +365 -printf '%s\n' | awk '{total=total+$1}END{print total/(1024*1024*1024)}' # total disk space used by files older than 365 days, in GB

Saturday, August 17, 2024

using Wiz remote for fade in and out of lights

Using a Wiz remote and Wiz LED lamps and LED strips in the cove for fade-in, fade-out at our Theatre - only the setup required the mobile app - thereafter, it works with bluetooth, so doesn't need an internet connection. The app also allows us to add another user as an owner by just scanning a QR code from the app.

Tuesday, August 13, 2024

LIC 'Life certificate' via App

Senior citizens having LIC pension plans need to submit 'Life certificates' every year or so. According to the email they send, this can be done by submitting a form in the attached format duly filled, signed and witnessed, either by email or to a branch office or customer service cell, or via their 'LIC Digital' app.

Earlier, (maybe one year ago?) LIC had a separate app called "Jeevan Sakshya" - now the 'LIC Digital' app has the 'jeevan sakshya' feature at the bottom of the home screen.

Three verification methods are available in the app - Digilocker, offline Aadhaar and Central KYC. Offline Aadhaar xml does not seem to be available any more from the link given in the app. Digilocker method worked well for parents. (no need to install anything - just "give permission for digilocker to get your Aadhaar/PAN details" with Aadhaar OTP, then take a selfie.

Edit March 2025 - The app showed 'No data' though an SMS arrived asking for life certificate. Called up and asked the LIC Customer Zone - they said, yes, certificate is due. So I thought it might be due to Android removing data from unused app, so uninstalled it and reinstalled it. Then, 

  • Jeevan Sakshya at the bottom of the home screen
  • Register - with their registered mobile number 93*******
  • Then the policies for which life certificates were due were listed, and proceeded with Digilocker as above.

Friday, August 09, 2024

Force 5G on Any Android Device, find cell towers 5G strength etc

How to Force 5G on Any Android Device | 5G only Samsung -  https://youtu.be/Ea7XwM8W2_M

Net Monitor app, https://play.google.com/store/apps/details?id=com.parizene.netmonitor

(shows towers near you, shows 5G strength etc)

From home screen > service menu > Phone info > 
(Select Phone index 0 for SIM1 etc)

Scroll down to set preferred network type, and choose NR only (Network Radio).

(Airtel doesn't seem to work with NR only mode, even at office where 5G strength is high. Jio seems to work.)

Tuesday, July 30, 2024

headless raspberry pi - changing VNC desktop resolution

In order to set up a headless raspberry pi with VNC, we can first follow this - https://raspberrytips.com/raspberry-pi-headless-setup/

I used the Raspberry Pi Imager method - under Advanced Options in Pi Imager.

Then, as suggested in this video for an older version, I could connect to the VNC desktop on the Pi and change the resolution using

Start -> Preferences -> Screen configuration

Then Layout Menu -> Screens -> NOOP1 -> Resolution -> 1920x1080

Monday, July 29, 2024

Raspberry Pi 4 - setting static IP and checking CPU temp

How to Set a Static IP Address on Raspberry Pi
https://www.tomshardware.com/how-to/static-ip-raspberry-pi
(did it via vnc, had to install realvnc client as tightvnc client did not support)

How to check CPU temperature on Raspberry Pi - Linux Tutorials - Learn Linux Configuration
https://linuxconfig.org/how-to-check-cpu-temperature-on-raspberry-pi

ffmpeg 25 fps to 24 fps

Due to this issue with OCVWarp and frame sequences, needed to change the fps for a video from 25 fps to 24 fps.

We can do it with re-encoding using Avisynth, under 

Video -> Filters -> Transform -> Change FPS

 - useful if we want to change the codec -

or without re-encoding with ffmpeg with a command similar to the one in my earlier post,

ffmpeg -itsscale 0.834167501 -i input-25fps.mp4 -vcodec copy output-24fps.mp4

Sunday, July 28, 2024

mp3 encoding for dot net application

We got a request to install NAudio and NAudio.Lame on the production server of one of our dot net apps. But the prod server runs Linux, and NAudio uses DirectSound, hence is Windows-only. The developers were informed, and they decided to use ffmpeg instead. We used /etc/environment to add the env variable FFMPEG_PATH they wanted to create, using whereis to find the location of the executable.

Notes:

https://www.nuget.org/packages/NAudio/
dotnet add package NAudio --version 2.2.1
run inside project folder, or else error
Could not find any project in `/home/ubuntu/`.

as the relevant user in the directory also, same error.

https://stackoverflow.com/questions/56062228/error-dotnet-could-not-find-any-project-in-c-when-running-dotnet-add

But dotnet add package--help indicates that this would just add a reference to the nuget package to the project.

So, anyway nuget would need to be installed.

sudo apt install nuget
and then ...
Oh!
https://github.com/naudio/NAudio/issues/1077
NAudio does not have linux support due to directsound dependency.

Thursday, July 25, 2024

rclone and RCloneBrowser for uploading 30 GB files to Google Drive

As noted earlier, rclone is the preferred solution to transfer large files to and from Google Drive.

A point to note is that mounting and then copying seems to result in errors for Google Drive if transfer times are greater than an hour or two, so we should preferably use just rclone copy or copyto.

In the case of a Windows machine, here were my steps:

choco install rclone
rclone config

(to create the gdrive remote)
(choose everything as the defaults.)
rclone lsd gdrivemydrivename:
(to list directories)
rclone copy myfilename.mp4 gdrivemydrivename:mydirname --progress

Unfortunately, RCloneBrowser doesn't show bandwidth or time to completion with the latest rclone. So, the commandline, or browser UI might be better.

chocolatey install

Many open-source projects can be easily installed on Windows using chocolatey - and it's scriptable, too. Installing chocolatey itself took a few steps.

I should have done with this,

https://docs.chocolatey.org/en-us/choco/setup/#installing-chocolatey-cli

but I ended up doing the powershell install,

https://docs.chocolatey.org/en-us/choco/setup/#install-with-powershellexe

So, running powershell as administrator, checking powershell version with

$PSVersionTable

(it was v5, so chocolatey is supported) and then  

Get-ExecutionPolicy

returned Restricted, so then ran 

Set-ExecutionPolicy AllSigned

and then the install script with

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))


Opening a cmd window (as administrator) after this, and 

choco install ffmpeg 

worked fine.

Tuesday, July 23, 2024

VNC scraping server

Looking to reinstall some sort of VNC on an old Lenovo Thinkpad (where the built-in keyboard has issues with some crucial keys like <space> and <enter>) - found this useful thread about installing Tiger VNC scraping server, for making screen 0 available - so that works well with cinnamon desktop, unlike other VNC solutions - 

https://forums.linuxmint.com/viewtopic.php?t=351208

 sudo apt-get install tigervnc-scraping-server

We need to use the -localhost no option also, if not tunnelling over SSH, as mentioned in the last part of that thread. So, the way I've implemented is to create a startvnc.sh with the following command,

x0vncserver -PasswordFile=/home/user/.vnc/passwd -localhost no

where the pw file was created by running

vncpasswd

Then, in Linux Mint, there is the "Startup Applications" Menu item, where we can add this script startvnc.sh with an appropriate delay if required - I've put in a 5 second delay.

booting from secondary SSD - /dev/sdb

At first, installed on the secondary drive (SSD), and Linux Mint automatically wrote grub to the SSD. But when booted, grub was loaded from the primary drive. First, I tried update-grub which worked - the new install was also seen. But when I reformatted the primary hard disk, a grub rescue> prompt was seen. In my case, I did not really need to do the grub rescue - instead, I needed to go into the bios by pressing enter on a USB keyboard during boot (since the built-in keyboard enter key was broken), then Startup --> Boot --> make the SSD the primary boot device, then save and reboot.

Tuesday, July 16, 2024

write to csv from Python

 Python Write Array To CSV [4 Methods] - Python Guides

Of the four options,
pandas.to_csv()
csv.writerow()
numpy.savetxt
numpy.tofile()

the tofile() method was what I used for the spline in OSREC-interp.

Monday, July 15, 2024

deployment-target in cordova moodle app config.xml file

Initially, I thought the 

<preference name="deployment-target" value="13.0" />

in the moodle app's config.xml file referred to Android version, so it should be updated to 14.0 for the SDK target 34 upgrade.

But as pointed out by @dpalou, this refers to iOS version, nothing to do with Android. 

Checking for 5G coverage

Following this video, could find that there is 5G coverage for Airtel at my location, using the Ookla Speedtest app, by going to the Maps button at the bottom of the home screen.

Wednesday, July 10, 2024

node version change in building customized Moodle app

Node version change, as we can see from this line in package.json for the moodle app,

so, changed this line in our build workflow.

Tuesday, July 09, 2024

Moodle Mysql database CPU usage at 200%

Originally, the issue raised was that an ad-hoc query was taking a long time to run. But checking the server, found that mysqld was using 200% CPU.

Checking why the database usage is so high, I tried to check which queries are taking more time on the db - 

Found that some ad hoc tasks are the culprit.
# Time: 2024-07-08T08:07:05.163875Z
# User@Host: db_admin[db_admin] @  [::1]  Id:  8699
# Query_time: 7.503725  Lock_time: 0.000050 Rows_sent: 3  Rows_examined: 384225
SET timestamp=1720426017;
SELECT classname FROM task_adhoc WHERE nextruntime < '1720426017' GROUP BY classname;
# Time: 2024-07-08T08:07:05.193117Z
# User@Host: db_admin[db_admin] @  [::1]  Id:  8551
# Query_time: 5.819065  Lock_time: 0.000049 Rows_sent: 3  Rows_examined: 384225
SET timestamp=1720426019;
SELECT classname FROM task_adhoc WHERE nextruntime < '1720426019' GROUP BY classname;
 
Checking under tasks,
https://ourserver.org/admin/tool/task/runningtasks.php
I see that an ad-hoc task of course_delete_modules has been running for 5+ hours

This is what is causing the db to become unresponsive.
From this page,
https://ourserver.org/admin/category.php?category=taskconfig
I see that the task is not supposed to take so long. Max lifetime is supposed to be 30 minutes.
 
Rebooting didn't help.

I had to go to the database and delete the relevant row from the adhoc_tasks table in the database.

So that task is now gone from the "Tasks running now" screen. 

But other tasks are running, which is normal. What is not normal is the extremely high CPU usage of the mysql database on the database server.  

The CPU 200% issues seems to be related to adhoc tasks being run by mod_forum

The task_adhoc table for this instance is filled with entries created by
\mod_forum\task\send_user_notifications
tasks - the other moodle instances don't have these.
 
From
checked
mdl_forum_queue table.

Found 45 rows, starting July 2, just like the adhoc
timemodified 1719909620

Could not find the relevant forum posts, so blindly deleted. 

Currently the cpu usage of mysql database has come down to < 1% - for which the following were done:
  • deleted the mod_forum notification ad hoc tasks from task_adhoc table - around 385,000 rows! dating from July 2
  • deleted the vv_forum_queue notification queue - around 45 rows, dating from July 2.
I'm leaving this for now, since I'm not sure what exactly we can do to prevent this sort of behaviour in future.
 
 

optimizing SQL code with help from ChatGPT

I had asked PB for help with optimizing the SQL code at
https://github.com/hn-88/ad-hoc-moodle-database-queries/blob/main/Feedback%20for%20all%20courses.sql

since it would time out for anything more than just a few lines of results, taking more than half an hour and slowing down the database. 

His response was to ask ChatGPT.

ChatGPT gives the following suggestion:
  1. Reduce Subqueries: Instead of running multiple subqueries for each feedback item, we join the feedback_value and feedback_item tables multiple times to get the necessary values.
  2. Conditional Aggregation: We use MAX(CASE WHEN ...) to fetch the appropriate values for each feedback item type.
  3. Grouping: We group by the relevant fields to ensure distinct results.

This approach reduces the number of scans and joins, potentially speeding up the query execution.



SQL STATEMENT

___________________________________________________
SELECT
    FROM_UNIXTIME(fc.timemodified) AS Time,
    fc.userid,
    u.idnumber,
    u.username,
    u.firstname,
    u.lastname,
    u.email,
    u.institution,
    fv.value AS "Email entered",
    c.fullname AS BSS,
    MAX(CASE WHEN fi2.name LIKE '%Chapter%' AND fi2.typ = 'textfield' THEN fv2.value ELSE NULL END) AS "Chapter name",
    MAX(CASE WHEN fi3.name LIKE '%Main%Script%' THEN fv3.value ELSE NULL END) AS "MainScript",
    MAX(CASE WHEN fi4.name LIKE '%Inquisit%uestion%' THEN fv4.value ELSE NULL END) AS "IQ",
    MAX(CASE WHEN fi5.name LIKE '%Suggested%ctivity%' THEN fv5.value ELSE NULL END) AS "SA",
    MAX(CASE WHEN fi6.name LIKE '%Assessment%' THEN fv6.value ELSE NULL END) AS "QA",
    MAX(CASE WHEN fi7.name LIKE '%Day%day%elevan%' THEN fv7.value ELSE NULL END) AS "DD",
    MAX(CASE WHEN fi8.name LIKE '%Value%ontent%gained.' THEN fv8.value ELSE NULL END) AS "VC",
    MAX(CASE WHEN fi9.name LIKE '%Interest%side%' THEN fv9.value ELSE NULL END) AS "IA"
FROM
    {feedback_value} fv
    LEFT JOIN {feedback_completed} fc ON fc.id = fv.completed
    LEFT JOIN {user} u ON fc.userid = u.id
    LEFT JOIN {feedback_item} fi ON fi.id = fv.item
    LEFT JOIN {feedback} f ON f.id = fi.feedback
    LEFT JOIN {course} c ON c.id = f.course
    LEFT JOIN {feedback_value} fv2 ON fc.id = fv2.completed
    LEFT JOIN {feedback_item} fi2 ON fi2.id = fv2.item
    LEFT JOIN {feedback_value} fv3 ON fc.id = fv3.completed
    LEFT JOIN {feedback_item} fi3 ON fi3.id = fv3.item
    LEFT JOIN {feedback_value} fv4 ON fc.id = fv4.completed
    LEFT JOIN {feedback_item} fi4 ON fi4.id = fv4.item
    LEFT JOIN {feedback_value} fv5 ON fc.id = fv5.completed
    LEFT JOIN {feedback_item} fi5 ON fi5.id = fv5.item
    LEFT JOIN {feedback_value} fv6 ON fc.id = fv6.completed
    LEFT JOIN {feedback_item} fi6 ON fi6.id = fv6.item
    LEFT JOIN {feedback_value} fv7 ON fc.id = fv7.completed
    LEFT JOIN {feedback_item} fi7 ON fi7.id = fv7.item
    LEFT JOIN {feedback_value} fv8 ON fc.id = fv8.completed
    LEFT JOIN {feedback_item} fi8 ON fi8.id = fv8.item
    LEFT JOIN {feedback_value} fv9 ON fc.id = fv9.completed
    LEFT JOIN {feedback_item} fi9 ON fi9.id = fv9.item
WHERE
    fc.timemodified > :fromdate
    AND fc.timemodified < :todate
    AND u.idnumber LIKE :paramidnumber
    AND fi.name LIKE '%Email%'
GROUP BY
    FROM_UNIXTIME(fc.timemodified),
    fc.userid,
    u.idnumber,
    u.username,
    u.firstname,
    u.lastname,
    u.email,
    u.institution,
    fv.value,
    c.fullname
___________________________________________________

Please check if this suggestion helps.

My response to this was, after trying out the code suggested by ChatGPT and then modifying it:

The code shown [above] did not work - my earlier code was producing 5 rows in around 5-10 minutes, the chatgpt code ran for 30 minutes without any result. Looking at the code, there are some possible mistakes like the lines like 
LEFT JOIN {feedback_value} fv3 ON fc.id = fv3.completed

Corrected the code as
c.fullname AS BSS,
    MAX(CASE WHEN fi2.name LIKE '%Chapter%' AND fi2.typ = 'textfield' THEN fv2.value ELSE NULL END) AS "Chapter name",
    MAX(CASE WHEN fi2.name LIKE '%Main%Script%' THEN fv2.value ELSE NULL END) AS "MainScript",
    MAX(CASE WHEN fi2.name LIKE '%Inquisit%uestion%' THEN fv2.value ELSE NULL END) AS "IQ",
    MAX(CASE WHEN fi2.name LIKE '%Suggested%ctivity%' THEN fv2.value ELSE NULL END) AS "SA"
, etc etc

instead of fi3, fi4, fi5, fi6 etc, and now the code runs much faster. 6 rows in 6 seconds.

https://github.com/hn-88/ad-hoc-moodle-database-queries/blob/main/Feedback%20for%20all%20courses%20revised.sql

Thanks once again. :)

(Some references I looked up, but could not find immediate solutions to my problem:

How to fix MySQL high CPU usage (bobcares.com)



)

Thursday, July 04, 2024

link from div to open in new window

We wanted a "click here" image link for one of our websites, but the image was actually a background in CSS and not a simple img html tag. So, basically we needed to make the entire div into a clickable link. Following these,

https://stackoverflow.com/questions/7185044/change-the-mouse-cursor-on-mouse-over-to-anchor-like-style

https://stackoverflow.com/questions/5141910/javascript-location-href-to-open-in-new-window-tab

https://stackoverflow.com/questions/8524470/click-anywhere-on-div-instead-of-directly-on-link

what we used was something like this:

<div class="our-class-name" style="cursor: pointer" onclick="window.open('ourpage.html', '_blank');">

Tuesday, July 02, 2024

Microsoft Teams for new users

One of our institutions wanted to add a large number of new users to Microsoft Teams. Initial plan was to create email ids in Google Workspace and then add them as Guest users in Microsoft Admin console. But then, it would be much easier for the users, and also retain all the functionality of sharing meeting id via email etc if the users were created within Microsoft Admin console instead. So, finally, that was the way it was done. 



 

Saturday, June 29, 2024

Azure - Update firewall configurations to allow Logic Apps IP addresses

We got an email from Microsoft Azure, asking us to update firewall configurations to allow Logic Apps IP addresses by 28 September 2024.

Verified in all our accounts that the only logic apps we used were the VM automatic start/stop apps which are currently disabled. So, no action to be taken for this.

Friday, June 28, 2024

quaternion tutorial

https://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#how-do-i-create-a-quaternion-in-c-

It turned out that I did not need to include glm etc, as in the page above, since simple linear interpolation followed by normalization was sufficient for my use case. Apparently linear interpolation is close, though not exact - this discussion.

Wednesday, June 26, 2024

unable to see old assets after email change

One of our websites had an issue, described as below:

... User was accessing the system using old@gmail.com. She had some issues with that id and she edited her profile on CMS and changed it to new@gmail.com While the system allows her to login using her new email address, she is unable to see the assets assigned to her as editor in the new id. Even when she creates an asset, even though she logs in with her new email, the asset gets created under her old email id ...
Solution was:

In the users table of the Postgres database, only the "email" field is editable by users - now updated the "username" field to
new@gmail.com
from
old@gmail.com

(The updating of username field by users is not enabled since back-end changes to the CMS data sheet are needed when such a change happens.)

additional spam protection for forms using Cloudflare turnstile

One of our forms, which had first level protection using a hidden field, occasionally got bursts of spam submissions. Added Cloudflare turnstile as an additional layer of protection.

In the <head> section of the web page which had the form, 

<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" defer></script>

Inside the form,

<div class="cf-turnstile" data-sitekey="0x4OUR-SITE-KEY0-"></div> 

and in the done function, handling the "failed captcha" situation - 

 $.ajax({
                        method: "POST",
                        url: url,
                        data: user
                    }).done(function (msg) {

                        // When the request is successful
                        if(msg=="Success") {
                        $('span').html('<strong>Thank you for submitting your details. We will get back to you shortly, in a week or so.</strong>');
                        $("form").trigger("reset");
                        }
                        if(msg=="Failed captcha.") {
                            $('span').html('<strong>Please resubmit after the captcha loads, checking the box to confirm you are human if necessary.</strong>');
                        }
                    }).fail(function (err, textstatus, error) {
                        $('span').text(textstatus);
                    });

              

Then, we need to add some back-end code. Since we're using Google Apps Scripts, this looked like:

function doPost(e) {

var scriptProperties = PropertiesService.getScriptProperties();
var myKey = scriptProperties.getProperty('SECRET_KEY');
.....
const siteresponse = e.parameter['cf-turnstile-response'];
.....
var verifyurl = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
var formData = {
'secret': myKey,
'response': siteresponse
};
var options = {
'method' : 'post',
'payload' : formData
};

var responsetositeverify = UrlFetchApp.fetch(verifyurl, options);
var verifydata = JSON.parse(responsetositeverify.getContentText());


if (!verifydata.success) {
// do the rest of the processing only if verification returns success.
return ContentService.createTextOutput().append('Failed captcha.');
}
 
 

 


Monday, June 17, 2024

problem and workaround for Youtube api calls from Google Apps script

When trying to implement the earlier solution to one of our channels, the script would fail, complaining that the user was not authorized for live streams. Interestingly, when using google api explorer, it asks whether to use the google account or the youtube brand name. If we choose the latter, it works.

The issue and its solution are discussed at  

Accordingly, started work on a script of our own, based on this blog post, but paused development since manual creation of broadcasts was preferred due to the complicated setup which depends on GDrive service which would fail at least once a month as my previous experience with Drive service shows.

The one take-away from this exercise seemed to be that the 'consent screen' needs to be set to 'Production' for this workaround to work, otherwise the Oauth doesn't proceed.

Sunday, June 16, 2024

Missing Site UUID or Hub Secret error in Moodle

One of our Moodle sites was presenting users with this error, "Missing Site UUID or Hub Secret. Please check your Hub registration".

Apparently the fix is to change a setting, as mentioned at
https://h5p.org/node/1472461

"uncheck the option "Use H5P-hub. mod_hvp | hub_is_enabled" in the H5P settings in Moodle (.../admin/settings.php?section=modsettinghvp"

But that setting says, "It's strongly encouraged to keep this option enabled. The H5P Hub provides an easy interface for getting new content types and keeping existing content types up to date. In the future, it will also make it easier to share and reuse content. If this option is disabled you'll have to install and update content types through file upload forms."

There is also an option to "Register an account with H5P hub" just below that.

I have now tried entering some data into the "register an account" part, for one of our Moodle sites.

Hopefully this resolves the issue.

Sunday, June 02, 2024

closed Airtable and SendinBlue (now Brevo) accounts

Since I'm no longer using their services, closed Airtable and Brevo (formerly Sendinblue) accounts. For Airtable, I copy-pasted a table I had made into a Google Sheet, deleted collaborators from it, and then deleted my account. 

Saturday, June 01, 2024

VP9 codec for 4K video on Raspberry Pi4 - stutters

Tested a video encoded with VP9 - very good quality 4K video - only 2.5 GB file size for a 24 minute 4K video - but playback on Kodi running on Raspberry Pi 4 stutters for high complexity scenes. x265 is the way to go, for now. 

Tuesday, May 28, 2024

Zoom in from Milky Way to Puttaparthi

The scripts and settings used to generate this 4k fisheye fulldome video are shared at https://github.com/hn-88/openspace-scripts 


The following script was used,
https://github.com/hn-88/openspace-scripts/blob/main/user/recordings/zoom-out-psn-to-galaxy4.osrectxt

where the motion is actually backwards, zooming out, in order to give a more controlled zoom travel. 

ffmpeg and blender were used to render the screenshot image sequences into video, forward and backwards. Blender could be used to fine-tune the video by speeding up parts of the video without much action and so on. 

ffmpeg to reverse a frame sequence - https://stackoverflow.com/questions/40475480/ffmpeg-convert-image-sequence-to-video-with-reversed-order

The zoom-in (reversed frames) have been uploaded and made available at archive.org using the x265-lossless codec under a Public Domain licence.

https://archive.org/details/zoom-in-to-psn-lossless

react app in docker vs native

Relative performance etc - via
which is hosted on vercel, https://gitachapsummwtel.vercel.app/

Hosting next.js on our own server -

Performance of docker -

Apparently nearly as good as native.

Monday, May 27, 2024

ffmpeg lossless for archive.org and reverse order of frames

Archive.org did not accept zip files containing frames for uploading 4K content, but lossless codecs were accepted.

ffmpeg - Best Lossless Video Codec for 8 bpc RGB image sequences? - Super User

seems to indicate that the best seems to be x265,

and commandline
 
ffmpeg -i input.mp4 -c:v libx265 -x265-params lossless=1 output.mp4 

And for reversing the frame order (backwards video),

 
- first bulk rename to - (minus) for the numbers prefix.

Saturday, May 25, 2024

github importer, for making a copy of a repository from the web interface

For testing a reported opencv bug

 
I wanted to make a copy of one of my repositories. Instead of cloning to a local directory etc, I wanted to do it from github's web interface. The solution seemed to be to use github importer. 
 
At the upper-right corner of any page, click the plus sign, and then click Import repository
 

making google great again

A follow-up to my post about the beginning of the end of Google -

https://askleo.com/why-ive-stopped-using-google-search/

and a temporary band-aid fix to get better search results from google,

https://tedium.co/2024/05/17/google-web-search-make-default/

- just add &udm=14 to the end of the search query url. 

Tuesday, May 21, 2024

Fly through Mars valley and Grand Canyon - generated with OpenSpace

The scripts and settings used to generate these 4k fisheye fulldome videos are shared at https://github.com/hn-88/openspace-scripts


 

https://github.com/hn-88/openspace-scripts/blob/main/user/recordings/setupgrandcanyon.osrectxt

https://github.com/hn-88/openspace-scripts/blob/main/user/recordings/grandcanyonflyin5.osrectxt

(default profile, Window options fisheye 4k as at
https://github.com/hn-88/openspace-scripts/blob/main/config/single_fisheye-4k.json )

Link to 4096x4096 video at archive.org -  https://archive.org/details/grand-canyon5

Flying 5 km (3 miles) above a valley on Mars, near Valles Marineris


https://github.com/hn-88/openspace-scripts/blob/main/user/recordings/marsvalley2setup2.osrectxt

https://github.com/hn-88/openspace-scripts/blob/main/user/recordings/marsvalley2upfrombeginning3.osrectxt

(this recording is played in reverse at the beginning of the video.)

https://github.com/hn-88/openspace-scripts/blob/main/user/recordings/marsvalley2.osrectxt

Link to 4096x4096 video at archive.org - https://archive.org/details/mars-fly-into-valley0001-6940

The 4k frames are available with me, and can be made available. I'll also see if I can upload them to archive.org - Edit - apparently zip files with jpg frames can't be uploaded to archive.org, so I have added links to the 4K movie files uploaded to archive.org above.

Monday, May 20, 2024

Microsoft's answer to brute force mitigation - $$$

 How to avoid successful SSH Brute Force Attack - Microsoft Q&A

mentions Just-in-time access usage. But that

https://learn.microsoft.com/en-us/azure/defender-for-cloud/just-in-time-access-usage

requires Defender for Cloud Plan 2

https://learn.microsoft.com/en-us/azure/defender-for-cloud/plan-defender-for-servers-select-plan#plan-features

which costs nearly $15 per month per server!

https://azure.microsoft.com/en-us/pricing/details/defender-for-cloud/

Indian income tax e-filing - validation failed

When filling up the ITR2 income tax return, one of the "validation failed" messages said:

In Schedule CG, Sl. No. B4a LTCG u/s 112A is not equal to total of Col. 14 of Schedule 112A

This is probably because of rounding errors, I think. The numbers in the quarter-wise table in Schedule CG (Capital Gains) must add up to the numbers in Schedule 112A. So we should manually add and check, and make small one rupee adjustments to make the quarterly numbers add up to the total in Schedule 112A.

Another couple of points to note when there are "brought-forward losses" -
(1) in that case, the maximum amount of the BFL has to be applied - we can't apply a lower amount of the total losses to cover only part of the profits of this financial year
(2) and the numbers in the quarterly numbers should then add up to zero (if the losses completely cover the profits.)

Monday, May 13, 2024

making a copy of a wordpress blog and setting it up on another domain

What I should have done:

Probably I should have used wp-cli to deactivate all plugins before the migration. And apparently, the whole thing could have been done far easily with wp-cli - https://rocketgeek.com/basics/using-wp-cli-to-migrate-copy-your-site/
https://guides.wp-bullet.com/migrate-wordpress-site-new-server-wp-cli/

Steps taken:

0. Ran all commands inside screen.

1. https://wordpress.stackexchange.com/questions/75135/how-to-export-import-wordpress-mysql-database-properly-via-command-line
says a normal mysqldump should suffice.

2. Mysqldump complained about permissions -
Error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump tablespacesldump: Error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump tablespaces

So, https://dba.stackexchange.com/questions/271981/access-denied-you-need-at-least-one-of-the-process-privileges-for-this-ope

SHOW GRANTS for someuser@localhost;.

To add the global privilege use the SQL command
GRANT PROCESS ON *.* TO someuser@localhost;

That solved the issue. In our case, I was running the SQL commands from the SQL console of dbeaver.

3. Created a new db as root, granted permissions for the relevant user as per https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

4. mysql -u theuser -p thenewdb < wpdevelbackup.sql to populate the new db.

5. Copied over the directory with cp -a to retain permissions as well as do a recursive copy - https://unix.stackexchange.com/questions/44967/difference-between-cp-r-and-cp-a
sudo cp -a olddirectory newdirectory

6. After that, need to update the wp_options table in the new database. option_value like '%public_html%' showed all the required changes to be made after siteurl -
siteurl
home
astra_sites_recent_import_log_file
recently_edited
astra_sites_recent_import_log_file
fs_active_plugins
duplicator_package_active
uagb_downloaded_font_files
_transient_dirsize_cache

(Had to copy paste to text editor and find and replace for the multiple instances of the old path in some of these fields.

the _transient field was very big. Since anyway it would be recreated, deleted its value instead of changing the path to the new path for that value.)

7. Have to edit wp-config file also, since the site was redirecting back to the old url. https://www.sitepoint.com/how-to-migrate-a-wordpress-site-to-a-new-domain-and-hosting/
Had to add the
define('WP_HOME','https://oursite.com');
define('WP_SITEURL','https://oursite.com');

at the end of wp-config file also, since I had not de-activated the plugins before doing the migration. Or maybe just a caching problem with firefox which I used for testing. Site was working at this point, when tested with another browser. (I had done the editing of /etc/apache2/sites-available etc beforehand.)

Wednesday, May 08, 2024

Schedule Page date listing much in advance

 PB wanted to verify that the schedule created for a few days in advance loads OK on the schedule page. But only a few days were visible. This was because

the code checks if the schedule data txt file is available, and then updates the dropdown, but only up to 5 days in advance -


while (dtimems < dateplus5ms) {
addifscheduledataavailable(dtimems);
dtimems += 24 * 60 * 60 * 1000;
}

It may be possible to see the schedule of other dates by changing your system date to the future.

And indeed, PB confirmed that he could check the published playlists for future dates by changing the system date.

Monday, May 06, 2024

run simple python code online

There is google's colab for executing python workbooks online, in the browser. But for simple code, trinket.io - "no need to log in, download plugins, or install software. "
via
https://www.youtube.com/watch?v=v7svyPnIeGA
via
https://www.wired.com/story/why-the-solar-system-is-flat/

Thursday, May 02, 2024

interesting problem with S3 buckets - anyone can do a $ DDoS now

Copy-pasting from Slashdot - 

How an Empty S3 Bucket Can Make Your AWS Bill Explode (medium.com) 55

Posted by msmash on Tuesday April 30, 2024 @03:10PM from the oops dept.
Maciej Pocwierz, a senior software engineer Semantive, writing on Medium: A few weeks ago, I began working on the PoC of a document indexing system for my client. I created a single S3 bucket in the eu-west-1 region and uploaded some files there for testing. Two days later, I checked my AWS billing page, primarily to make sure that what I was doing was well within the free-tier limits. Apparently, it wasn't. My bill was over $1,300, with the billing console showing nearly 100,000,000 S3 PUT requests executed within just one day! By default, AWS doesn't log requests executed against your S3 buckets. However, such logs can be enabled using AWS CloudTrail or S3 Server Access Logging. After enabling CloudTrail logs, I immediately observed thousands of write requests originating from multiple accounts or entirely outside of AWS.

Was it some kind of DDoS-like attack against my account? Against AWS? As it turns out, one of the popular open-source tools had a default configuration to store their backups in S3. And, as a placeholder for a bucket name, they used... the same name that I used for my bucket. This meant that every deployment of this tool with default configuration values attempted to store its backups in my S3 bucket! So, a horde of misconfigured systems is attempting to store their data in my private S3 bucket. But why should I be the one paying for this mistake? Here's why: S3 charges you for unauthorized incoming requests. This was confirmed in my exchange with AWS support. As they wrote: "Yes, S3 charges for unauthorized requests (4xx) as well[1]. That's expected behavior." So, if I were to open my terminal now and type: aws s3 cp ./file.txt s3://your-bucket-name/random_key. I would receive an AccessDenied error, but you would be the one to pay for that request. And I don't even need an AWS account to do so.

Wednesday, May 01, 2024

OCVWarp on Google Cloud Shell

Checked and found that OCVWarp works (though slowly - 5 fps for XVID encoded 1080p output) even on Google Cloud Shell, after installing the dependencies.

wget https://github.com/hn-88/OCVWarp/archive/refs/tags/v4.01.zip
unzip v*.zip
cd OCVWarp*/build
wget https://github.com/hn-88/OCVWarp/releases/download/v4.01/OCVWarp-4.01-x86_64.AppImage
chmod +x OCV*mage
mv OCV*mage ocvwarp
sudo apt install libopencv-dev


(after uploading the input file)


./ocvwarp OCVWarp.ini 30fps.mp4 output.mp4

Friday, April 26, 2024

Moodle upgrade path - 4.1 to 4.5

An evaluation of requirements and timelines for upgrading Moodle 4.1 to 4.3 or 4.5.

Moodle 4.1 -> 4.3

Min PHP 7.4 -> 8
PHP extension sodium is required
(seems to be built in to 8
)
PHP setting max_input_vars must be >= 5000.
PHP variants: Only 64-bit versions of PHP are supported.

MySQL 8.0 (increased since Moodle 4.1)

Moodle 4.4 release date is 22 April 2024
so probably should upgrade to that - OR -

Next LTS is 4.5. 7 October 2024.

Moodle 4.1 -> 4.4

Min PHP 8.1

Ubuntu 22.04
PHP 8.1.2
Mysql 8.0.28

PHP 8.3

How to upgrade from Ubuntu 20.04 to 24.04 - Probably will need to do it as a two step process -
https://linuxconfig.org/ubuntu-upgrade-to-24-04-noble-numbat-a-step-by-step-howto-guide
 
20.04 is supported till Apr 2025. So in Oct 2024, we should be able to upgrade the OS and Moodle together. 







Friday, April 19, 2024

Filezilla TLS errors

When using Filezilla on Linux Mint at work, connecting to an FTP server, after logging in, I get some errors like the following:


Command: LIST
Response: 150 Opening BINARY mode data connection.
Error: GnuTLS error -110: The TLS connection was non-properly terminated.

Some file transfers go through, while some get 550 errors - when I close Filezilla and open it again, the transfer succeeds.
 
Later, when using Windows and downloading using a domestic BSNL fiber line, there were no errors.
 
According to this set of posts on serverfault, it may have been due to either the firewall gateway blocking passive mode FTP or it may have been something to do with implicit/explicit TLS.

Wednesday, April 17, 2024

methods to download from Amazon S3 bucket (if we own/manage the bucket)

Some ways are mentioned at 

 
Cyberduck can provide a UI for Windows or Mac - "Cyberduck is a libre server and cloud storage browser for Mac and Windows with support for FTP, SFTP, WebDAV, Amazon S3, OpenStack Swift, Backblaze B2, Microsoft Azure & OneDrive, Google Drive and Dropbox."

Saturday, April 13, 2024

workflow_dispatch only from default branch

I like to set Github Actions to only run when manually triggered, that is, using workflow_dispatch

As that page says,  "To trigger the workflow_dispatch event, your workflow must be in the default branch."

But we can change the default branch - like we may want to do for forks etc - Repository --> Settings --> Default branch (choose by clicking the "choose another branch" button which has two opposing arrows as an icon)

comparing the contents of two directories on Windows

 How to Compare Two Folders on Windows 11 and 10 (howtogeek.com)

robocopy "C:\first" "C:\second" /L /NJH /NJS /NP /NS

Thursday, April 11, 2024

reminder to take a break - using cron

Wanted to create a pop-up message or reminder (and was later requested an audio reminder) for N to take periodic breaks from the computer. Since his usage was mostly passive, workrave did not work for this purpose - workrave's timer only progresses when the keyboard or mouse are active.

 Looking for solutions, reminder apps on Mint/Ubuntu seemed to have only flatpak versions which I did not want to install.

Finally thought it would be simpler to use cron.

But, to pop up messages on the screen with cron, we need some special handling.
https://unix.stackexchange.com/questions/307772/pop-up-a-message-on-the-gui-from-cron
https://unix.stackexchange.com/questions/111188/using-notify-send-with-cron

And for audio, we would need another line to be added to the script. Working script - 

#!/bin/bash
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
export DISPLAY=:0
export XDG_RUNTIME_DIR=/run/user/1000
# this last line above is for sound to work
notify-send -u critical "this is the reminder to take a walk"
# the -u critical is supposed to show over full screen apps, but doesn't always work
/usr/bin/mpg123 /home/username/Downloads/Walk.mp3 > /dev/null 2>&1

For help with setting up cron, cron.help is useful. Eg.

*/30 * * * * /home/username/walkremind.sh

for every half an hour.

For getting the environment variables' values, used

printenv

And for installing notify-send

sudo apt install libnotify-bin