Skip to content

Instantly share code, notes, and snippets.

View urigoren's full-sized avatar

Uri Goren urigoren

View GitHub Profile
@urigoren
urigoren / heic2jpg.py
Created November 10, 2023 15:45
A python script to convert all HEIC photos in a folder to JPG format
from PIL import Image
from pathlib import Path
from pillow_heif import register_heif_opener
from tqdm import tqdm
from argparse import ArgumentParser
register_heif_opener()
def main(params):
print("Converting HEIC files to JPG")
files = list(Path(".").glob("*.heic")) + list(Path(".").glob("*.HEIC"))
import openai
from decouple import config
openai.api_key = config("OPENAI_KEY")
YES_TOKEN = frozenset([5297, 3763, 3363, 8505, 3363, 3763, 43335, 3763, 21560])
NO_TOKEN = frozenset([2949, 645, 1400, 3919, 1400, 645, 15285, 645, 8005])
def yes_or_no(txt: str)->bool:
response = openai.Completion.create(
model="text-davinci-003",
@urigoren
urigoren / wsl2_reclaim.txt
Created January 14, 2023 13:48
How to reclaim WSL2 space
wsl --shutdown
diskpart
# open window Diskpart
select vdisk file="C:\Users\ugore\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit
from collections import defaultdict
from itertools import product
from scipy import sparse
from sklearn.base import TransformerMixin
class InteractionBySplit(TransformerMixin):
"""
Takes a sparse matrix as input, and an index to split by, and returns all possible interactions before and after that index.
"""
def __init__(self, split_index,*args,**kwargs):
@urigoren
urigoren / bgprocess.py
Last active February 3, 2022 09:51
Run a python process in the background
from pathlib import Path
import subprocess, sys
def bgprocess(p:Path, *args):
python = sys.executable
if not isinstance(p, Path):
p = Path(p)
p = p.absolute()
return subprocess.Popen([python, p.name]+list(args), cwd = str(p.parent), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
@urigoren
urigoren / ConditionedTextClassifier.py
Last active July 10, 2021 14:05
Bag-of-words baseline for conditional text classification
from copy import deepcopy as clone
from sklearn.base import ClassifierMixin
from sklearn.pipeline import Pipeline
class ConditionedTextClassifier(ClassifierMixin):
def __init__(self, conditions, model, condition_sep=' <s> '):
self.condition_sep=condition_sep
self.conditions = {}
for c in conditions:
self.conditions[c] = clone(model)
@urigoren
urigoren / config_reader.py
Created May 1, 2021 19:41
A simple cascading config reader
import os, sys, json
from pathlib import Path
class ConfigReader:
def __init__(self, default=None, **kwargs):
self.default=default
self.py_file = Path(os.path.join(os.getcwd(), sys.argv[0])).absolute()
p = self.py_file.parent
found_config_json = []
while p!=Path('/'):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@urigoren
urigoren / .htaccess
Last active February 7, 2021 13:00
Call python via command line from php
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!index\.php).+)$ /index.php?py=$1 [NC,L,QSA]
import sys, os
import streamlit as st
def file2page_name(fname):
return fname.replace('.py', '').split("_", 1)[1].title()
sys.path.append("..")
page_files = dict()