Thursday, July 26, 2018

macOS: checking for OpenSSL... configure: error: not found

Source: Problem with openssl on macOS
If your ./configure (e.g. for pgbouncer) terminates with the following error despite openssl being installed:
checking for OpenSSL... configure: error: not found
Then, restart it like follows:
./configure --with-openssl=/usr/local/opt/openssl

macOS: listening ports

Source: How can I list my open network ports with netstat?
[jerome@jeroboam] > sudo lsof -PiTCP -sTCP:LISTEN | grep 6432
pgbouncer 10533 jerome    9u  IPv6 0x8678a9be8d9262f5      0t0  TCP *:6432 (LISTEN)
pgbouncer 10533 jerome   10u  IPv4 0x8678a9be9e2f23dd      0t0  TCP *:6432 (LISTEN)

Wednesday, July 25, 2018

ssh: ssh a remote host via a bastion

Source: SSH ProxyCommand example: Going through one host to reach another server

In order to reach remote1 through a bastion host, add the following lines in your .ssh/config:
Host bastion
HostName bastion-01.golgoth.com
User jgallinari

Host remote1
HostName remote1.toto.swir
User jgallinari
ProxyCommand ssh jgallinari@bastion -W %h:%p
Then ssh remote1 should do it.

Friday, July 20, 2018

macOS: find your CPU

[jerome@jeroboam] > sysctl -n machdep.cpu.brand_string
Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz

Thursday, July 19, 2018

AWS: Using environment variables in CodeBuild buildspec

Source: Using environment variables in AWS CodeBuild buildspec.yml
See S3_BUCKET below, which is first expanded from ImportValue, then used in BuildSpec.
  AvUsageQuarantineBuildProject:
    Type: AWS::CodeBuild::Project
    Condition: Preprod
    Properties:
      Name: av-usage-quarantine-build
      ServiceRole: !GetAtt AvUsageQuarantineBuildProjectRole.Arn
      Artifacts:
        Type: CODEPIPELINE
        Name: av-usage-quarantine
      Environment:
        Type: LINUX_CONTAINER
        ComputeType: BUILD_GENERAL1_SMALL
        Image: aws/codebuild/java:openjdk-8
        EnvironmentVariables:
          - Name: S3_BUCKET
            Value: !ImportValue delivery-AvDeliveryUtilsBucket
      Source:
        Type: CODEPIPELINE
        BuildSpec: !Sub |
          version: 0.2
          phases:
            install:
              commands:
                - cd ~; wget https://raw.github.com/technomancy/leiningen/stable/bin/lein; chmod +x lein; mv lein /bin
                - LEIN_ROOT=true lein
            build:
              commands:
                - cd $CODEBUILD_SRC_DIR
                - LEIN_ROOT=true lein uberjar
            post_build:
              commands:
                - aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --s3-prefix lambda --output-template av-usage-quarantine-output-template.yaml

macOS: Terminal follow focus

Source: Set Terminal Focus to Follow the Mouse Cursor in Mac OS X
Follow focus ON
defaults write com.apple.Terminal FocusFollowsMouse -string YES
Follow focus OFF
defaults write com.apple.Terminal FocusFollowsMouse -string NO
Then, restart Terminal.

Working on High Sierra 10.13.6.

Clojure: transducers from the ground up

Clojure transducers from the ground up: the practice

AWS: !Sub |


Q: What does !Sub | mean ?
A: This means that you can enter normal looking text without having to use things like "\n" to mean end of line.

AWS: 7 Awesome CloudFormation Hacks

Source: 7 Awesome CloudFormation Hacks

Tuesday, July 17, 2018

Clojure: count truthy occurences

Count truthy occurences
(count (filter identity [nil 1 nil 4 nil]))
2
Count falsey occurences
(count (filter #(or (false? %) (nil? %)) [nil 1 false 4 nil]))
3

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