Ron and Ella Wiki Page

Extremely Serious

Page 31 of 34

RegEx Positive Look Ahead with Sublime

Positive look ahead with regex is another useful constraint that we can add to our expression. It only matches the left side, if and only if the look ahead matches. The look ahead doesn't consume any characters and has the following syntax:

<left side>(?=<look ahead>)

Example:

<?xml version="1.0"?>
<fruits>
 <a>apple</a>
 <b></b>
 <c>cashew</c>
 <d></d>
</fruits>

From the XML above find all the empty elements and add an attribute empty that is set to true but only matching the opening tag.

Find Replace Comment
<(?<tag>\w*[^>])>(?=</\k<tag>>) <$1 empty="true"> The <left side> is the one highlighted in blue.

The positive <look ahead> is the one highlighted in green.

Configuring User Level Proxy for Gradle

  1. Create gradle.properties files in the following directory if not yet existing:
     <USER_HOME>/.gradle
  2. Add the following entries for http proxy configuration in the gradle.properties file:
    systemProp.http.proxyHost=<PROXY_HOST>
    systemProp.http.proxyPort=<PROXY_PORT>
    systemProp.http.proxyUser=<PROXY_USERNAME>
    systemProp.http.proxyPassword=<PROXY_PASSWORD>
    systemProp.http.nonProxyHosts=<NON_PROXY_HOSTS>

    Note: <NON_PROXY_HOSTS> is delimited by pipe symbol (e.g. localhost|*.test.net)

    Note: If https proxy configuration is needed use the same entries except that all http will must be replaced with https (e.g. systemProp.https.proxyHost).

RegEx Named Groups with Sublime

Parentheses in regular expression (RegEx) can be used for grouping expression and can be named. To name it, after the opening parenthesis follows it with the following:

 ?<name>

Within the same expression you can backreference the group using the following:

\k<name>

On the replace field, based on the group position it will be numbered starting from 1 and increasing from the left of the expression and must be preceded with dollar sign (i.e. $). Use this number to access the captured match.

Note: if your group exceeds a single digit use ${<nn>} (e.g. ${10}) notation.

Example

<?xml version="1.0"?>
<fruits>
 <a>apple</a>
 <b></b>
 <c>cashew</c>
 <d></d>
</fruits>

From the XML above find all the empty elements and add an attribute empty that is set to true.

Find Replace Comment
<(?<tag>\w*[^>])></\k<tag>> <$1 empty="true"></$1> The named group (i.e. blue text) is assigned to $1.

The \k<tag> (i.e. green text) is the backreference.

RegEx Capturing Groups with Sublime

Parentheses in regular expression (RegEx) can be used for grouping expression.

Within the same expression you can backreference the group using the following:

\<GROUP_POSITION>

<GROUP_POSITION> is the quantitative location of the group from left to right starting from 1.

On the replace field, it follows the <GROUP_POSITION> but instead of using backslash (i.e. \) use dollar sign (i.e. $) to precedes it.

Note: if your group exceeds a single digit use ${<nn>} (e.g. ${10}) notation.

Example

<?xml version="1.0"?>
<fruits>
 <a>apple</a>
 <b></b>
 <c>cashew</c>
 <d></d>
</fruits>

From the XML above find all the empty elements and add an attribute empty that is set to true.

Find Replace Comment
<(\w*[^>])></\1> <$1 empty="true"></$1> The group (i.e. blue text) is assigned to $1.

The \1 (i.e. green text) is the backreference.

Git for Windows Credentials

The location for git for windows credentials can be found in the Credential Manager of windows. You can use this manager to add, remove or delete a git credential.

This can be accessed from the Control Panel then click the User Accounts. From there, click Credential Manager.

Control Panel -> User Accounts -> Credential Manager

Normally the credential manager looks like the following:

Downloading a GitHub Pull Request

  1. Open an open pull request on GitHub which normally has the following format:
  2. Open a terminal for running a git command (e.g. bash, cmd, powershell, etc...).
  3. Navigate to the location where your git forked repository was cloned.
  4. Download a copy of a pull request using the following command:
    git fetch upstream pull/<ID>/head:<NEW BRANCH>

    Where the variables can be describe as the following:

    <ID> This is the associated code attached to the pull request. Normally has the following format #<ID> (e.g. #123) or see the format from step 1.
    <NEW BRANCH> This is the unique desired branch name on your fork.
  5. Switch to the new branch and do what you want (e.g. code review, testing) using the following command:
    git checkout <NEW BRANCH>

Local Working Directory Ignore in Git

Ignoring files in git can be in the well known .gitignore file or in the .git/info/exclude file.

What's the difference between the two files?

File

Description

.gitignore

Operates at the repository level and everyone is sharing this file.

.git/info/exclude

Operates at the local working directory (i.e. normally the root of the cloned repository) level and only you has this file.

Exclude File

If .git/info/exclude file is present it must have the same formatting rule as the .gitignore file.

If the file to be ignored was already in the repository and you can still see it as modified. You can execute the following command:

git update-index --assume-unchanged <FILENAME>

Example:

git update-index --assume-unchanged config/database-config.xml

The reversal of this command is the following:

git update-index --no-assume-unchanged <FILENAME>

 

Securing Tinker Board SSH

  1. Require the sudoer to prompt for a password by updating the /etc/sudoers file with the following:
    Look for the following:

    %sudo ALL=(ALL) NOPASSWD: ALL

    And update to become the following:

    %sudo ALL=(ALL) ALL
  2. Update the /etc/ssh/sshd_config file to have the following added:
    PermitRootLogin no
  3. Install fail2ban using the following command:
    sudo apt-get install fail2ban
  4. Create the file /etc/fail2ban/jail.d/jail.ssh file to have the following:
    [ssh]
     enabled = true
     port = ssh
     filter = sshd
     logpath = /var/log/auth.log
     maxretry = 6
     bantime = -1
     banaction = iptables-allports
  5. Restart the service using the following command:
    sudo systemctl restart fail2ban

See Unbanning an IP

Using Putty SSH Key Pair

  1. Login to your account on the remote server.
  2. Create a file ~/.ssh/authorized_keys file and placed in the putty public key with the following format:
ssh-rsa <PUBLIC_KEY> <KEY_COMMENT>

Note: If you don’t have a public key generated you can follow the procedure from Generating Putty SSH Key Pair.

If the file already exists then append the public key on a new line with the same format specified earlier.

  1. If necessary update the permission of the authorized_keys file with the following command:
chmod 600 ~/.ssh/authorized_keys
  1. If necessary update the permission of the .ssh directory with the following command:
chmod 700 ~/.ssh
  1. Setup the Pageant (see Using Pageant to hold the Putty Private Key) to hold the private key (and passphrase).
  2. Run the Putty application.
  3. Fill-up Host Name (or IP Address) field with the following format:
<USERNAME>@<HOST_NAME_OR_IP_ADDRESS>

Where fields are defined as follows:

<USERNAME> is the account name used on step 1.

<HOST_NAME_OR_IP_ADDRESS> is the remote server used on step 1.

Example

user@someserver.com

user@192.168.1.200

  1. Click the Open button and expect to be connected to the remote server without it asking you to provide your password (or even your passphrase).

Using Pageant to hold the Putty Private Key

  1. Run the Pageant daemon that will listen to a putty SSH connection.
  2. Right click the Pageant icon from the taskbar that can be identified like the following:
  3. Select Add Key.
  4. Browse and select the target private key (i.e. ppk file).
    Note: If you don’t have a private key generated you can follow the procedure from Generating Putty SSH Key Pair.
  5. Supply the passphrase of the key if required.

Passing the Private Key upon running the Pageant Daemon

Every time at a pageant daemon was started the private key must be added. To simplify this, we can add the private key as a parameter on the target field of the shortcut of the pageant daemon like the following:

"<PAGEANT_EXECUTABLE>" "<PRIVATE_KEY>"

Example

Where the fields are defined as:

<PAGEANT_EXECUTABLE> is "C:\putty\bin\pageant.exe"<PRIVATE_KEY> is "C:\private-key.ppk"

Note: If the key has a passphrase it must be provided every time.

« Older posts Newer posts »