Accelerator key for a date stamp - version-control

Here's an open ended question. I work on a lot of mssql files, and I like to have a date stamp on each. This is so I can know just by looking at the source of a stored procedure whether it's up to date or not.
I'd like to have a shortcut autocomplete key, that, if i type say, d-tab-tab, I get the current date printed to the file. And yes, I am that lazy. :)
So the question is:
Is there any way of getting around this problem entirely?
If not, how would you suggest solving it?
Clever ideas welcome.

Are these files in source control? If so, see whether your source control provider allows templates within the source file which get filled in with the time and date when you check in.

If you use Notepad (and this is possibly the only argument for using it) then F5 does the trick.

What about using version control for your files and including automatic keyword expansion.
Using CVS Keyword Expansion you could put $Date: $ in the file and it will get replaced with the date of the last checkin. No typing or updating needed, it's "auto-magic".

Related

How to replace value in txt file with powershell from GitHub

I want to build a simple script that may be useful for others as well, but I have only very basic programming knowledge and can't do it myself without learning how to write powershell scripts from scratch.
What this script is supposed to do is, open an INI file (really just a txt), look for a variable with an assigned value and replace that value from a txt hosted on GitHub, save and then run a program.
This is for the tracker list of qBittorrent, since that feature still hasn't been implemented and the only other script that I could find that does this is for linux and mac, there seem to be none for windows.
The basic idea is this:
get-content "c:\users\[user]\appdata\roaming\qbittorrent\qbittorrent.ini"
# This is where pseudo code starts
get file from "[github-link.txt]"
save file to cache # keeping it is useless as it gets updated daily
find variable "Session\AdditionalTrackers=" in qbittorrent.ini
replace value of variable with content of cached file # this is what I struggle with most when looking for example code. Everything I could find specified the exact string that needed replacing, which in this case is quite long and may change with every update of the file.
overwrite original file
launch program qbittorrent.exe
end script
Conveniently or most likely deliberately all (most) of the tracker lists on GitHub are already formatted in a way that they can be directly pasted into the file without having to worry about formatting. Example.
I can totally understand if nobody wants to do the work, but I would greatly appreciate it and possibly others that are looking for a stopgap for the lacking feature.
If this already exists, go ahead and call me an idiot and while you're at it drop a link ;)
I just found a little tool called Power Automate and it pretty much does what I was looking for. It's not quite as elegant as a single click script but it does the job. Sadly I can't share the "flow" I built because, well, there is no option for it - thanks Microsoft. So, I'll try my best to write it out.
Not quite a "solution" but pretty to close to it.
Here is the "flow":
get file from web // from github for example
read text from file // read downloaded .txt file
read text from file // read qBittorrent.ini
crop text // crop between flags in qBittorrent.ini use "Session\AdditionalTrackers=" as start and "Session\GlobalMaxRatio=" as end and save to cropVar2
crop text // crop before flag use "Session\AdditionalTrackers=" as flag and save to cropVar1
crop text // crop after flag use cropVar2 as flag and save to cropVar3
replace text // replace cropVar2 with content of downloaded file and save to cropVar2
write text to file // write cropVar1,cropVar2,cropVar3
end flow
Keep in mind that any changes to the qBittorrent.ini may change the order of the entries. Which means you have to check if it's still correct after every update and after every change you make in the options. This is a massive cludge after all...
You can input fail saves so that you won't break anything if the order changed.

Bulk change date to present date with ExifTool

I have a bunch of images with different create dates. I want to normalize them all to a given date (say today's date) using a batch file (Windows). Can ExifTool set dates? I only see documentation and examples for shifting dates. To shift the date to present, I would need to somehow read the date for each file, calculate the difference, and then shift. That would be ok, but I don't know how to read the create date into a variable using ExifTool.
One obstacle for me is that I don't speak Perl. I do Python, and there is pyexiv2. This allows to write the "date", but I can't see anywhere if that is just create date or all dates.
Edit
Here shows using, for example,
exiftool -AllDates='2010:08:08 15:35:33' -overwrite_original IMG_01.jpg
in Ubuntu linux, but I could not get that to work in Windows.
As a hack, I tried
exiftool -AllDates+=2015:03:02 IMG_8220.JPG
which set the dates to the time executed, probably because the shift was so completely crazy. But I'd like to have control, and, specifically be able to change YYYY:MM:DD without changing the time.
Consequently, help still appreciated.
I crossposted to the ExifTool forum, and ExifTool author Phil Harvey responded that you need to use double quotes. The single quotes from the linked blog post don't do it in Windows.
So, one would use
exiftool -AllDates="2010:08:08 15:35:33" IMG_01.jpg
I tested it and (of course) it worked.

NSIS SetDateSave not preserving the creation/modified date of files installed in .nsi file

I am using the SetDateSave function in several places in my .nsi file
However once the installer is run the all files date modified/created field is updated to the current time.
Any ideas?? I know that commands in .nsi files will only effect every line below the command. I am guessing that there is some other command further down that is overriding the SetDateSave, but I need a second opinion please!
Update:
I think the nsisunz it the culprit! Testing ZipDLL instead. Will update answer here if I solve it!
It was the zip format that was resetting the date modified field!
Simply used ZipDLL instead of nsisunzip!
Hope this helps someone in the future :)

Validate against an Eclipse formatting profile from command line

I'm looking for a way to verify Java code against an Eclipse code formatting profile from the command line. The goal is to create a Mercurial hook which rejects any commit that doesn't match the profile. Is there a way to do this?
I'm aware of the possibility to call Eclipse's formatter from the command line. What I'm looking for is something which just validates (yes/no). I guess I could use the formatter and then compare the two, but it seems like a clumsy approach.
Background: The reason we want to try this is because we currently get many unnecessary merge conflicts because of formatting differences. We have an environment where multiple IDE:s are used, although only one is officially supported. We want to enforce the official profile, and everyone can continue using the tools they prefer as long as they set it up to format the code correctly.
In brief, follow those steps:
Duplicate the original Java file in a temporary place ;
Format the temporary duplicate using the Eclipse Java code formatter ;
Check whether the files are identical or not.
Tricks to help you out:
To call the Eclipse Java code formatter from command line, see Formatting your code using the Eclipse code formatter.
To know whether files are identical, using the diff utility: diff --text --quiet >/dev/null, the error code will tell you what you're seeking for.

Emacs: Is there a way to generate a skeleton ChangeLog from diff?

I'd like to partly automate creation of GNU-style ChangeLog entries when working with source code in version control. The add-changelog-entry-other-window works with one file at a time and you have to visit the file to use it.
What I'd like to see instead is to have some command that would take an output of diff -u -p (or have integration with VC modes so it could process svn diff etc) and to create all the skeleton entries at once.
For example, if svn status shows
D file1.c
M file2.c
A file3.c
the command would create
2009-09-05 My Name <my.email>
* file1.c: Removed.
* file2.c: WRITE YOUR CHANGES HERE
* file3.c: New.
Better yet, if it could parse the changed files in some languages to an extent so it could offer:
* file2.c (new_function): New function.
(deleted_function): Removed.
(changed_function): WRITE YOUR CHANGES HERE
I have found this feature in Emacs manual, but I don't see how I could apply it here.
Any suggestions? Thanks.
EDIT: One answer suggested vc-update-change-log. Unfortunately it only supports CVS and it creates ChangeLog entries by querying the already-commited VC logs. Thus even if it supported svn and others, it would be impossible to commit the changes and the ChangeLog in the same commit.
EDIT2: Apparently add-changelog-entry-other-window (C-x 4 a) works not only from visited file but from diff hunk involving that file too. (Source) This is almost what I am looking for. This together with elisp loop to iterate through all hunks should solve it.
There is a function vc-update-change-log that automatically generates change log entries from the version control log entries.
diff-add-change-log-entries-other-window is documented to do exactly what you mentioned in EDIT2:
diff-add-change-log-entries-other-window is an interactive compiled
Lisp function in `diff-mode.el'.
(diff-add-change-log-entries-other-window)
Iterate through the current diff and create ChangeLog entries.
I.e. like `add-change-log-entry-other-window' but applied to all hunks.
Unfortunately, it doesn't work very well for, say, new files: it doesn't even include the filenames of such files in the skeletal changelog entry.
You might have better luck with gcc's mklog script, which you can get from http://gcc.gnu.org/viewcvs/gcc/trunk/contrib/mklog.
I don't know of a function that does this, but it should be easy to implement. Basically, you want to
get the changed files
for each file, call add-change-log
"Find change log file, and add an entry for today and an item for this file.
Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
name and email (stored in `add-log-full-name' and `add-log-mailing-address').
Second arg FILE-NAME is file name of the change log.
If nil, use the value of `change-log-default-name'.
Third arg OTHER-WINDOW non-nil means visit in other window.
Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
never append to an existing entry. Option `add-log-keep-changes-together'
otherwise affects whether a new entry is created.
Option `add-log-always-start-new-record' non-nil means always create a
new record, even when the last record was made on the same date and by
the same person.
The change log file can start with a copyright notice and a copying
permission notice. The first blank line indicates the end of these
notices.
Today's date is calculated according to `add-log-time-zone-rule' if
non-nil, otherwise in local time."
so the magic code is going to look something like
(apply 'make-magic-change-log-entry changed-files-list)
and make-magic-change-log-entry simply curries the add-change-log function so that the only argument is file-name — you set the other ones.
I've written a function to do something similar to what you were talking about. You can get the code at http://www.emacswiki.org/emacs/log-edit-fill