Skip to content

Instantly share code, notes, and snippets.

View akagr's full-sized avatar

Akash Agrawal akagr

View GitHub Profile
@akagr
akagr / download_kindle.js
Last active October 20, 2024 16:19
Download kindle books from Amazon web
/*
I was looking to try a non-kindle e-reader, but my library kept weighing me down. While I had calibre and the de-drm plugin, I found the downloaded books on my kindle were in kfx format and weren't playing well with calibre, even with the kfx input plugin.
Further, I found downloading books directly from web (Amazon > content library) did give me an azw3 file, which works well with de-drm.
To automate part of the process, I wrote a short js script. It doesn't walk through all the pages in content library, but it does download all the books currently visible on the list. Amazon lets us view 25 books per page, so I just had to switch pages, run script, repeat.
The meat of this script is constructing the url used to start a download. Device type, serial number, customer id etc. will be different for everyone, so it's best to download one book manually and check the network inspector for the request details. Apart from the book's `key`, all other details remain same for all the books (at least they did for me
@akagr
akagr / renew-gpgkey.md
Created August 27, 2024 11:32 — forked from krisleech/renew-gpgkey.md
Renew Expired GPG key

Renew GPG key

Given that your key has expired.

$ gpg --list-keys
$ gpg --edit-key KEYID

Use the expire command to set a new expire date:

@akagr
akagr / debug.py
Created August 21, 2023 12:26
Logging request data in python
import logging
from http.client import HTTPConnection
log = logging.getLogger('urllib3')
log.setLevel(logging.DEBUG)
# logging from urllib3 to console
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
log.addHandler(ch)
@akagr
akagr / keytool-self-signed-certificate.md
Created May 4, 2023 15:29 — forked from elton-alves/keytool-self-signed-certificate.md
Self signed certificates with keytool
@akagr
akagr / prepare-commit-message
Last active March 28, 2023 06:01
Git commit message hook for JIRA tickets
#!/bin/sh
#
# Inspects branch name and checks if it contains a Jira ticket number (i.e. ABC-123).
# If yes, commit message will be automatically prepended with [ABC-123].
#
# Useful for looking through git history and relating a commit or group of commits
# back to a user story.
# Thanks to https://medium.com/bytelimes/automate-issue-numbers-in-git-commit-messages-2790ae6fe071
@akagr
akagr / fizzbuzz.lisp
Created July 7, 2021 15:39
functional fizz buzz in emacs lisp
(defun divisible (a b)
(equal 0 (% a b)))
(defun to_s (item) (format "%s" item))
(defun fizzbuzz (num)
(let* ((fizz (if (divisible num 3) "fizz" ""))
(buzz (if (divisible num 5) "buzz" ""))
(combi (concat fizz buzz))
(result (if (length> combi 0) combi (to_s num))))
@akagr
akagr / em.scpt
Last active June 14, 2024 03:46
MacOS launch helper to start emacs daemon or attach to one
-- ███████╗███╗░░░███╗░█████╗░░█████╗░░██████╗
-- ██╔════╝████╗░████║██╔══██╗██╔══██╗██╔════╝
-- █████╗░░██╔████╔██║███████║██║░░╚═╝╚█████╗░
-- ██╔══╝░░██║╚██╔╝██║██╔══██║██║░░██╗░╚═══██╗
-- ███████╗██║░╚═╝░██║██║░░██║╚█████╔╝██████╔╝
-- ╚══════╝╚═╝░░░░░╚═╝╚═╝░░╚═╝░╚════╝░╚═════╝░
--
-- Open this script with 'Script Editor' on MacOS, then save it
-- inside /Applications as an 'Application', not 'Script'.
# Just a copy of https://stackoverflow.com/a/30724359/1825727
def from_hashstring(value)
json_string = value
.gsub(/([{,]\s*):([^>\s]+)\s*=>/, '\1"\2"=>') # Handle ruby symbols as keys
.gsub(/([{,]\s*)([0-9]+\.?[0-9]*)\s*=>/, '\1"\2"=>') # Handle numbers as keys
.gsub(/([{,]\s*)(".+?"|[0-9]+\.?[0-9]*)\s*=>\s*:([^,}\s]+\s*)/, '\1\2=>"\3"') # Handle symbols as values
.gsub(/([\[,]\s*):([^,\]\s]+)/, '\1"\2"') # Handle symbols in arrays
.gsub(/([{,]\s*)(".+?"|[0-9]+\.?[0-9]*)\s*=>/, '\1\2:') # Finally, convert => to :
JSON.parse(json_string)
@akagr
akagr / keybase.md
Created April 1, 2020 17:19
keybase.md

Keybase proof

I hereby claim:

  • I am akagr on github.
  • I am akashagrawal (https://keybase.io/akashagrawal) on keybase.
  • I have a public key ASB2jpNzAa37164ZMfrGb0Te3fV4rcXowwYbpKIG-AeTwwo

To claim this, I am signing this object:

@akagr
akagr / squareup.sh
Last active December 19, 2018 18:17
Squares up rectangular images by filling empty space with blur of same image
# To get the resolution, multiply 118 by cm. For example, 7 cm image at 300ppi will be 7 * 118 = 826 px
RESOLUTION=826
convert $1 -resize ${RESOLUTION}x${RESOLUTION}^ -gravity center -crop ${RESOLUTION}x${RESOLUTION}+0+0 +repage -blur 0x8 temp.jpg
convert temp.jpg $1 -resize ${RESOLUTION}x -gravity center -composite -matte "./output/$1-out.jpg"