Posts

Showing posts from October, 2022

Take Charge of PDF in GNU Emacs

Image
Display popup annotation in docview   All or None Docview is the default major-mode for displaying PDF in Emacs. It converts each page into an image using ghostscript into a temporary folder (/tmp/docview<nnnn>) and displays the same. For large PDF document, this conversion is unnecessary in most cases - especially when one is looking at the document for quick reference.   An ideal solution would be to convert pages on demand. However, for this, one would need to know the number of pages in the document. This can be done either by some external tools like pdfinfo or one would need to parse the metadata in the document. So here's some elisp code for the same.   (require 'pdf) (pdf-get "Root.Pages.Count")   or   M-x pdf-total-pages   ;; Metadata about the document (pdf-get "Root.Metadata")     So here we are - now that one can parse the metadata, what else can we do? Form fields and Embedded scripts M-x pdf-form PDF supports embedded Javascript for add

AWS API Usage in Elisp

Image
Here's some sample elisp code for signing Amazon Web Services (AWS) API requests . The value (first element) returned by (aws-sign4) is used in Authorization header while making a request. When the function is called with an expires value, it returns a URL which can be directly used in a browser. (require 'aws-sign4)   (let ((*aws-credentials*        (lambda ()          (values "AKIAIOSFODNN7EXAMPLE" "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"))))   (aws-sign4 :region "eu-west-1"              :service "s3"              :host "s3-eu-west-1.amazonaws.com"              :path "/some-bucket/some-file"              ))   (let ((*aws-credentials*        (lambda ()          (values "AKIAIOSFODNN7EXAMPLE" "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"))))   (aws-sign4 :region "us-east-1"              :service "iam"              :host "iam.amazonaws.com"              :params '((&qu

One-click Social Media Client

Image
Reddit: Dashboard and details view Twitter: Dashboard and details view Tumblr: Dashboard and details view Youtube: Dashboard and details view   GNU Emacs as a Social Media Client Consumption of social media typically necessitates few repeated actions - like, share, comment and follow. If these actions are assigned to convenient keyboard keys, the consumption becomes easier - no more pointing and clicking tiny icons. Here's an attempt to unify this experience using GNU Emacs, tumblesocks and oauth2.   (require 'tumblesocks) (require 'oauth2)   ;; service below is one of twitter, reddit or tumblr (setq tumblesocks-service-conf    (service . ( client-id secret-key redirect-url ))     Use M-x sm-twitter , M-x sm-reddit , M-x sm-youtube or M-x sm-tumblr . First time, it will open a browser window. You'll need to login to the service and allow the permissions in following window. Then you'll be redirected to a URL. You'll need to copy the code (code= value#_ ) in th

Oauth2 sample flow in Elisp

Image
Here's a modified version of oauth2.el . This Elisp code works for oauth2 flow using Twitter, Gmail, Reddit and Tumblr. To add more services, add the provider URLs to the variable oauth2-service-conf. To make API calls, set the service configuration values (client-id, secret-key and  redirect-url) in the variable t-service-conf. Then use the examples in the usage section. (require 'oauth2)  (setq t-token nil) (setq t-service-conf   '((service . ( client-id secret-key redirect-url ))))   (defun t-api-oauth2-request (url params method service auth-scope                        &optional headers)   (let* ((oauth2-conf (assoc service oauth2-service-conf))      (conf (assoc service t-service-conf))      (t-consumer-key (nth 1 conf))      (t-secret-key (nth 2 conf))      (t-callback-url (nth 3 conf))      (data nil))     (unless (assoc service t-token)       (push (cons service           ( oauth2-auth (nth 1 oauth2-conf)                    (nth 2 oauth2-conf)