Skip to content

Instantly share code, notes, and snippets.

@sonnyksimon
sonnyksimon / lastDayOfMonth.jq
Last active April 30, 2024 11:19
example input: "2024-01-01"
(strptime("%Y-%m-%d") | mktime | strftime("%Y-%m-28") | strptime("%Y-%m-%d") | mktime + (4 * 24 * 60 * 60)) | (. - ((strftime("%d") | tonumber) * 24 * 60 * 60) | todate)
@sonnyksimon
sonnyksimon / _string-similarity.txt
Last active February 23, 2024 04:18
string similarity
Can we implement all of these algorithms?
Similarity Algorithms:
- Cosine
- Fuzzy Wuzzy
- Jaccard
- Jaro
- Jaro Winkler
- Q-gram
- Sørensen DIce
@sonnyksimon
sonnyksimon / yaml2json
Created October 1, 2023 07:26
yaml2json: Compact script for yaml to json conversion
#!/usr/bin/env python
"""yaml2json: Compact script for yaml to json conversion"""
import yaml
import json
import sys
args = [open(x,'r') for x in sys.argv[1:]]
args = [sys.stdin.read(), *args] if not sys.stdin.isatty() else args
files = [yaml.safe_load(y) for y in args]
#!/usr/bin/sh
# yaml2json
cat myFile.yml | python -c 'import yaml; import json; import sys; f = sys.stdin.read(); conf = yaml.safe_load(f); out = json.dumps(conf, separators=(",",":")); print(out)'
@sonnyksimon
sonnyksimon / parseCSV.jq
Created September 7, 2022 19:03
jq --slurp --raw-input
split("\n")
| (
.[0]
| split(",")
) as $head
| .[1:]
| map
(
split(",")
| to_entries
@sonnyksimon
sonnyksimon / google-spending.js
Created August 29, 2022 03:31
Calculate Google Spending from Chrome Console
// Google Activity URL: https://pay.google.com/gp/w/u/0/home/activity
// add the id `x-payments-hist` to the tbody
// containing the payments after viewing
// all records (i.e. it says "No more transactions")
let payments = [];
let rows = document.querySelectorAll("#x-payments-hist > tr");
rows.forEach(function(node) {
let r = {};
@sonnyksimon
sonnyksimon / applyjq.py
Last active June 20, 2022 16:39
Python JQ in windows
import subprocess
import json
def applyjqtxt(filter, text):
echo = subprocess.Popen(('echo', text), stdout=subprocess.PIPE)
output = subprocess.check_output(('jq', filter), stdin=echo.stdout)
echo.wait()
return output
def applyjq(filter, data):
@sonnyksimon
sonnyksimon / isNotANumber.js
Created January 13, 2021 19:02
js isNotANumber
const isNotANumber = (v) => {
const n = Number(v);
return n !== n;
}
export default isNotANumber;
@sonnyksimon
sonnyksimon / probability.py
Last active January 13, 2021 19:13
Calculate the probability of atleast one match after x tries
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# SPDX-License-Identifier: MIT
#
""" Calculate the probability of atleast one match after x tries"""
from __future__ import print_function
import argparse
co3325
co3326
co3354
co3355