Skip to content

Instantly share code, notes, and snippets.

@jcrubino
jcrubino / server.py
Last active June 16, 2023 06:42
Simple Flask Web Server for Image Captioning and Document Embedding Generation
import base64
import logging
from io import BytesIO
import torch
import torch.nn.functional as F
from flask import Flask, request
from PIL import Image
from torch import Tensor
from transformers import AutoModel, AutoTokenizer
@jcrubino
jcrubino / video_prep.sh
Last active May 9, 2023 19:15
Bash File to Prepare a Folder of Videos
#!/bin/bash
# Sanitize all filenames in the current directory using detox
for file in *
do
new_file=$(detox "$file")
if [ -n "$new_file" ] && [ "$new_file" != "$file" ] && [ ! -e "$new_file" ]
then
mv "$file" "$new_file"
fi
@jcrubino
jcrubino / wrapper.py
Created March 24, 2012 20:22
wraps IMDB class data function to provide fully complaint json
# JSON IMDbPY class wrapper
# Goal: wraps IMDB class data function to provide fully complaint json
# author: james , rubino <at> gmail , com
# note: contains wrapper and randomized test cases
from random import randint as r
import json
import imdb
ia = imdb.IMDb()
@jcrubino
jcrubino / run_python_script_in_conda_env.bat
Created June 4, 2021 00:35 — forked from maximlt/run_python_script_in_conda_env.bat
Run a Python script in a conda environment from a batch file
@echo OFF
rem How to run a Python script in a given conda environment from a batch file.
rem It doesn't require:
rem - conda to be in the PATH
rem - cmd.exe to be initialized with conda init
rem Define here the path to your conda installation
set CONDAPATH=C:\ProgramData\Miniconda3
rem Define here the name of the environment
@jcrubino
jcrubino / GIST_Travelling_Salesman_problem.ipynb
Created May 3, 2021 05:19 — forked from vaclavdekanovsky/GIST_Travelling_Salesman_problem.ipynb
Solving Travelling Salesman problem using genetic algorithm
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jcrubino
jcrubino / array_operations.py
Created May 2, 2021 18:11
rotation of arrays
def rotate_array_right(array, n):
length = len(array)
remainder = n % length
if remainder == 0:
return array
temp_array = array[0:remainder]
return array[remainder:] + temp_array
@jcrubino
jcrubino / circular_buffer.py
Last active May 2, 2021 17:07
Circular Buffer
class RingBuffer:
index = 0
value = None
def __init__(self, length):
# create buffer using dequeue
self.buffer = deque([], length)
# establish end index number
self._eix = length-1
from bs4 import BeautifulSoup
from requests import get
import json
import re
import emoji
css = "script"
@jcrubino
jcrubino / def_fan.py
Last active December 11, 2015 09:59
example of using gevent coroutines inside a function. Uses pylast and gevent for network calls to last.fm
def define_fan(fan):
pool = Pool(4)
try:
book = {}
def name(fan):
book['name'] = fan.item.get_name()
def get_age(fan):
book['age'] = fan.item.get_age()