Posts

Circle Packing Animation in GNU Emacs

Image
  Here's an implementation of circle packing algorithm by Wang et. el. in Elisp. Front chain is the set of circles on the periphery. These are shown as connected by red line in the animation. (require 'graph-pack) (defstruct point x y r)   ;; Define a point (setq p (make-point :x 17 :y 0 :r 16))   ;; Define a list of points (setq points (list p1 p2))   ;; Image is an SVG image. This is used for drawing the animation (optional). (graph-pack points image)    Background I don't have access to the research paper. The link to paper in D3js documentation wasn't very helpful either. Hence the code didn't make much sense to me. It only struck me when I saw the following image. Important: My implementation doesn't use scores at each step. On the surface, that doesn't seem to be a drawback though. Code https://github.com/atamariya/tumblesocks/blob/dev/graph-pack.el https://github.com/atamariya/tumblesocks/blob/dev/graph-enclose.el https://github.com/atamariya/tumb

SVG Animation in GNU Emacs

Image
  Synchronized Multimedia Integration Language (SMIL) is an SVG extension which allows one to create simple animation without Javascript. Here is a basic implementation for <animate> tag. (require 'svg)   (svg-animation-run)    ;; Exiting the image-mode will cancel the animation.  ;; Following command will also cancel the animation. (svg-animation-cancel)   Code https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/svg.el   References Bat SVG    

Mozilla Readability in GNU Emacs

Image
  Output using Readability (left) and original eww (right)   Mozilla Readability is a standalone version of the readability library used for Firefox Reader View . A simple hack to eww can bring the same feature in GNU Emacs. ( Note: eww already has a readable mode. This is just an alternative. Updated the post to reflect the same.)   - Install NodeJS   - Install npm modules. npm install @mozilla/readability jsdom   - Create a file readability.js with following content. Note the file location. var { Readability } = require('@mozilla/readability'); var { JSDOM } = require('jsdom'); var fs = require("fs"); var str = fs.readFileSync(process.stdin.fd).toString(); var doc = new JSDOM(str); var reader = new Readability(doc.window.document); var article = reader.parse(); console.log(article.content);     - Modify the following function to use the file location noted above . Evaluate the function. (defun mozilla-readability (start end)   (shell-command-on-region star

Elisp Snippets

Image
Some useful Elisp snippets. Random number Generate a random number between min and  max positive integers.  Note: We are adding 1 to max to make it an inclusive range. (defun random-num (max &optional min)   (let* ((num (random ( 1+ max ))))     (if min (max min num) num)))     Random color   (defun random-color-rgb ()   (list (random 256) (random 256) (random 256))) (defun random-color-html ()   (apply #'format "#%02x%02x%02x" (random-color-rgb)))   Random face color Generate a random valid color for a font face. (defun random-color-face ()   (let* ((colors (defined-colors))      (n (length colors)))     (nth (random n) colors)))      

Data Visualization with GNU Emacs

Image
    GNU Emacs can be used for quick data visualization in combination with Gnuplot. When you have some data and you want to visualize what the correlation looks like, this command comes in handy. No need for any setup - no data file and no Gnuplot script. The command below uses some sensible defaults for trivial cases. If the first line contains string label, the same is used as a key label for the value and/or axes' names as appropriate. If there's a single column of data, it is used as Y value. If there's more than one column, first column is used as X value and other columns are plotted along Y-axis. Takes care of comma or whitespace separator. Note: The latest version of the code is available at the end of the post. Options available in latest version   - Install gnuplot executable and gnuplot Elisp package . - Evaluate the defun ( C-M-x ). - Select a data range using rectangle command copy-rectangle-as-kill (C-x r M-w). - Run M-x  gnuplot-rectangle. This opens the g

Just In Time Lazy-Loading

In personal computing, there are multiple scenarios where Just in time (JIT) lazy-loading is desirable since what can be shown to the user at any point of time is limited by the screen real estate. This involves two steps: Detect changes Refresh the visible changed part during idle time Consequently, a framework to support these scenarios is desirable. Specific logic related to refreshing, like image loading or font coloring, can be encapsulated in individual functions which will be called by the framework. Detect Changes While editing a document, the number of changes will be huge. So it's better to track the extent of changes or the changed region instead of individual changes. When the file is loaded, the whole file is considered to be changed. Refresh the changed part in idle time Run a timer which kicks off when the computer is idle i.e. the user is not interacting with the computer. This is to ensure that the user never faces a lag in his interaction. If an idle timer is not

GNU Emacs as a Comic Book Reader

Image
  Comics are available in digital format as a collection of images in a compressed ZIP or RAR file (.cbz or .cbr file extension respectively). These can be enjoyed in GNU Emacs with full access to image viewing capabilities using keybindings.   # Make sure you have unrar installed for CBR files # apt install unrar   (require 'arc2-mode)   (setq archive-summarize-files-fn 'archive-summarize-files-as-thumb)     Note: The archive-mode is capable of displaying the list of files in an archive; though it depends on external tools for extraction. For JPG and PNG, Emacs can resize the image without external convertor (ie. imagemagick). However, some menu options for image transformations in image-mode might not be available. Use the following patch for image-mode.el . @@ -460,16 +460,16 @@ image-mode-map       :help "Show image as hex"]      "--"      ["Fit to Window Height" image-transform-fit-to-height -     :visible (eq image-type 'imagemagick) +