Thursday, September 3, 2020

".ps1 is not digitally signed. The script will not execute on the system."

I am forced to use M$ Windåse at work, which is not my preferred OS. Most things annoys me about it and I do not understand most things when my Winbox complains. Latest complaint from my Winbox was

.ps1 is not digitally signed. The script will not execute on the system.

trying to install Grunt via Chocolatey. The solution is to bypass the signing requirement

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

<rant>So much for security.... My Winbox is attached to an AD with all the drawbacks and not really any advantages. Admin privileges only via external "security" program, so... we pretend it is safe, but... mostly just a nuisance... god I miss Linux or OSX.... Yes i do use WSL for most work, but dang... it's slow!!!!</rant>

As usual this tip is mostly for my own sanity, so I can find this again the next time Winbox complains. Solution courtesy of Caio Moreno.

Wednesday, January 22, 2020

Runnig multipe versions of PHP on Ubuntu

Running multiple versions of PHP on Ubuntu is fairly trivial since all supported version can be found in the main PPA for supported PHP versions. The repository can be added with

$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update

Look here1 for details. Then the relevant versions can then be installed

$ sudo apt install php7.4
$ sudo apt install php5.6

It is now possible to switch to the relevant version interactively with

$ sudo update-alternatives --config php

or alternatively directly with

$ sudo update-alternatives --set php /usr/bin/php5.6

This will change the version on the command line. Change version used by Apache with2

$ sudo a2dismod php7.4
$ sudo a2enmod php5.6
$ sudo systemctl restart apache2

Extensions

Most relevant extensions can be installed directly via apt. Fx.

$ sudo apt install php-ast

This will add the extension to all installed version of PHP the extension is supported for

Extensions via PECL3

Some extension is only available via PECL. PECL comes with the dev files for PHP, also available via apt

$ sudo apt install php7.4-dev

When using multiple versions of PHP, you need to set up the dev dependencies correctly, so extensions are installed correctly. php, phpize and php-config all need to be set to use the correct PHP version

$ sudo update-alternatives --config php
$ sudo update-alternatives --config phpize
$ sudo update-alternatives --config php-config

Extension installed via PECL is only installed for the current version of PHP. You need to manually add the extension to php.ini with (ast extension used as an example)

extension=ast.so

Manually installing extensions4

If you are compiling an extension yourself, you need to setup PHP the same way as when using PECL. After downloading the source code for the extension, build and install the extension with

$ cd extname 
$ phpize 
$ ./configure 
$ make

Remember to add the extension to php.ini

References

  1. https://launchpad.net/~ondrej/+archive/ubuntu/php
  2. https://opensenselabs.com/blog/tech/change-php-version-drupal-website-apache-nginx
  3. https://www.php.net/manual/en/install.pecl.pear.php
  4. https://www.php.net/manual/en/install.pecl.phpize.php

Tuesday, February 19, 2019

Replacing text using sed on OSX

Yet another reminder post for my self.

One again is bumped into the error message

sed: 1: "test.txt": undefined label 'est.txt'

when trying to replace text in a file using sed. When using sed on OSX to replace text in files, using -i, the BSD variant of sed on OSX requires an extension parameter, where a copy of the original file saved.

The syntax is as following

sed -i '.bak' 's/before/after' file.txt

If you are sure of what you are doing you can leave the extension parameter empty and not having a backup.

sed -i '' 's/before/after' file.txt

As a reference, here is the syntax for the GNU variant, ie. Ubuntu and friends

sed -i 's/before/after' file.txt

Tuesday, December 22, 2015

Screenshots in OSX

This is mostly for my own convenience, since I always forget the screenshot key combinations for doing the various kinds of screenshots you can do in OSX.

  • Command + Shift + 3 : Take screenshot of the whole screen
  • Command + Shift + 4 : Take screenshot of a part of the screen
  • Command + Shift + 4 : Press Space and select window to take screenshot of
The command for taking a screenshot of a window also works on open menus.

Appels official documentation: https://support.apple.com/en-us/HT201361

Make Alt + left/right work in iTerm2

I recently got a new harddrive, SSD!!!! So I made the decision to wipe the slate and did a clean install. But as always not every thing worked as before, as always. One of the most annoying things was that Alt + left arrow did not jump one word to the left and vide versa for Alt + right arrow. This is OSX default behaviour, on Linux it is Ctrl + arrow keys.

Anyway, to solve this you need to change what iTerm sends when you hit the key combination. Quickest way is to change set keys shortcuts for the default profile to "xterm Defaults"
Next you need to set the correct key bindings in your .inputrc, .bashrc etc. The file depends on how you set up your system. I cannot remember what file is standard on OSX, but i have my config stuff in a .bash_profile to avoid polluting the system more the needed. So i put the following two lines in my .bash_profile

bind '"\033[1;9D": backward-word'
bind '"\033[1;9C": forward-word'

Reload your config file or open a new terminal and I have Alt + arrow keys back working.

Have a look at http://superuser.com/questions/357355/how-can-i-get-controlleft-arrow-to-go-back-one-word-in-iterm2 also.