Function to change the extension of current file in Emacs lisp

Today, I was going through my draft files on this blog and many of them where .html files exported from Blogger (where I previously hosted this blog). And I wanted to change them to markdown files with .md extension. I could obviously use my script to change extension of multiple files, but I thought, there should be a way to do this within emacs.

So I took a deep dive into Emacs documentation and the end result was this function:

Change file extension in Elisp

1
2
3
4
5
6
7
8
9
10
(defun my/change-file-extension ()
(interactive)
(let* ((new-extension (read-from-minibuffer "Type the new extension including the dot (.): "))
(new-file-name (concat (file-name-sans-extension buffer-file-name) new-extension))
(filename (buffer-file-name)))
(rename-file filename new-file-name t)
(rename-buffer (concat (file-name-sans-extension (buffer-name)) new-extension))
(set-visited-file-name new-file-name)
(set-buffer-modified-p nil)
(message (concat "File renamed to " new-file-name))))

The above function will ask the user for the new extension, and then rename the file, buffer and also set the visited file name to the filename with new extension.

And on my Spacemacs, I added this key-binding to that function. “o” is reserved for user defined functions in Spacemacs.

1
(spacemacs/set-leader-keys "ofrx" 'my/change-file-extension)

If you know a better way of doing this, please feel free to add a comment. Any other suggestions welcome as well.

References

Setting up Apache Airflow on AWS EC2 instance

Setting up Airflow on AWS Linux was not direct, because of outdated default packages. For example I had trouble using setuid in Upstart config, because AWS Linux AMI came with 0.6.5 version of Upstart.

AMI Version: amzn-ami-hvm-2016.09.1.20161221-x86_64-gp2 (ami-c51e3eb6)

Install gcc, python-devel, and python-setuptools

1
sudo yum install gcc-c++ python-devel python-setuptools

Upgrade pip

1
sudo pip install --upgrade pip

Install airflow using pip

1
sudo /usr/local/bin/pip install airflow[s3, hive, python]

AWS SNS error - Invalid parameter

So I was playing with AWS Lambdas, and wanted to setup SNS notification for that.

1
aws sns publish --topic-arn arn:aws:sns:eu-west-1:22834709971:my-awesome-sns-topic --subject 'Subject' --message 'Hello, hello!'

Game Of Life (in Scala)

I recently came across an interesting problem/game called Game Of Life. A visual version of this is available here. Also, here is a beginners introduction to Game Of Life, or simply Life, written by Alex Bellos at Guardian.

It is a cellular automation problem created by John Horton Conway, a British mathematician in 1970, not a game you play to win or lose. This problem has a few rules that we need to follow.

Rules

  1. A cell in the grid can be dead or alive.
  2. A live cell with less than 2 live neighbours will die.
  3. A live cell with 2 or 3 live neighbours will stay alive.
  4. A live cell with more than 3 live neighbours will die.
  5. A dead cell with exactly 3 neighbours will become alive.

These rules are pretty simple. Once we know the number of live neighbours of a given cell, we can determine it’s fate in a step. In this post I’m going to dicuss method to find neighbours of a given cell in a matrix.

In Game of Life, we take a seed grid and eventually get another grid as a output, by applying the rules to each cell.

A pattern to use RequireJS config in a separate file

Setting up Airflow on AWS Linux was not direct, because of outdated default packages. For example I had trouble using setuid in Upstart config, because AWS Linux AMI came with 0.6.5 version of Upstart.

AMI Version: amzn-ami-hvm-2016.09.1.20161221-x86_64-gp2 (ami-c51e3eb6)

Install gcc, python-devel, and python-setuptools

1
sudo yum install gcc-c++ python-devel python-setuptools

Upgrade pip

1
sudo pip install --upgrade pip

Install airflow using pip

1
sudo /usr/local/bin/pip install airflow[s3, hive, python]

SOLID design principle

Setting up Airflow on AWS Linux was not direct, because of outdated default packages. For example I had trouble using setuid in Upstart config, because AWS Linux AMI came with 0.6.5 version of Upstart.

AMI Version: amzn-ami-hvm-2016.09.1.20161221-x86_64-gp2 (ami-c51e3eb6)

Install gcc, python-devel, and python-setuptools

1
sudo yum install gcc-c++ python-devel python-setuptools

Upgrade pip

1
sudo pip install --upgrade pip

Install airflow using pip

1
sudo /usr/local/bin/pip install airflow[s3, hive, python]

Closures

Setting up Airflow on AWS Linux was not direct, because of outdated default packages. For example I had trouble using setuid in Upstart config, because AWS Linux AMI came with 0.6.5 version of Upstart.

AMI Version: amzn-ami-hvm-2016.09.1.20161221-x86_64-gp2 (ami-c51e3eb6)

Install gcc, python-devel, and python-setuptools

1
sudo yum install gcc-c++ python-devel python-setuptools

Upgrade pip

1
sudo pip install --upgrade pip

Install airflow using pip

1
sudo /usr/local/bin/pip install airflow[s3, hive, python]

Sample app for Play! 2.2, Spring-data-jpa and Backbonejs

Setting up Airflow on AWS Linux was not direct, because of outdated default packages. For example I had trouble using setuid in Upstart config, because AWS Linux AMI came with 0.6.5 version of Upstart.

AMI Version: amzn-ami-hvm-2016.09.1.20161221-x86_64-gp2 (ami-c51e3eb6)

Install gcc, python-devel, and python-setuptools

1
sudo yum install gcc-c++ python-devel python-setuptools

Upgrade pip

1
sudo pip install --upgrade pip

Install airflow using pip

1
sudo /usr/local/bin/pip install airflow[s3, hive, python]

Backbonejs in jsFiddle.net

Setting up Airflow on AWS Linux was not direct, because of outdated default packages. For example I had trouble using setuid in Upstart config, because AWS Linux AMI came with 0.6.5 version of Upstart.

AMI Version: amzn-ami-hvm-2016.09.1.20161221-x86_64-gp2 (ami-c51e3eb6)

Install gcc, python-devel, and python-setuptools

1
sudo yum install gcc-c++ python-devel python-setuptools

Upgrade pip

1
sudo pip install --upgrade pip

Install airflow using pip

1
sudo /usr/local/bin/pip install airflow[s3, hive, python]

Populate Select box dynamically (plugin version)

Setting up Airflow on AWS Linux was not direct, because of outdated default packages. For example I had trouble using setuid in Upstart config, because AWS Linux AMI came with 0.6.5 version of Upstart.

AMI Version: amzn-ami-hvm-2016.09.1.20161221-x86_64-gp2 (ami-c51e3eb6)

Install gcc, python-devel, and python-setuptools

1
sudo yum install gcc-c++ python-devel python-setuptools

Upgrade pip

1
sudo pip install --upgrade pip

Install airflow using pip

1
sudo /usr/local/bin/pip install airflow[s3, hive, python]