Check command origin in Vim
If we want to check from where the command came from we can use
:verbose :com COMMAND
If we want to check from where the command came from we can use
:verbose :com COMMAND
In JavaScript when we show length
property on the function we get back the arity(number of arguments) of that function.
function importantFunction(first, second) {}
importantFunction.length
// 2
function complexFunction(first, second, third) {}
complexFunction.length
// 3
Networking on mac can be tricky, the same applies to NAT. If we want our mac to act as NAT we need:
1) Enable forwarding
sudo sysctl -w net.inet.ip.forwarding=1
2) Create a file with our NAT rules for eg nat_rules
with our configuration
nat on en0 from en1 to any -> (en0)
3) Start PF via pfctl
sudo pfctl -d # stop pfctl
sudo pfctl -F all -f ./nat_rules # flush all rules and load new ones
sudo pfctl -e # start pfctl
Chrome has a built-in tool for emulating various vision deficiencies which can be helpful when we are checking the accessibility of the website.
To turn on the emulation:
1) Open DevTools
2) Go to the Rendering
tab
3) At the bottom of the page we have “Emulate vision deficiencies” dropdown where we can choose from various vision disabilities like blurred vision.
Sometimes when we try to push some changes to the repository git push
can hang and we cannot get any meaningful information. We can check the GitHub status page but when everything is green there what can we do to get more information(applies only for ssh)
1) Create script like ~/sshv.sh
#!/bin/bash
ssh -vvv "$@"
2) Add permissions chmod u+x ~/sshv.sh
3) Push to the repo GIT_SSH=~/sshv.sh git push <rest of your command>
We should see what exactly what ssh is doing.
In Elixir when we are printing struct we can hide struct’s details implementing Inspect
protocol. For example the DateTime
struct is doing that so when we are inspecting it it shows us pretty version instead of the detailed one.
iex(1)> now = DateTime.utc_now()
~U[2020-10-06 10:59:58.388743Z]
iex(2)> IO.inspect(now)
~U[2020-10-06 10:59:58.388743Z]
If we want to reveal all the information that the struct contains we can use structs: false
option.
iex(5)> IO.inspect(now, structs: false)
%{
__struct__: DateTime,
calendar: Calendar.ISO,
day: 6,
hour: 10,
microsecond: {388743, 6},
minute: 59,
month: 10,
second: 58,
std_offset: 0,
time_zone: "Etc/UTC",
utc_offset: 0,
year: 2020,
zone_abbr: "UTC"
}
Github have two shortcut domains
repo.new - for creating new repository
gist.new - for creating new gist
Add x509
hex package to deps:
def deps do
[
{:x509, "~> 0.8.0"}
]
end
Generate certificates:
$ mix x509.gen.selfsigned
Add certificates to you Cowboy setup:
Plug.Cowboy,
scheme: :https,
plug: YourAppPlug,
options: [
port: 8443,
cipher_suite: :strong,
certfile: "priv/cert/selfsigned.pem",
keyfile: "priv/cert/selfsigned_key.pem",
otp_app: :your_app
]
}
Having that in mind we can use JSON inside of YAML and technically it would work as a correct YAML file.
# example.yml
{ "key": "value" }
Would work the same as:
# example.yml
---
key: value
More details: YAML specification
The browser has a built-in mode where we can easily edit the whole content. It can be useful for prototyping or quick changes during the call.
document.designMode = "on";
More information: MDN
There is no need to use case
inside of anonymous function - instead, we can create function with multiple heads.
list = [1, 2, 3, {4, 5}, 6, {7, 8}]
Enum.each(list, fn
{first_value, secon_value} ->
IO.puts("Tuple: #{first_value}, #{secon_value}")
element ->
IO.puts("Simple element: #{element}")
end)
I’ve just learned that if you want to use a dollar sign inside Makefile you need to escape $
with an extra $
.
For example:
LATEST_COMMIT := $(shell git log --oneline | head -1 | awk '{print $1}')
It won’t work because make
thinks that we are accessing make variable. If we want to use this awk
command inside Makefile we need to escape the $
LATEST_COMMIT := $(shell git log --oneline | head -1 | awk '{print $$1}')
Imagine you have a process which is responsible for consuming some sort of queue and spawning a separate process for each given job.
Each of the job processors later called workers communicates with some infrastructure layers for eg. external API, database, etc. We are injecting infrastructure to workers via configuration:
defp current_impl do
Application.get_env(:scanner, :ensure_file, __MODULE__.AwsImpl)
end
Each injected implementation must implement complementary behaviour for eg.
defmodule Scanner.Scans.EnsureFile.Impl do
@callback call(String.t, String.t) :: {:ok, any()} | {:error, any()}
end
In this setup, we could mock the whole behaviour using Mox
:
# test_suport.ex or other file with your test configuration
Mox.defmock(Scanner.EnsureFileMock, for: Scanner.Scans.EnsureFile.Impl)
Application.put_env(
:sanner,
:ensure_file,
Scanner.EnsureFileMock
)
# actual test
expect(Scanner.EnsureFileMock, :call, fn ^bucket, ^path ->
{:ok, :response}
end
When we run this test with the given context we would gen an error:
(Mox.UnexpectedCallError) no expectation defined for Scanner.EnsureFileMock.call/2
The reason is that Mox by default works in private
mode which is applying our mocked behaviour only for the current process - in our scenario our tested module spawns workers which are the real consumers of our mock and the implementation is only mocked for our test process. To allow our child process to consume the mock we need to set Mox in our test the global mode:
setup :set_mox_global
Or we could use:
setup :set_mox_from_context
Which will set the private
mode only when a test has async: true
otherwise it would use global mode.
When you forgot to use secrets from the very beginning - and some secrets landed in your repository eg. login/password/secret_key you can remove them in a simple way using filter-branch
for example to remove password you need to use:
git filter-branch --tree-filter "find . -type f -exec sed -i -e 's/password/**REMOVED**/g' {} \;"
It will replace password
with **REMOVED**
in the whole repo and commits.
npm install -g redis-commander
redis-commander --redis-port PORT --redis-host HOST --redis-password PASSWORD
redis-commander UI available at `localhost:8081