Margie's Tech Blog

Mostly Linux & Python syntax notes and hyperlinks.

Wednesday, September 25, 2024

Windows Batch Script Time Stamp - beware the morning space

I had been creating a time stamp just to give my output unique file names so as not to overwrite previous test output.

I'd been doing this:

REM TT= time tag for this run
set T=%time%
set TT=%T:~0,2%%T:~3,2%%T:~6,2%

It works fine after 10 am:

C:\Users\mharrison>set TT=%T:~0,2%%T:~3,2%%T:~6,2%
C:\Users\mharrison>echo %TT%
100359
C:\Users\mharrison>echo filename%TT%
filename100359

I've been using this time stamp method for weeks, but apparently never before 10 am. It broke my code this morning. Before 10am, the plain old time inserts a space:

C:\Users\mharrison>echo %time%
 9:56:08.38

So when I try to append it to make a unique file name, I insert a space in the file name, which confuses the code:

C:\Users\mharrison>set TT=%T:~0,2%%T:~3,2%%T:~6,2%
C:\Users\mharrison>echo %TT%
 95740
C:\Users\mharrison>echo filename%TT%
filename 95740

So I changed the method to only use the 2nd digit of the hour:

REM TT= time tag for this run
set T=%time%
set TT=%T:~1,1%%T:~3,2%%T:~6,2%


Testing in the Command Prompt window after 10am: 
C:\Users\mharrison>set T=%time%
C:\Users\mharrison>echo %T%
10:11:54.96 
C:\Users\mharrison>set TT=%T:~1,1%%T:~3,2%%T:~6,2%%T:~1,1%%T:~3,2%%T:~6,2%
C:\Users\mharrison>echo %TT%
0115401154
C:\Users\mharrison>echo filename%TT%
filename0115401154 

 

Wednesday, July 26, 2023

Xms size must be multiple of 1024

 from java (oracle.com) and java (oracle.com):

-Xmssize

Sets the minimum and the initial size (in bytes) of the heap. This value must be a multiple of 1024 and greater than 1 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes.

The following examples show how to set the size of allocated memory to 6 MB using various units:

-Xms6291456
-Xms6144k
-Xms6m

Also for 

Friday, April 28, 2023

Compressed Windows C-drive and LTS Ubuntu

I compressed my PC's Windows 10 C drive after spending a very long time trying to figure out how to get it out of the "red". Unfortunately, the next time I started up LTS Ubuntu, it complained about the virtual disk being compressed and would not start up.

I followed other web advice to look under C:\users\[me]\AppData\Local\Packages

There I found something named CanonicalGroupLimited.Ubuntu20.04onWindows_79rblahblah ..

After I decompressed that package LTS Ubuntu worked again.

Wednesday, March 22, 2023

python len() for record offsets

 From a colleague:

In case you ever have to do an f.seek():

When calculating record offsets, python only does a consistent and correct len() value if your file is opened in binary.


Friday, March 3, 2023

Performance illusion from using repetitive test data

We often copy a few fake records to create a large input file with which to test how the code handles it.

It's a useful test; but don't use it to gauge performance. 

Data from repeated records can be cached and reused. If your production data will vary, then it won't get the same use out of caching. Caching could even hurt performance.

Wednesday, July 8, 2020

Windows batch script - decimal points and comma separators

Adding a decimal place to express ms as seconds:


C] echo %ms:~0,-2%.%ms:~-2,2%
123.45

C] echo %m2:~0,-2%.%m2:~-2,2%
12.34

C] set m1=123

C] echo %m1:~0,-2%.%m1:~-2,2%
1.23

C] set m0=23

C] echo %m0:~0,-2%.%m0:~-2,2%
.23

C] set m=2

C] echo %m:~0,-2%.%m:~-2,2%
.2

C] set m=02

C] echo %m:~0,-2%.%m:~-2,2%
.02

To insert commas, not so simple:

C]  set m=123456789

C]  echo %m%
123456789

C] echo %m:~-3,3%
789

C] echo %m:~-6,3%,%m:~-3,3%
456,789

C]  echo %m:~-9,3%,%m:~-6,3%,%m:~-3,3%
123,456,789

C]  echo %m:~-12,3%,%m:~-9,3%,%m:~-6,3%,%m:~-3,3%
123,123,456,789


More complex solutions at https://stackoverflow.com/questions/28700043/thousands-separator-of-an-integer-value


C]  echo %m%
123456789

C]  if %m% GTR 99999999 (set c=%m:~-9,3%,%m:~-6,3%,%m:~-3,3%)C]  echo %c%
123,456,789

C]  set n=12345

C]  if %n%  GTR 99999999 (set c=%n:~-9,3%,%n:~-6,3%,%n:~-3,3%) else ( if %n% GTR 9999 (set c=%n:~-6,3%,%n:~-3,3%) )

C]  echo %c%
123,345       WRONG!!

Wednesday, March 18, 2020

Using RegExp in Notepad++ to convert all RollingFileAppender to DailyRollingFileAppender in a log4j.properties file

1) Change RollingFileAppender to DailyRollingFileAppender

Search for

log4j.RollingFileAppender

Replace with

log4j.DailyRollingFileAppender


2) To comment out the MaxFileSize line:

Search for

log4j\.appender\.[a-zA-Z]+\.MaxFileSize

Replace with

#$&

This works because $& matches the entire expression matched.
(Commenting out instead of deleting in case you want to go back to Rolling.)

3) To comment out the MaxBackupIndex line:

Search for

log4j\.appender\.[a-zA-Z]+\.MaxBackupIndex

Replace with

#$&


4) To insert the DatePattern='.'yyyy-MM-dd line just before existing log4j.appender.SOMETHING.layout= line:

Search for

(log4j\.appender\.[a-zA-Z]+\.)layout=

Replace with

${1}DatePattern='.'yyyy-MM-dd\n$&

This works because:
The parentheses marking from "log4j" to just before "layout" marks out the part returned by ${1}
Then the "\n" adds a newline
Then the $& restores the beginning of the layout= line.

 

-->

Tuesday, October 15, 2019

TrackMyUniverse


I’ve lately been looking at GitHub and listening to python podcasts trying to think of a python project to do. I remembered a Prolog project I wrote for a class I was taking at Harvard Extension back in the ‘80s. Prolog has a built-in inference engine, so I wrote a story chronology tool. E.g. if event A happens before event C and B before A then B was before C.

For decades, now, I’ve been writing bits of stories that all take place in the same space fantasy universe.
I have boxes and Google docs folders full of drafts.
There are some sort of finished parts: A few TV mini-series scripts, a full-length screenplay, a novella, and a novel that once could be read as finished until, under the influence of its 3rd or 4th writing group, I tore it apart and never pieced it back together again.

Whenever I return to writing about my universe I need to find the correct draft and update there.

Sometimes, I’d like to be able to open my computer and just start typing.

Maybe I could write a python tool for this.
It could use a noSQL database- since it would be literally collections of documents.
One point of access would be a character list.
Another would be places: each event or story fragment occurs at a particular place.
Events are characterized by characters and places.
Places and characters have event histories.
Characters are connected by family relationships from which obvious chronologies can be inferred. No significant time travel, so events when parents are young can be inferred to occur before events when their children are adults, etc.
Characters are also connected by time spent together- in the same place or in the same spaceship.

I’d also like to tie in version control for saving multitudinous versions of paragraphs, chapters, scenes, lines of dialogue, whatever.

Eventually, one could walk into this universe and look around.

Friday, August 9, 2019

Windows - using %CD% for current directory and levels

For windows scripting, you can access levels above %CD%. Just remember to use backslash, not forward slash:

C:\Users\mharrison>echo %CD%
C:\Users\mharrison
C:\Users\mharrison>dir %CD%\..\..
 Volume in drive C is Windows
 Volume Serial Number is E431-FA9F
 Directory of C:\
03/03/2017  11:02 AM    <DIR>          DRIVERS
04/11/2018  07:38 PM    <DIR>          PerfLogs
05/31/2019  02:25 PM    <DIR>          Program Files
05/15/2019  09:04 AM    <DIR>          Program Files (x86)
03/25/2019  05:33 PM    <DIR>          test
05/13/2019  10:56 AM    <DIR>          Tools
04/09/2019  09:21 AM    <DIR>          Users
08/08/2019  06:02 PM    <DIR>          Windows
               0 File(s)              0 bytes
               8 Dir(s)  61,991,501,824 bytes free

C:\Users\mharrison>dir %CD%/..
Invalid switch - "..".

Also, check out this great tool for formatting code for blogging on blogger:
http://formatmysourcecode.blogspot.com/

Thursday, April 12, 2018

Centos Firstboot - No Way Out

So I continued following the advice in CentOS 6 Linux Server Cookbook.
I installed firstboot.
    yum -y install firstboot
    chkconfig firstboot on
One is supposed to be able to navigate using arrow keys.
That worked until this screen:
But suddenly, the tab keys worked! Now I can leave.
Never mind.