Wednesday, March 19, 2025

Working with server and browser time


Consider the image:

  • A is showing 8 hours ago because the server time is in a different time zone (TZ) to the TZ of the browser
  • B is what we want because that's the browser or local time which is computed with the TZ offset.

In the "olden" times, getting the browser or local datetime in reference to a server's datetime was to use a library like moment.js. But browsers have gone a long way.

Actually code:


const offsetLocalTime = new Date(dateStringFromServer);

offsetLocalTime.setHours(
  offsetLocalTime.getHours() - offsetLocalTime.getTimezoneOffset() / 60,
);

The trick is the getTimezoneoffset() function. But it's not a silver bullet because:

  • It only works with UTC or ISO dates. Remember, that UTC and ISO dates are "time keeping" standards NOT A FORMAT. Although, UTC and ISO are slightly different ways to track time, usually that's not a problem since the different between the two is a fraction of a second - which is only really significant if you're working in an ultra precise environment.
  • It "guesses" the time zone of the OS so if the user configured his TZ incorrectly, then the computation is also off.


Tuesday, January 21, 2025

Fix Losing your HD mounts on RaspberryPI with a Orico 9558u3

If you're anything like me, having a lot of old, mismatched 3.5" drives, you'd probably decide on getting a n USB enclosure like the Orico 9558u3, plug it into your RaspberryPI, edit your FSTAB to automount, then setup Samba to file share. 

Well, that works until the Orico 9558u3 decides to sleep to save power when there's no drive activity. It can't help itself BECAUSE it's a feature. Now you lose access to your mount drives. Now what?

Lucky, we're in linux and we can simply fake drive activity and set it on a schedule.

We simply run a cronjob every 5 minutes to "touch" the disk. Hehehe.

Open your CronTab:

$ sudo crontab -e

With your text editor (nano or vi), add the following line:

$ */5 * * * * /bin/touch /your/hdd/mnt/here &>/dev/null

Add more lines for each drive you want to keep awake.

Lastly, restart your crontab.

$ sudo systemctl restart cron
$ sudo systemctl status cron



Friday, November 29, 2024

Doing a git clone within a LAN without Internet

On the laptop where the repo to be clone is hosted, we run the command git daemon from the terminal.

Sample command on the HOST:

 $ git daemon --base-path=<path_to_folder_containing_project_folder> --export-all --verbose  

<path_to_folder_containing_project> is the folder containing your projects folders, it will provide all projects under that folder. You're basically looking for the project folder containing the .git folder.

The client:

 $ git clone git://<local ip>/<project name>  

It's that easy but do note that the cloned repo's origin will be pointing to the HOST IP, so you need to use git remote set-url origin to point it to a different IP or origin. 

We might want to run git daemon with the --verbose option to get more details in case we run into problems.

If we are getting connection problems, you might have to check Firewall settings to allow the connection.


Reference

* https://stackoverflow.com/questions/5200181/how-to-git-clone-a-repo-in-windows-from-other-pc-within-the-lan