Even though I have moved over to Linux completely for quite sometime, every now and then I’ll encounter situations in which I really have to use windows. Last time I had to do it is because of a form which was a Word document set up in a way that I had to use ms word to fill it in. Initially I planned to never go back to windows and in such situations I’ll just borrow a windows computer just for that purpose. Then I realised it is better to have a windows installation loaded with commonly used software ready to go whenever I needed it rather than depending on someone else. So I installed windows on my desktop using VirtualBox. The only thing which needs to be sourced is the windows installation disk (.iso) which either someone can loan you a copy or buy one. I used my university’s license on this one.
The steps are straightforward with Arch. Install virtualbox, virtualbox-host-modules-arch, virtualbox-ext-oracle (this one is from AUR). Open virtual box and create your Virtual machine following the step by step GUI and start the machine. Thats it. We have a working windows installation. First thing we need to do in the guest system is install “guest additions” which can be inserted as a disc from Devices>Insert Guest Additions CD Image. The way to make the virtual machine look seamless with host OS is by setting the same wallpaper , set the guest to auto-resize to host window, hide the menu bar and status bar.
My configuration for i3 is available at https://github.com/sbmkvp/config
Sometimes you just don’t have the patience to open a GUI. Imagine you are working on a terminal remotely through a very feeble internet connection and after hours of data wrangling you got your results in one small package. Now all you want is to email this 200kb document (average size of a 20k word .txt document). You can either load a GUI, open a browser, open gmail (the login page itself is 2MB), attach the file and send the email or just execute a one line command which does everything for you. With some minimal setup you can do the latter – sending email via CLI just like any other shell command. You can even include this in your scripts (send mail when the script finishes running etc).
We will do this using a terminal program called “mutt” which also has a brilliant CLI interface and will configure it to use gmail via imap. First step is to install mutt using a package manager, (apt/ yum/ pacman for linux and brew for macosx). I am doing this in Arch with pacman. I am installing mutt and smtp-forwarder and then create necessary folders and files for mutt.
sudo paman -S mutt smtp-forwarder
mkdir -p ~/.mutt/cache/headers
Edit the muttrc file with your favourite text editor and add these configurations, (make sure to change the username to your username and if your are using two factor authentication with gmail the password has to be generated from App passwords.
set imap_user = 'firstname.lastname@example.org'
set imap_pass = 'yourpassword'
set from= 'email@example.com'
set folder = imaps://imap.gmail.com/
set spoolfile = imaps://imap.gmail.com/INBOX
set header_cache = "~/.mutt/cache/headers"
set message_cachedir = "~/.mutt/cache/bodies"
set certificate_file = "~/.mutt/certificates"
set smtp_url = 'smtps://firstname.lastname@example.org:465/'
set imap_pass = 'yourpassword'
set move = no
set imap_keepalive = 900
set editor = vim
bind pager j next-line
bind pager k previous-line
set sort = threads
set sort_aux = reverse-date-sent
That is it! Now we can send mail from terminal by just passing some text or a file with the text to the mutt command,
echo "email body" | mutt -s "email-subject" -- email@example.com
mutt -s "email-subject" -- firstname.lastname@example.org < file_with_body_text.txt
we can even attach files like this,
echo "please find attached" | mutt -s "email-subject" -a "attachment.pdf" -- email@example.com
I have been really busy the past 3 days so there were no posts. So there is going to be 3 unrelated small posts on small utilities I use. First thing is a http-server. Since web browsers are locked down these days, it is not easy to read files off local machine when you are testing even a simple website. For example, If I have a html file where I want to load a csv, parse it and display it, serving the html from a http server is the only way to allow a chrome/ Firefox to read the file. At the same time, I really don’t want to install a full Apache wen server to serve two html files.
The solution to this is a node package – ‘http-server’. It is a tiny http server which when run from a folder in CLI, serves the folder contents as a http-host at localhost. All we need to do is,
# Install nodejs and node package manager (npm)
sudo pacman -S node npm
# Install http-server package through npm globally
npm install -g http-server
# start the server
That is it! whichever folder you ran http-server would be accessible at the ip/port shown. we can combine this with forever (another node package) or run under a gnu-screen session to keep it in the background.
This is a really recent development and I am very excited about this. I finally found a way to have a somewhat proper Linux installation on my phone. Though it might not be the best place to have a CLI, it is really promising and I can rely on this to do some small stuff on the go. As the tools I use are getting simpler (Photoshop vs Imagemagick) and the hardware of the phones I own are getting better, it is should possible for my phone to do the things my 5 year old laptop could handle provided the right environment.
This is done by installing a full Arch installation on an Android phone under the termux environment using the installer from TermuxArch. The installation here is actually way easier than installing Arch on a normal desktop. We start by installing termux android app. When we open termux we get a bash shell. From here we install wget by running, pkg install wget . When this is complete we download and run the Arch installation script by,
# Download the script
# Adding execute permissions
chmod a+x setupTermuxArch.sh
# Run the script
Now we can just follow the instructions in the script which will download and unpack a base Arch Linux system and ask you to edit the mirror list. At this point, just un-comment (remove the #) of the closest mirrors and save and exit the file. When the installation is complete you have a vanilla arch system on your mobile! Now we can theoretically install and use any program I have on my work desktop on my phone which including to ssh, vim, git, latex, R, node, postgres, mongodb, etc etc. I can even ssh into my work desktop straight from here. Below are some screenshots of the system (the chart is done entirely on phone!).
R with ggplot2
Plotting with ggplot2
Another short post showing off the stuff I have been working on. As I mentioned earlier I have moved to Linux couple of years back with Ubuntu and now I have moved to Arch. It is as minimal as it gets and along with AUR, stuff just works. Though I am not a big fan of GUI, I definitely have a need for at least a window manager to display the browser and graphics/documents I work on. So I need a system which is minimal, bloat free with exactly the things I want, with an efficient keyboard based navigation. The video below shows my current set up (note: I mostly reside inside the terminal with tiling mode so floating windows here are just to make things look nice)
This is a small quirk I solved recently so wanted to document here. Recently I moved my desktop at work from ubuntu to arch linux. To be honest, it went surprisingly well. Every single thing I had in ubuntu migrated nicely to arch with just one exception – tmap package in R.
The “tmap” package depends on “v8” package which in turn depends on v8 library in linux specifically version 3.14. This library is not available under pacman (arch package manager) and had to be compiled from AUR package. It seemed easy enough until it turned out that the package needed to update gyp which moved its source code from svn to git. While I could still compile it by modifying the PKGBUILD file, it resulted in segmentation faults while actually loading v8 package in R. After meddling with it for sometime I eventually gave up and decided to just wait for the update for tmap rather than wasting time on it. But I fixed it this week!
The trick is a two step install with yaourt (separate package manager for AUR). First we need to install yaourt and then both v8-3.14 and v8-3.14-bin package using yaourt after which tmap installs and works perfectly in R
yaourt -S v8-3.14
yaourt -S v8-3.14-bin
As I have mentioned earlier in the blog, I really don’t like GUI based Integrated Development Environments. The reasons I find them pointless are,
- Since I never deal with anything bigger than a one person project, I almost never use any advanced IDE features like debugging etc. The only things I find useful in a GUI based IDE are syntax highlighting and some of the WYSWYG stuff.
- I work with headless systems where I don’t have the permissions to install my favourite GUI systems, so irrespective of how good an IDE is I cannot use them in the most powerful machines I have at my disposal. I need my workflow to be portable to the least common denominator.
Because of this I had to give up on one of the best GUI IDEs I have ever seen – R Studio. Though I could get by with most of the stuff with vim and screen the biggest feature in R studio I missed was the ability to execute commands from the script into the console. Today I figured out how to implement the same in my vim+screen+R setup.
map <C-L> "kyy:echo system("screen -S $STY -p R -X stuff ".escape(shellescape(@k),"$"))<CR>j
vmap <C-L> "xy:echo system("screen -S $STY -p R -X stuff ".escape(shellescape(@x."\n"),"$"))<CR>j
Having these two lines in the .vimrc adds mapping to Ctrl-L in normal mode and in visual mode to transfer commands from the current file to the window with R console opened under the current screen session. In normal mode the entire line is sent to R and in visual mode what ever that is selected is sent to R. A demo of these mappings is shown below.