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 / 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 / ring_buffer
Last active August 29, 2015 14:14 — forked from mtambos/ring_buffer
import numpy as np
class RingBuffer(np.ndarray):
'A multidimensional ring buffer.'
def __new__(cls, input_array):
obj = np.asarray(input_array).view(cls)
return obj
// http://is.gd/gWewbP
extern mod extra;
use extra::treemap::TreeMap;
use extra::json::ToJson;
use extra::serialize::Decodable;
use json = extra::json;
// structs are required for decoding a JSON object into a Rust object
#[deriving(Decodable)]