Skip to content

Instantly share code, notes, and snippets.

View dgaitsgo's full-sized avatar

David Gaitsgory dgaitsgo

View GitHub Profile
@dgaitsgo
dgaitsgo / match-histogram.py
Created November 7, 2023 01:25
Histogram matching open-cv
import cv2
# Load the reference and target images
reference_image = cv2.imread('reference_image.jpg')
target_image = cv2.imread('target_image.jpg')
# Convert to LAB color space (preserves color information)
reference_image_lab = cv2.cvtColor(reference_image, cv2.COLOR_BGR2LAB)
target_image_lab = cv2.cvtColor(target_image, cv2.COLOR_BGR2LAB)
@dgaitsgo
dgaitsgo / next-comp
Created July 13, 2022 03:08
New React/CSS Module TS Component
#!/bin/bash
if [ "$1" == "" ]; then
echo "Missing $component name"
exit 0
fi
for comp in "$@"
do
if [ ! -d ./$comp ]; then
@dgaitsgo
dgaitsgo / fragment.glsl
Created April 25, 2022 02:27
Basic ThreeJS TypeScript setup
varying vec2 vUv;
void main() {
gl_FragColor = vec4(vUv, 0.0, 1.);
}
initImageHoverListeners = (image: HTMLImageElement): void => {
const imageButtonId = 'bai-image-btn-container'
const imageLink = this.getImageContainer(image)
const buttonContainer = this.getButtonContainer('image')
if (imageLink) {
const wrapper = imageLink.parentNode
wrapper?.addEventListener('mouseover', (e) => {
if (e.target === image) {
document.getElementById(imageButtonId)?.remove()
@dgaitsgo
dgaitsgo / auto-check.js
Created February 16, 2020 03:07
Auto-check swasdfasd
const blackListedRouterError =
Number(
[...document.querySelectorAll("th")]
.filter(a => a.textContent.includes("[FILTERED] blacklisted"))
[0]
.nextSibling
.innerText
) > 0
@dgaitsgo
dgaitsgo / Polynomial-no-parens.ne
Last active October 13, 2019 15:42
Single variable polynomial parser without parens
@{%
const filter = d => d.filter(dp => dp)
%}
main ->
_ add_sub _ {% filter %}
| _ add_sub _ "=" _ add_sub _ {% filter %}
exp ->
add_sub _ "^" _ exp
@dgaitsgo
dgaitsgo / number.ne
Created October 13, 2019 09:59
Improved canonical nearley number parser
number ->
int {% id %}
| float {% id %}
| "-" int {% function(d) { return(d[0] + d[1]) } %}
| "-" float {% function(d) { return(d[0] + d[1]) } %}
float ->
int "." [0-9]:+ {% function(d) { return(d[0] + d[1] + d[2].join("")) } %}
| "." [0-9]:+ {% function(d) { return(d[0] + d[1].join("")) } %}
@dgaitsgo
dgaitsgo / polynomial.ne
Created October 10, 2019 04:58
2nd Degree Polynomial Nearley Parser
main ->
polynom
polynom ->
_ add_sub _
| _ add_sub _ "=" _ add_sub _
parens ->
"(" _ add_sub _ ")"
| term
@dgaitsgo
dgaitsgo / get_cdc_measles_data.py
Created August 6, 2019 10:19
Fetching and parsing CDC for cumulative year to date total measles cases by state, territory and region
# coding: utf-8
# In[30]:
import os
import json
from contextlib import closing
from bs4 import BeautifulSoup
import csv
@dgaitsgo
dgaitsgo / cycleIndices.js
Created March 16, 2019 12:32
Cycle Indices
// down
const nextIndex = ( currIdx - 1 + elems.length ) % elems.length
// up
const nextIndex = ( currIdx + 1) % elems.length