Skip to content

Instantly share code, notes, and snippets.

View kishorek's full-sized avatar

Kishore Kumar Uthirapathy kishorek

View GitHub Profile
@kishorek
kishorek / poetry_req.py
Created January 10, 2024 07:35
Export poetry dependencies as requirements.txt
def export_poetry_dependencies(pyproject_path, requirements_path):
# Flag to check if we are within the dependencies section
in_dependencies = False
with open(pyproject_path, "r") as pyproject_file, open(
requirements_path, "w"
) as requirements_file:
for line in pyproject_file:
# Check for the start of the dependencies section
if line.strip() == "[tool.poetry.dependencies]":
@kishorek
kishorek / gist:c2b0d28dc05ceb5d77cd11a49879108e
Created October 12, 2023 13:32
Mongo - Convert a string into number and use in a find query
{$expr:{$gt:[{$toInt:"$field"},1]}}
@kishorek
kishorek / gist:417aef863868ae3f15d325a3880437ad
Created October 12, 2023 13:24
Mongo - Get distinct values of a field
[
{
$unwind: {
path: '$field_name',
preserveNullAndEmptyArrays: true
}
},
{
$group: {
_id: null,
@kishorek
kishorek / db_utils.py
Created March 16, 2023 13:26
Elastic Search + Mongo in Python
from pymongo import MongoClient
from elasticsearch import Elasticsearch
class MongoElasticCache:
def __init__(self, mongo_uri, mongo_db, mongo_collection, es_host, es_index):
self.mongo_client = MongoClient(mongo_uri)
self.mongo_db = self.mongo_client[mongo_db]
self.mongo_collection = self.mongo_db[mongo_collection]
self.es_client = Elasticsearch([es_host])
@kishorek
kishorek / explore_json.py
Created February 15, 2022 05:25
Print all the keys in JSON
import json
"""
This script will print all the JSON keys present in a JSON
"""
FILE = "<file_path here>"
DIVIDER = "."
ARRAY_INDICATOR = "[]"
@kishorek
kishorek / exportImportJavaCert.md
Last active September 15, 2021 06:33 — forked from jeffsheets/exportImportJavaCert.md
Bash Commands to Export Cert and Import into Java Truststore

Command to export a cert from a website to a .cer file (example uses google.com) Tested with git-bash shell on Windows. Assume similar on Mac?

openssl s_client -servername google.com -connect google.com:443 </dev/null 2>/dev/null | openssl x509 -inform PEM -outform DER -out google.com.cer

Command to import into local java truststore (use your own location of JAVA_HOME)

"$JAVA_HOME"/bin/keytool -keystore "$JAVA_HOME"/jre/lib/security/cacerts -importcert -alias google.com -file google.com.cer

@kishorek
kishorek / jsoneditor.html
Created May 20, 2021 14:24
Quick Simple JSON Editor HTML
<!DOCTYPE html>
<html lang="en">
<head>
<!-- when using the mode "code", it's important to specify charset utf-8 -->
<meta charset="utf-8" />
<link
href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.4.1/jsoneditor.min.css"
rel="stylesheet"
type="text/css"
@kishorek
kishorek / tk_save_open_files.py
Created October 23, 2020 12:43
Open or Save files using system dialog in Python
from tkinter.filedialog import askopenfilename, asksaveasfile
file_path = askopenfilename(title = "Select the image", filetypes = (("jpg", "*.jpg"), ("png", "*.png")))
files = [('Image File', '*.jpg')]
savefile = asksaveasfile(filetypes = files, defaultextension = files)
@kishorek
kishorek / PDFFormReader.java
Created March 12, 2019 10:09
Read PDF Acro Forms
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField;
import java.io.IOException;
import java.util.List;
public class PDFFormReader {
@kishorek
kishorek / UIView+Subviews.swift
Created November 9, 2017 06:15
Remove all subviews from UIView
extension UIView {
// Recursive remove subviews and constraints
func removeSubviews() {
self.subviews.forEach({
if !($0 is UILayoutSupport) {
$0.removeSubviews()
$0.removeFromSuperview()
}
})