Where It All Started.

Where It All Started.

Life, Stock Trading, Investments, Business and Startup. Most are programming stuff.

Tag: macos

Using Vim Hex Editor To View Keyboard Key Hex Code

The best way to predict the future is to create it.

— Anonymous.

In this TIL (Today I Learned), we will review a way on how to view keyboard key hex code. As I modify my iTerm2 (a popular terminal emulator for macOS) key shortcuts to map my tmux Ctrl + b keys, I wonder how to get the keyboard key hex codes easily.

Then I remembered that there is the xxd (a command line hex viewer and editor which is part of the vim package) command which can process keys and convert them to hex code.

To start off, we run xxd from the terminal. It will wait for a read line. Execute your keystrokes (e.g. Ctrlb) then press enter to create a new line. After the new line add EOF (End Of File) which would corresponds to the keyboard keys Ctrl + d. After doing the process above xxd would output a hex representation of the keyboard key code that you desire.1

Another trick using xxd command is to reverse hex string like this.

echo <hex code> | xxd -revert -plain | rev | tr -d '\n' | xxd -plain

An example hex code would be 030201. That would output a reverse 010203. The rev command will reverse the output while the tr would trim newline.


  1. https://stackoverflow.com/questions/36321230/finding-the-hex-code-sequence-for-a-key-combination ↩︎

Checkout Specific Directory Within Git Repo

I believe that the first test of a truly great man is his humility. Really great men have a curious feeling that the greatness is not in them but through them. And they see something divine in every other man and are endlessly, incredibly merciful.

— John Ruskin.

One day I was working on a driver port to macOS (Apple Macintosh OS) and the only opensource code for it can be found on Linux kernel.

Heck! The Linux kernel repository is around 2GB including all history and I only needed a specific directory inside the repository. After searching the whole internet I found an answer1.

Here are the steps to clone a specific directory from a git repository:

  1. First and foremost you need to create a local blank repository on your workstation. git init <repo-url>
  2. Inside the created bare repository, map the remote URL of the remote repository you want to clone. cd <repo-name> git remote add origin <remote-repo-url>
  3. Then, setup the git config and specify that you’ll be doing a sparse checkout. git config core.sparsecheckout true
  4. Create and add all the directories you want to checkout in the sparse-checkout file that can be found in .git/info/sparse-checkout. echo "<needed-directory>/*" >> .git/info/sparse-checkout
  5. When all the above steps is done, finally pull the repository objects. git pull --depth=1 origin master

So guys if you have any questions? hit me up on my social media accounts. That’s all there is that is needed. Now its already cloned and can now be worked on.

❌ Originally posted on August 5, 2019.


  1. https://stackoverflow.com/a/28039894 ↩︎

Creating Bootable ISO from macOS Installer

If the freedom of speech is taken away then dumb and silent we may be led, like sheep to the slaughter.

— George Washington.

Recently, I’ve been in a situation on where I want to create a separate portable macOS Mojave1 installer but I don’t know how. I’ve compiled this steps which I gathered from multiple sources to create a boot-able macOS installer. This article will assume you are running on macOS system.

  1. First and foremost, we download the macOS installer that we want to use from the Apple App Store. I pick the latest one (at this time of writing) which is Mojave.
  2. After that export an environment variable to hold the output ISO filename that we will be consuming. export ISO_PATH="mac_installer.iso"
  3. Then we create a blank dmg volume using the command hdiutil2. This command will create a HFS+J filesystem table to store the installer data with the capacity of 6GB. hdiutil create -o "$ISO_PATH.cdr" -size 6g -layout SPUD -fs HFS+J`
  4. Mount the created volume. If you get a problem while mounting the volume, try to create the folder first using mkdir -p /Volumes/install_build. hdiutil attach "$ISO_PATH.cdr.dmg" -noverify -mountpoint /Volumes/install_build`
  5. After that run the setup to install and copy the files in the volume that we mounted earlier. sudo "/Application/Install macOS Mojave.app/Contents/Resources/createinstallmedia" --volume /Volumes/install_build --nointeraction
  6. Unmount the volume.
    Note: Check the name first, as volume name changes after the setup. The installation process specifically overwrites the partition table and volume name. hdiutil detach "/Volumes/Install macOS Mojave"
  7. We convert the dmg volume to UDTO compatible ISO standard. hdiutil convert "$ISO_PATH.cdr.dmg" -format UDTO -o "$ISO_PATH"
  8. Then we rename and remove .cdr extension. mv "$ISO_PATH.cdr" "$ISO_PATH"
  9. Finally, we delete all the remnants of the procedure. rm "$ISO_PATH.cdr.dmg"

That’s all the steps needed. If you ever completed it without error then you got yourself a macOS ISO installer.

🧡🧡🧡🧡🧡🧡🧡

Hope you guys enjoyed this article!


  1. macOS Mojave is the fifteenth major release of macOS, Apple Inc.’s desktop operating system for Macintosh computers. Mojave was announced at Apple’s Worldwide Developers Conference on June 4, 2018, and was released to the public on September 24, 2018. Wikipedia ↩︎
  2. hdiutil – Manipulate disk images (attach, verify, burn, etc). https://ss64.com/osx/hdiutil.html ↩︎

Installing MySQL2 Ruby Gem in macOS Mojave

Installing MySQL2 gem became a common problem for people who uses macOS to develop Ruby1 based apps that utilized MySQL2 data store. I’ve personally encountered this problem myself back in the days and still encountering this on brand new setup macOS workstation. In this article, we will go through the steps I did to resolved this problem.

Tradition lives because young people come along who catch its romance and add new glories to it.

— Michael Novak.

Prerequisites

We assume here you have some basic knowledge on setting up Ruby and command line tools on macOS.

  • Ruby (Latest)
  • Bundler3 (Latest)
  • Homebrew4 (Installed and no problems, run and check brew doctor for more info and if the installation is okay)

What did I do to solve the problem?

Here’s what I’ve done to resolve the problem.

  1. First is to install openssl or gnutls (choose your poison). Both are great have some pros and cons but most people would use openssl and that’s what I preferred. brew install openssl
  2. Then we point mysql2 dependency to the installed openssl package from Homebrew. bundle config --global build.mysql2 --with-opt="$(brew --prefix openssl)"
  3. After all of that, we install the mysql2 dependency and all the sub-dependents that are needed. bundle install

That’s all needed in order to install mysql2 on a fresh macOS Mojave. Now you can develop ruby app that utilize MySQL as data store.

So guys, let me know if you encountered any problems? or any particular additional ways to install mysql2. That’s it guys hope you enjoyed this article and as always live life.

😀😁😁🤣😃😄


  1. Ruby is an interpreted, high-level, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro “Matz” Matsumoto in Japan. Ruby is dynamically typed and uses garbage collection. ↩︎
  2. MySQL is an open-source relational database management system. Its name is a combination of “My”, the name of co-founder Michael Widenius’s daughter, and “SQL”, the abbreviation for Structured Query Language. ↩︎
  3. Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. ↩︎
  4. Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS operating system and Linux. The name is intended to suggest the idea of building software on the Mac depending on the user’s taste. ↩︎