Skip to content

Instantly share code, notes, and snippets.

@CoderPrans
CoderPrans / generate-tithis.js
Created February 19, 2024 08:21
a sample application of generator functions to iterate indefinitely yet yield a definite result.
// import astronomy-engine
let astronomy = require('astronomy-engine');
let tithis = [ "Shukl Prti. (Br 1)", "Shukl Dwit. (Br 2)", "Shukl Trit. (Br 3)", "Shukl Catu. (Br 4)", "Shukl Panch. (Br 5)", "Shukl Sast. (Br 6)", "Shukl Sapt. (Br 7)", "Shukl Asht. (Br 8)", "Shukl Nava. (Br 9)", "Shukl Dasm. (Br 10)", "Shukl Ekad. (Br 11)", "Shukl Dwad. (Br 12)", "Shukl Tryod. (Br 13)", "Shukl Caturd. (Br 14)",
"Purnima (Full Moon)",
"Krshn Prti. (Da 1)", "Krshn Dwit. (Da 2)", "Krshn Trit. (Da 3)", "Krshn Catu. (Da 4)", "Krshn Panch. (Da 5)", "Krshn Sast. (Da 6)", "Krshn Sapt. (Da 7)", "Krshn Asht. (Da 8)", "Krshn Nava. (Da 9)", "Krshn Dasm. (Da 10)", "Krshn Ekad. (Da 11)", "Krshn Dwad. (Da 12)", "Krshn Tryod. (Da 13)", "Krshn Caturd. (Da 14)",
"Amavasya (New Moon)"];
function getTithi(date) {
let moonFactor = astronomy.MoonPhase(date) / 12;
@CoderPrans
CoderPrans / binary-tree.clj
Created July 29, 2021 13:55
Binary Tree implementation in Clojure
;; {:n 0
;; :l {:n 1 :l nil :r nil}
;; :r {:n 2 :l nil :r {:n 3
;; :l nil
;; :r nil}}}
;; 0
;; / \
;; 1 2
;; / \ / \
;; nil nil nil 3
@CoderPrans
CoderPrans / get-sicp.clj
Last active July 13, 2021 21:11
ba.bash.ka script to download SICP
#!/usr/bin/env bb
(require '[babashka.curl :as curl])
(def sicp-url "https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/")
(def pages (map #(str "book-Z-H-" % ".html" ) (rest (range 39))))
(def data (map #(vector (str sicp-url %) %) pages))
@CoderPrans
CoderPrans / json-viewer.js
Last active August 25, 2023 15:52
A Min browser's userscript that pretty-prints raw JSON for slightly better view
// ==UserScript==
// @name JSON Viewer
// @match *
// @run-at document-start
// ==/UserScript==
let pretags = document.querySelectorAll(
'[style="word-wrap: break-word; white-space: pre-wrap;"]',
);