Go Does Not Have Reference Variables

To be clear, Go does not have reference variables, so Go does not have pass-by-reference function call semantics. Dave Cheney

What is a reference variable?

In languages like C++ you can declare an alias, or an alternate name to an existing variable. This is called a reference variable.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>

int main() {
  // integer type
  int a = 10;
  // reference type; type annotation: "int &"
  // means "reference to an integer variable" type
  int &b = a;
  int &c = b;

  // 10 10 10
  printf("%d %d %d\n", a, b, c);
  // reference variables share the same memory address
  // with the variable which they refer to;
  // 0x7ffeea4654f8 0x7ffeea4654f8 0x7ffeea4654f8
  printf("%p %p %p\n", &a, &b, &c); // here, & is "address of" operator

  // pointer type; type annotation: "int *"
  // means "pointer to an integer variable" type
  int *p1 = &a;
  int *p2 = &a;
  int *p3 = &a;

  // here, * is "deferencing"(or "content of") operator
  // 10 10 10
  printf("%d %d %d\n", *p1, *p2, *p3);

  // pointer variables have their own memory address
  // 0x7ffee82644e0 0x7ffee82644d8 0x7ffee82644d0
  printf("%p %p %p\n", &p1, &p2, &p3);

  return 0;
}

You can see that a, b, and c all refer to the same memory location. A write to a will alter the contents of b and c. This is useful when you want to declare reference variables in different scopes–namely function calls.

How to Assume IAM Role in AWS and Use It

AWS IAM Assume Role is a mechanism that enables a user or service to assume a specific IAM role temporarily. This allows the user or service to acquire temporary security credentials, including access keys, session tokens, and permissions, to perform actions within AWS resources. The assumed role can have different permissions and policies than the original user or service, ensuring a granular level of access control and reducing the need for sharing long-term credentials.

How to Configure Remote SSH Connection to WSL 2

There may be a case where you want to use WSL(Windows Subsystem for Linux) via a remote SSH connection.

Configuring a remote SSH connection to WSL is not necessarily straightforward because:

  • You need to configure port forwarding from WSL to the host machine
  • WSL does not have systemd, so you need to configure automatic booting of WSL and then SSH server inside it(because you will want to automate everything).

Well, let’s take a look at the configuration process step by step.

Vim Notes

There are several modes in VIM. NORMAL, INSERT, VISUAL are most common ones.

The Most Used Default Key Bindings

  • :q: quit VIM. :wq: save the current buffer and quit. :q! discard unsaved changes and quit
  • h, j, k, l: Movement. Example: 8k - move 8 lines up
  • :99: jump to the line 99
  • w: move one word forward
  • b: move one word backward
  • $: move to the end of the current line
  • 0: move to the beginning of the current line
  • o: insert a new line below and go insert mode
  • O: insert a new line above and go insert mode
  • A: go insert mode at the end of the current line
  • y: yank (copy) selected text
  • p: paste the yanked text
  • d: delete the selected text
  • dd: delete the current line
  • x: delete the cursor character
  • v: select the cursor character
  • V: select the current line
  • :sp: split the screen horizontally
  • :vs: split the screen vertically
  • /john: search for “john” in the current file buffer
  • n: jump to the next search result
  • N: jump to the previous search result
  • gg: jump to the top of the current file
  • G: jump to the bottom of the current file
  • %: jump to the closing/opening pair bracket
  • :%s/abc/xyz/g: replace every “abc” with “xyz” in the current file
  • :vimgrep: search current directory, see the help for more info
  • :help: open VIM help

Vim “leader” Key

<leader> key is a vim tool that can be used to create personalized shortcuts.

How to Use Multiple Github Accounts With SSH Keys on the Same Machine

There might be a chance that you need to create and use a separate github(or bitbucket) account other than your personal one in your workplace. And Github(Bitbucket or Gitlab will do the same I believe) doesn’t allow to share a ssh key between different accounts for authentication.

That’s the case we are going to figure out below.

First of all, create a new ssh key pair on your machine.

1
2
3
ssh-keygen -t ed25519 -C "[email protected]"
# Note: If you are using a legacy system that doesn't support the Ed25519 algorithm, use:
ssh-keygen -t rsa -b 4096 -C "[email protected]"

Next, edit/create the ssh config file.