Posts

Showing posts from April, 2024

Analyzing 3 Body Problem in GNU Emacs

Image
  3 Body Problem is a sci-fi series on Netflix. Though this post is more about the analyzing process in GNU Emacs than about the show storyline. This is a work-in-progress . Design Decisions Leaf title will be displayed at the center of the circle. If it has an image, it will be displayed at the bottom. Group title is displayed at the top. Information gets fuzzier at a certain density. Around 16 leaves and three levels - root, groups and leaves - seems to be a comfortable threshold.  

Alternatives in GNU Emacs

Image
  Exploring some alternative ideas in GNU Emacs. Stock Heatmap Index (left) and Sector (right) performance heatmap   The circle radius is proportional to the weight of the stock in the index. The color is a range between green, white and red based on the price movement. This uses circle packing . ;; For drawing tooltip, additional point attributes are required. Properties old-x and old-y are used internally. ;; fill    - Circle color ;; title  - Circle label (Use \n for new line) ;; href - Link ;; text  - Tooltip text (Use \n for new line) (defstruct point x y r old-x old-y fill title href text)   ;; Image is an SVG image. (graph-draw-tree root image)    

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). The return value is the front chain. This can be further used to generate a circumscribing circle. (graph-pack points image)  ;; Get circumscribing circle (setq p (graph-enclose (graph-pack children)))   Bubble Graph   You can pass a hierarchical tree of points to generate a bubble graph. Only radii of leaf nodes are mandatory. title and fill parameters are used if provided. ;; For drawing additional point attributes are required. Hence this definition is different from above. Properties old-x and old-y are used internally. (defstruct point x y r old-x

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)))     HTML Text HTML uses HTML entities for special characters. e.g. &amp; entity for & (ampersand). ;; Buffer text to HTML Text (xml-escape-string STRING)   ;; HTML Text to buffer text (xml-substitute-special STRING)