Mock http REST server for prototyping

TIL: install json-server to have a local http server serving JSON $ npm install -g json-server $ json-server --watch db.json https://www.npmjs.com/package/json-server

Fernando Costa Bertoldi

Monotonic clocks

A monotonic clock is a time source that won’t ever jump forward or backward (due to NTP or Daylight Savings Time updates). To measure durations, we must use monotonic clocks. C++: std::chrono::steady_clock C/POSIX: clock_gettime(CLOCK_MONOTONIC, &t); Java: System.nanoTime .NET: System.Diagnostics.Stopwatch Rust: std::time::Instant Ruby Process.clock_gettime(Process::CLOCK_MONOTONIC) Python: time.monotonic Perl: Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC) PHP: hrtime(true) Javascript: performance.now() https://stackoverflow.com/questions/3523442/difference-between-clock-realtime-and-clock-monotonic https://lobste.rs/s/uzjmam/mon_stupid_simple_monitoring#c_m6je8w

Fernando Costa Bertoldi

Programatically change the programs associated with a file extension in Windows

https://ss64.com/nt/ftype.html https://ss64.com/nt/assoc.html https://www.emacswiki.org/emacs/WThirtyTwoFileAssociations To use the emacs client as the editor associated with certain file extension, use the ftype and assoc commands. Run the followin as admin: ftype Emacs.org=<emacs-path>\emacsclientw -na runemacs "%1" ftype Emacs.el=<emacs-path>\emacsclientw -na runemacs "%1" rem ftype txtfile=<emacs-path>\emacsclientw -na runemacs "%1" assoc .txt=txtfile assoc .org=Emacs.org assoc .el=Emacs.el To add the option to open a file with emacs, edit the following registry file, substituting the .el extension with one you want to open with Emacs, and import in regedit:...

Fernando Costa Bertoldi

Read metadata (EXIF) from pictures with exiftool

https://exiftool.org/

Fernando Costa Bertoldi

Remove file from Git history

https://stackoverflow.com/a/64563565/2634595 https://github.com/newren/git-filter-repo Use the third-party add-on git-filter-repo # 1. fresh clone of the repo. Make sure you have a backup clone somewhere else in case something goes wrong. $ mkdir tmpdir && cd tmpdir && git clone <repo> # 2. make sure remote origin is configured in .git/config # 3. multiple paths can be specified by using multiple --path parameters $ git filter-repo --invert-paths --path <path to the file or directory> # 4....

Fernando Costa Bertoldi

Run commands on startup on Windows

To run a command for all users on startup, add a shortcut to the shell:common startup folder C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup To run for your specific user on startup, add it to the shell:startup folder F:\Users\<user>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup To open one the above folders, type the shell command (either shell:startup or shell:common startup) in the Run prompt (Win+R) or in the Windows Explorer address bar (Win+E) SysInternals’ Autoruns lists all auto-starting programs

Fernando Costa Bertoldi

Run emacs server in Windows

We can also run the emacs server as a daemon on user init in Windows. We take advantage of the user startup folder, where you can put a batch script or shortcut which will be executed on user login. Go to the Roaming startup folder by either opening Run Command (Win+R) and typing shell:startup, or opening the Windows Explorer (Win+E) and typing shell:startup in the address bar Create a shortcup by right-clicking, new->shortcut....

Fernando Costa Bertoldi

sh: regexp match

TIL: to regexp match a string and use it as a condition, pipe it to grep -Eq $ protoc --version | cut -d' ' -f2 | grep -Eq ${PROTOC_VERSION} || { echo 'Incompatible protoc version'; exit 1; }

Fernando Costa Bertoldi

Transmission and .torrent files

The Transmission BitTorrent client saves the .torrent files of active torrents in $HOME/.config/transmission/torrents folder Use the transmission-show tool from the transmission-cli package to show .torrent file metadata

Fernando Costa Bertoldi

Turn off annoying alarm sounds on Windows

https://www.digitalcitizen.life/when-each-sound-windows-sound-scheme-played/ Actual path in the above article is wrong, see where to go below. Windows by default plays annoying sounds when something fails in a program, e.g. when the search in Firefox or other programs finds zero occurrences, or in any editor, just trying to move the cursor past the end of the file. To turn off these sounds: go to Control Panel->Hardware and Sounds->Alter System Sounds change the sound file to (None) for the following events: Windows/Asterisk Windows/Default Beep Windows/Exclamation...

Fernando Costa Bertoldi