Friday, March 8, 2024

Saturday, February 3, 2024

How to reference the previous string in Zsh command-line

In `zsh`, you can get the last string in a list of strings separated by spaces by using parameter expansion. Here's a simple command to achieve this:

```zsh
# Assuming a list of strings separated by spaces
list_of_strings="string1 string2 string3 string4"
# Use parameter expansion to get the last string
last_string=${(s: :)list_of_strings}[-1]

# Print the last string
echo $last_string
```

In this example, `(s: :)` is a parameter expansion flag that splits the variable `list_of_strings` on spaces, treating it as an array. `[-1]` then accesses the last element of this array.

To put this into a function that you can use in an interactive shell to get the last string before the cursor, you can use the following `zsh` function:

```zsh
# Define the function to get the last string before the cursor
get_last_string_before_cursor() {
  # Split LBUFFER into an array of words
  local words=(${(z)LBUFFER})
  # Get the last word
  local last_word=${words[-1]}
  # Print the last word
  echo $last_word
}

# Create a ZLE (Zsh Line Editor) widget that binds the function
zle -N get_last_string_before_cursor_widget get_last_string_before_cursor

# Bind the widget to a keyboard shortcut, for example, Ctrl + t
bindkey '^T' get_last_string_before_cursor_widget
```

Add this function to your `.zshrc` file. After reloading your shell, you can press `Ctrl + t` to print the last string before the cursor on the command line.

Friday, October 13, 2023

xdotool workaround for opening an email in conversation view in thunderbird 115.3.1

With a recent update of Thunderbird, I've noticed that when I open an
email with conversation view (with Ctrol+Shift+O), the messages are
not properly sorted anymore. I had to click the sort-by-date menu and
sort-by-thread menu, respectively, every time.
 

I've written a script to automate that boring process as you can see below.

#!/usr/bin/bash

xdotool mousemove 500 500
xdotool click 1
xdotool key ctrl+shift+o
sleep 1
xdotool key --delay 100 alt+v s e
sleep 1
xdotool key ctrl+shift+o
sleep 1
xdotool key --delay 100 alt+v s t
sleep 1
xdotool key 0x002a
xdotool mousemove 500 335

I store this script in dom0 and name it xdo-thread. I map this script
with F5 key. Now, every time I want to see the messages in
conversation view, I simply press F5. 


There's one tricky part I'd like to point out. The line "xdotool click 1" is a trick. Without it, we can't use "xdotool key". I'm not sure what the reason is yet. Maybe it's about window focus.

Sunday, July 9, 2023

High-speed trains

Someone has once said “Life is a journey, not a destination.” However, for
decades, technological advancement in high-speed trains has been only focusing
on decreasing the time it takes to travel from one place to another. That’s
purely an oversight of how much quality time we can have to make bonds with
our friends, family members, the mother nature, and even ourselves while we’re
traveling on the trains.

We can’t deny that the most famous nation that has been developing the
fastest high-speed trains is Japan with its state-of-the-art Shinkansen, aka the
bullet train. It claims that within the next few years, their bullet train will be
able to travel at the maximum of 320 Km/h. That sounds crazy, isn’t it?
There’s also the so-called Hyperloop, an ambitious engineering project, which
was recently reintroduced to the world by SpaceX, a high-tech company owned
by one of the richest and smartest guy on earth, Elon Musk. With this tech-
nology, they aim to reach a top speed of 1,220 Km/h, which is 4 times higher
than the Japanese’s!

However, nowadays, more and more people are starting to see the importance
of journey and ways to spend quality time with those they love. This is exactly
how the low-speed train idea was born. Imagine you are traveling by a train
which is passing through a fantastic scenery in Hokkaido or Switzerland which
could take your breath away. I bet you wouldn’t want a high-speed train during
the trip.

In conclusion, we should combine both the high-speed and low-speed train
technologies into a new one called, mixed-speed train. This train will travel
fast when it is passing through dull areas and slow when it is passing through
wonderful places. I’m writing this article on a train. Next station, Changi
Airport. Thank you for reading.

Thursday, June 8, 2023

I loved BG

Poem
by Langston HughesI loved my friend.
He went away from me.
There’s nothing more to say.
The poem ends,
Soft as it began—
I loved my friend.

Poem
by ... I loved my friend.
BG went away from me.
There’s nothing more to say.
The poem ends,
Soft as it began—
I loved my BG.

How to record video without sound on Android?

 Line Camera + Samsung's Screen Recording (without Sound)

Thursday, May 11, 2023

Was life really better?

\begin{document}

\maketitle

People often talk about how life was better in the `good old days', but
how true is that?  Let's look into my views of life before and after the
smartphone era.

Life was absolutely different when there was no smartphone.  Your bosses
and co-workers could not easily reach out to you via instant messaging
apps after work hours or while on holidays.  If they really needed to
contact you, they had to give you a call.  Giving someone a call means
that it has to be a matter of utmost importance.  This helped filtering
out less important or disorganized matters from reaching out to us.
Moreover, even within work hours, allowing other people to text you any
time they wish is a great distraction at work which reduces productivity
tremendously.  Every time we get distracted by someone, involuntarily,
while we are working on something, it will take an average of 23 minutes
and 15 seconds to refocus \cite{lastoe20}.  In order to circumvent this
problem, some companies allow each employee to set his/her own
workplace-distraction-hours.  Anyone who needs to talk to another person
has to check his/her schedule first.

However, I agree that there are many benefits that come with smartphone.
Things such as Duolingo, a language learning app, which allows us to
learn new languages at any time and places we want, or Google Maps,
which makes it extremely easy to travel without having to give too much
effort into planning, are really useful.

In conclusion, there are countless benefits we can get from smartphone,
but we have to be aware of the pitfalls that come with it.

\begin{thebibliography}{10}
  \bibitem{lim23} Alex Lim et al,
    \textit{Constant companion: Our lives with mobile phones
    https://www.straitstimes.com/multimedia/graphics/2023/05/mobile-phones-singapore/},
    The Straits Times,
    10\textsuperscript{th} May 2023.

  \bibitem{fried18} Jason Fried et al,
    \textit{It Doesn't Have to Be Crazy at Work},
    Harper Business,
    2\textsuperscript{nd} October 2018.

  \bibitem{lastoe20} Stacey Lastoe,
    \textit{https://www.themuse.com/advice/this-is-nuts-it-takes-nearly-30-minutes-to-refocus-after-you-get-distracted},
    TheMuse.com,
    19\textsuperscript{th} June 2020.
\end{thebibliography}

\end{document}

Monday, May 8, 2023

How to enter unicode character in Linux?

You can enter unicode character in Linux by:

    Ctrl + Shift + u

follows by the unicode number, e.g., 1F43E for the Paw Prints character.

Sunday, May 7, 2023

Paw Prints in Unicode

Unicode U+1F43E   ðŸū

is the cat's paw print character!