We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Welcome
Latest postsOmarchy tweaks
Just some little tweaks here and there
After installing Omarchy I usually do:
Configs
DNS
Setup -> DNS -> Cloudflare
Consult your DNS setup with:
resolvectl status
.bashrc
Add to ~/.bashrc:
# CUSTOM
alias la="ls -lahF"
export PATH=~/bin:$PATH
export ERL_AFLAGS="-kernel shell_history enabled"
Unable to boot into Manjaro encrypted device after update
grub_is_using_legacy_shim_lock_protocol not found
After updating my OS last night I was seeing this error after reboot:
Error: grub_is_using_legacy_shim_lock_protocol not found
Yup, didn’t read the update/release notes (as usual). So needed to do some digging around until I found a solution that worked for me.
TIL: Read from STDIN in Elixir on HackerRank
Grab input data in HackerRank problems
Grab the input provided by HackerRank from STDIN with:
input = IO.read(:stdio, :all)
|> String.split("\n", trim: true)
If the input provided are numbers you might want to chain the above with:
input = IO.read(:stdio, :all)
|> String.split("\n", trim: true)
|> Enum.map(&String.to_integer/1)
In recent versions of Elixir (v1.13.0 or above) you might
want to use IO.read(:stdio, :eof) instead.
But HackerRank is running Elixir 1.8.2 which don’t
support the :eof option yet (LeetCode uses 1.15.7 by
the way…).
You can look at the Elixir version from within the REPL
with: System.version.
Permutations in Elixir
Generate all the permutations of a given list
While working on a problem, suddenly I had the need to get a hold of all the permutations of the elements in a list.
Thus, I did what any good engineer would do: I browsed the internet for a little bit and found a solution.
It makes use of for comprehensions and recursion.
It’s very concise and elegant, judge yourself:
defmodule Util do
def permutations([]), do: [[]]
def permutations(list) do
for(item <- list, rest <- permutations(list -- [item]), do: [item | rest])
end
end
TIL: Compare dates in Elixir
The right way to do date comparison in Elixir
Directly comparing dates with >, <, <=, etc.
won’t throw an error, but can give the wrong result.
The right way to go about it, is to use Date.compare/2.
E.g.:
today = Date.utc_today()
tomorrow = Date.add(today, 1)
yesterday = Date.add(today, -1)
Date.compare(today, tomorrow)
# :lt
Date.compare(today, today)
# :eq
Date.compare(today, yesterday)
# :gt
TIL: Escape JavaScript RegExp string
Create a regular expression from any string
Sometimes you try to use certain strings to create regular expressions.
The problem is these string might contain characters that have special meaning inside a RegExp. For example:
const myString = '[Hello?](World)!!!'
To escape it for safe use as a regex pattern, lodash provides
escapeRegExp.
const myString = '[Hello?](World)!!!'
// "\\[Hello\\?\\]\\(World\\)!!!"
Favorites
Handy shortcutsOmarchy tweaks
Just some little tweaks here and there
After installing Omarchy I usually do:
Configs
DNS
Setup -> DNS -> Cloudflare
Consult your DNS setup with:
resolvectl status
.bashrc
Add to ~/.bashrc:
# CUSTOM
alias la="ls -lahF"
export PATH=~/bin:$PATH
export ERL_AFLAGS="-kernel shell_history enabled"
Remove PDF password in Linux
Let's see how turn a password protected file into a normal one.
Using QPDF
QPDF is a command-line program for Linux that converts from one PDF file to another equivalent PDF file while preserving the content of the file. The tool allows you to encrypt and decrypt, web-optimize, and split and merge PDF files.
If you are using Manjaro, QPDF should be already installed. In case it is not, try with:
sudo pacman -S qpdf
To convert a secured file into an open one, use this command:
qpdf --password=mysecretpassword --decrypt the-secured.pdf new-unsecured.pdf