Skip to content

Instantly share code, notes, and snippets.

View punit-naik's full-sized avatar
🎯
Look for success, you'll fail. Strive for excellence, you'll prevail. - Punit

Punit Naik punit-naik

🎯
Look for success, you'll fail. Strive for excellence, you'll prevail. - Punit
  • Bicholim, Goa, India
View GitHub Profile
@punit-naik
punit-naik / atom_clojure_setup.md
Created January 3, 2022 17:25 — forked from jasongilman/atom_clojure_setup.md
This describes how I setup Atom for Clojure Development.

Atom Clojure Setup

This describes how I setup Atom for an ideal Clojure development workflow. This fixes indentation on newlines, handles parentheses, etc. The keybinding settings for enter (in keymap.cson) are important to get proper newlines with indentation at the right level. There are other helpers in init.coffee and keymap.cson that are useful for cutting, copying, pasting, deleting, and indenting Lisp expressions.

Install Atom

Download Atom

The Atom documentation is excellent. It's highly worth reading the flight manual.

@punit-naik
punit-naik / unlock
Created October 7, 2021 18:59
Mount/unmount a bitlocker encrypted partition in read-write mode
#!/bin/bash
sudo mkdir -p /media/bitlocker
sudo mkdir -p /media/bitlockermount
UNMOUNT=false
case "$1" in
-u | --unmount )
UNMOUNT=true
@punit-naik
punit-naik / tika_parser.clj
Created September 20, 2021 07:59
Parsing a document's content using Apache Tika with Clojure
;; Execute the following `lein try` command to get a REPL with the following libraries loaded in it's classpath
;; lein try org.apache.tika/tika-parsers 1.14 org.apache.tika/tika-core 1.14
(import '[org.apache.tika Tika])
(import '[java.nio.file Files])
(import '[java.io File])
(import '[java.io ByteArrayInputStream])
(def tika (Tika.))
(def f-bytes (-> (File. "/path/file.pdf") .toPath Files/readAllBytes))
@punit-naik
punit-naik / tika-parser.clj
Last active October 7, 2021 19:00
Provides functions to extract content from a doc using Tika parsers in Clojure
;; NOTE: Please add [org.apache.tika/tika-parsers "1.25] and [org.apache.tika/tika-core "1.25] in your dependencies
(import '[org.apache.tika.parser AutoDetectParser])
(import '[org.apache.tika.metadata Metadata])
(import '[org.apache.tika.sax BodyContentHandler])
(import '[java.nio.file Files])
(import '[java.io ByteArrayInputStream ByteArrayOutputStream])
(require '[clojure.java.io :as io])
(defn parse-doc
@punit-naik
punit-naik / elasticsearch-scripting-nested-field.sh
Last active January 15, 2021 09:58
Elasticsearch - search for keys inside nested field value, which is a map/json
#!/bin/bash
curl -X GET https://<username>:<password>@<host-url>/<index(es)>/_search?pretty=true -H 'Content-Type: application/json' -d "{\"query\": {\"match_all\":{}}, \"script_fields\": {\"field_keys_prefied_with_a\": {\"script\": {\"lang\": \"painless\", \"source\": \""" Map m = params._source.<nested/map field name>; return (m == null) ? new HashMap() : m.entrySet().stream().filter(e->e.getKey().startsWith(params.prefix)).collect(Collectors.toMap(e->e.getKey(),e->e.getValue())); \""", \"params\": {\"prefix\": \"a\"}}}}, \"size\": 100}"
@punit-naik
punit-naik / round-n.clj
Last active August 3, 2020 13:53
Takes upto `n` non-zero integers after the decimal for a floating point number. This will skip zeros if present just after the decimal
(def round-n
"Takes upto `n` non-zero integers after the decimal for a floating point number
This will skip zeros if present just after the decimal"
(memoize
(fn [num n]
(let [num (double num)
[before-decimal after-decimal] (str/split (str num) #"\.")
n (if (> n (count after-decimal)) (count after-decimal) n)
str-not-zero? (fn [s] (not (zero? (Integer/parseInt s))))]
(Double/parseDouble
@punit-naik
punit-naik / cljs-fullstack-template
Created May 28, 2020 20:09
cljs-fullstack-template
lein new luminus <prj-name> +http-kit +mongodb +swagger +re-frame +shadow-cljs +auth-jwe +cucumber +site
@punit-naik
punit-naik / screen-tearing.txt
Last active May 24, 2020 13:14
Resources to fix screen tearing problems on Ubuntu
1. For firefox - https://askubuntu.com/a/1141380/286994
3. For Intel Display driver - https://www.youtube.com/watch?v=IJeX35wbZY4
2. For NVidia Display Driver - https://www.youtube.com/watch?v=oYWer86A20s
@punit-naik
punit-naik / dev-env-setup.sh
Last active June 26, 2025 18:52
Helps to setup my Development environment
#!/bin/bash
###########################################
# Tried and tested on my Ubuntu 24.04.2 #
###########################################
sudo apt update
echo "### Generic - Apt-Fast"
@punit-naik
punit-naik / datomic.schema_dump.clj
Created January 23, 2020 10:58 — forked from jeroenvandijk/datomic.schema_dump.clj
(A) method to dump a datomic database schema
(ns datomic.schema-dump
(:require
[datomic.api :as d]
[clojure.pprint]))
(defmethod clojure.pprint/simple-dispatch datomic.db.DbId [v] (pr v))
(defmethod clojure.pprint/simple-dispatch datomic.function.Function [v] (pr v))
(defn database-url [name]
(str "datomic:mem://" name))