Saturday, July 14, 2018

macOS: know the previous shutdowns cause

centurion:~ jerome$ log show --predicate 'eventMessage contains "Previous shutdown cause"' --last 24h

Filtering the log data using "eventMessage CONTAINS "Previous shutdown cause""
Skipping info and debug messages, pass --info and/or --debug to include.
Timestamp                       Thread     Type        Activity             PID    TTL  
2018-07-14 11:14:28.111106+0200 0xe5       Default     0x0                  0      0    kernel: (AppleSMC) Previous shutdown cause: 5
2018-07-14 11:32:41.196172+0200 0xe3       Default     0x0                  0      0    kernel: (AppleSMC) Previous shutdown cause: 5
 --------------------------------------------------------------------------------------------------------------------
Log      - Default:          2, Info:                0, Debug:             0, Error:          0, Fault:          0
Activity - Create:           0, Transition:          0, Actions:           0

Tuesday, July 10, 2018

macOS: release C-left, C-right, C-up, C-top for Emacs

On Emacs, I use key bindings for ^↑ (C-up), ^↓ (C-down), ^← (C-left) and ^→ (C-right), but macOS by default maps them to Mission Control. In order to replace ^ with ⌘ for Mission Control shortcuts, use System Preferences > Keyboard > Shortcuts like in

macOS: install Apache2::Request mod_perl module

Sources:
Trying to install Apache2::Request on macOS from CPAN will cause multiple errors.
cpan Apache2::Request
First, we will need apxs (Apache Extension tool).
For this, install httpd from homebrew.
brew install httpd
Then, we will need Xcode.
So, install it from the Apple Store.

Then, Apache2::Request install will try to have access to multiple Xcode directories that do not exist.
So, create symbolic links and missing directory.
sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/ /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.13.xctoolchain

sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.13.xctoolchain/usr/local/bin/

sudo ln -s /usr/local/bin/apxs /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.13.xctoolchain/usr/local/bin/apsx

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk
Then install libapreq2 library.
  1. Download libapreq2-2.13. 
  2. Compile libapreq2 sources.
tar xvfz libapreq2-2.13.tar.gz
cd libapreq2-2.13
./configure
make
make install
Then install mod_perl 2.

svn checkout https://svn.apache.org/repos/asf/perl/modperl/trunk/ mod_perl-2.0
cd mod_perl-2.0
perl Makefile.PL MP_CCOPTS=-std=gnu89
make
make install
NB: mod_perl.so and mod_apreq2.so will be installed in /usr/local/lib/httpd/modules.

Then update Apache configuration.
vi /usr/local/etc/httpd/httpd.conf
LoadModule perl_module lib/httpd/modules/mod_perl.so
LoadModule apreq_module lib/httpd/modules/mod_apreq2.so
...
ServerName jeroboam:8080
...
PerlSwitches -I /Users/jerome/perl5/lib/perl5
PerlModule Apache::DBI
PerlModule ModPerl::Registry
PerlRequire /Users/jerome/src/connectmv/perl/lib/startup.pl
<Location /hlr_vas/>
    SetHandler perl-script
    PerlResponseHandler MBQT::mod_perl::HlrVas
</Location>

# PerlSetEnv DBG_FLG 1
Apache restart
/usr/local/bin/apachectl restart

Friday, July 6, 2018

macOS: iconify / deiconify shortcuts

  • Iconify: ⌘+M
  • Deiconify: ⌘+TAB, then select application, then press ⌥, then, release ⌘

macOS: paste without style

Instead of using ⌘+V , you can press ⌥+⇧+⌘+V to paste text without any formatting.

Thursday, July 5, 2018

macOS: triple click to select path in Terminal

Source: Is there a UNIX-style triple click to select path in Terminal.app?
The shortcut for Terminal.app is ⌘+⇧+doubleclick.

macOS: install postgreSQL 9.4

brew install postgresql@9.4 --with-python
brew link postgresql@9.4 --force

macOS: install sshpass

brew install http://git.io/sshpass.rb

macOS: Fixing HOME and END keys

Source: Fixing HOME and END keys, and more, on macOS
mkdir -p $HOME/Library/KeyBindings
echo '{
/* Remap Home / End keys to be correct */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */
}' > $HOME/Library/KeyBindings/DefaultKeyBinding.dict

Wednesday, July 4, 2018

Virtualbox: Connect to the host machine from a VirtualBox guest OS

Source: Connect to the host machine from a VirtualBox guest OS
See "Another way to do this is to use a "Host" type of virtual network."

The simplest to always get the same IP address @home and @office for your VM is to use the Host-only adapter.

git: use p4merge on macOS

Source: Customizing Git, section External Merge and Diff Tools.

macOS: -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

Source: nixCraft
Option #1 : Terminal > Preferences > Profiles
However, this may cause some issues with e.g. PostgreSQL psql displaying unicode characters, e.g. <e2><94><8c><e2><94><80>.
So, if the issue is only caused by ssh, I prefer option #2:
sudo vi /etc/ssh/ssh_config
#       SendEnv LANG LC_*

macOS: size of email data

Spark Email
Outlook 2016
Mail

Monday, July 2, 2018

byobu: Function keys in Macos terminal

In order to have F2 or F8 work as expected for byobu in Macos terminal, you need to configure it as xterm-256 :
Terminal | Preferences

Wednesday, June 27, 2018

Wednesday, June 20, 2018

Git: The art of rebase

Source: Always Squash and Rebase your Git Commits
[Edit]: Squash the Last X Commits Using Git

Clojure: create a Clojure docker

Use case: I need to run some Clojure tests that use a library depending on glibc 2.14.
Unfortunately, I use CentOS 6.9 that relies on glibc 2.12, that cannot be updated.
Solution: Use a Docker file to run the Clojure tests.

Source: https://store.docker.com/images/clojure
docker pull clojure
  • Dockerfile
  • FROM clojure
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    COPY project.clj /usr/src/app/
    RUN lein deps
    COPY . /usr/src/app
    RUN lein uberjar
    CMD ["lein", "test"]
  • docker.build.sh
  • set -x
    cd ~/av-usage
    cp ~/tmp/clojure/docker/Dockerfile Dockerfile.test
    docker build -f Dockerfile.test -t av-usage-test .
    rm Dockerfile.test
  • docker.run.sh
  • set -x
    docker run -it --rm --name my-av-usage-test av-usage-test

Git: Reset local branch to remote HEAD

Source: Reset local repository branch to be just like remote repository HEAD
git fetch origin
git reset --hard origin/master

Thursday, June 14, 2018

yum: installed package

yum list installed | grep glibc