The best way to predict the future is to create it.
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. Ctrl – b) 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.
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:
First and foremost you need to create a local blank repository on your workstation. git init <repo-url>
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>
Then, setup the git config and specify that you’ll be doing a sparse checkout. git config core.sparsecheckout true
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
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.
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.
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.
After that export an environment variable to hold the output ISO filename that we will be consuming. export ISO_PATH="mac_installer.iso"
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`
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`
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
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"
We convert the dmg volume to UDTO compatible ISO standard. hdiutil convert "$ISO_PATH.cdr.dmg" -format UDTO -o "$ISO_PATH"
Then we rename and remove .cdr extension. mv "$ISO_PATH.cdr" "$ISO_PATH"
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!
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↩︎
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.
We assume here you have some basic knowledge on setting up Ruby and command line tools on macOS.
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.
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
Then we point mysql2 dependency to the installed openssl package from Homebrew. bundle config --global build.mysql2 --with-opt="$(brew --prefix openssl)"
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.
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. ↩︎
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. ↩︎
Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. ↩︎
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. ↩︎