Skip to content

Instantly share code, notes, and snippets.

View InputBlackBoxOutput's full-sized avatar
🐮

Rutuparn Pawar InputBlackBoxOutput

🐮
  • Boston, MA
View GitHub Profile
// FizzBuzz using Arduino
// Author: @InputBlackBoxOutput
// Written on 20 Oct 2020
// No additional components & connections required.
// Just connect your Arduino to your PC
#define BAUDRATE 9600
#define LOOP_DELAY 700
@InputBlackBoxOutput
InputBlackBoxOutput / minimax_chess.py
Created June 18, 2021 12:03
Chess engine using minimax with alpha beta pruning
# Chess bot
# Caution: This code is not optimized hence takes tremendous amount of time to run
# If you are looking for an open source chess engine, try stockfish or sunfish
# Code originally written by AnthonyASanchez
# Modified by Rutuparn Pawar (InputBlackBoxOutput) to implement parallel processing
import chess
import sys
import random
@InputBlackBoxOutput
InputBlackBoxOutput / video_splitter.py
Last active October 2, 2021 19:27
A Python wrapper for ffmpeg that allows you to split video files
#!/usr/bin/env python
# Source: https://github.com/c0decracker/video-splitter
import csv
import subprocess
import math
import json
import os
import shlex
from optparse import OptionParser
@InputBlackBoxOutput
InputBlackBoxOutput / timeseries_plot.py
Created August 6, 2021 04:06
Python program to plot timeseries data stored in a CSV file. Format: <timestamp>,<value>\n
import sys
try:
import matplotlib.pyplot as plt
except ModuleNotFoundError:
print("Error: Module was not found")
sys.exit()
except:
print("Something went wrong while importing module/s \n")
sys.exit()
@InputBlackBoxOutput
InputBlackBoxOutput / image_data_augmentation.py
Created August 6, 2021 04:23
Image data augmentation using openCV
# Image Data augmentation
# Use this program to perform image data augmentation in case you do not want to use a generator for some reason
# Check out ImageDataGenerator if you are looking for a generator in TensorFlow: https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image/ImageDataGenerator
import cv2
import numpy as np
import glob
import hashlib
search_pattern = "images/*.jpg"
@InputBlackBoxOutput
InputBlackBoxOutput / dulicate_entries.py
Created August 17, 2021 06:25
Python program to remove duplicate entries in a text or CSV file
with open("text.txt", 'r') as infile:
data = infile.read().splitlines()
# print(data)
with open("text.txt", 'w') as outfile:
for each in list(set(data)):
outfile.write(each + '\n')
@InputBlackBoxOutput
InputBlackBoxOutput / csv_json.py
Last active September 6, 2021 17:12
Convert a text file or CSV file into a JSON file
import json
seperator = ','
with open("text.txt", encoding='utf-8') as file:
data = file.read().splitlines()
print(len(data))
json_object = {}
for i, each in enumerate(data):
@InputBlackBoxOutput
InputBlackBoxOutput / word_cloud.py
Created September 7, 2021 15:53
Create a word cloud using the 'wordcloud' module
from wordcloud import WordCloud
import matplotlib.pyplot as plt
def plot_wordcloud(text, mask=None, max_words=200, max_font_size=100, figure_size=(12.0,12.0),
title = None, title_size=18, image_color=False):
wordcloud = WordCloud(background_color='white',
max_words = max_words,
max_font_size = max_font_size,
random_state = 42,
@InputBlackBoxOutput
InputBlackBoxOutput / convert_delimiter.py
Created September 10, 2021 10:42
Python program for changing the delimiter of a CSV file
import re, sys
input_file ="input.csv"
output_file ="output.csv"
input_file_delimiter = ';'
output_file_delimiter = ','
output = []
with open(input_file) as f_input:
lines = f_input.read().splitlines()
@InputBlackBoxOutput
InputBlackBoxOutput / detect_edges.py
Last active January 27, 2022 06:21
Canny edge detector with threshold calculation using Otsu's method
import cv2
import numpy as np
def calculate_threshold(img):
hist, bin_edges = np.histogram(img, bins=256)
bin_mids = (bin_edges[:-1] + bin_edges[1:]) / 2.
weight1 = np.cumsum(hist)
weight2 = np.cumsum(hist[::-1])[::-1]
mean1 = np.cumsum(hist * bin_mids) / weight1