Skip to content

Instantly share code, notes, and snippets.

View ThePyProgrammer's full-sized avatar
💻
Dying of Multiple Project Setting and Abandoning Disorder (MPSAD)

Prannaya Gupta ThePyProgrammer

💻
Dying of Multiple Project Setting and Abandoning Disorder (MPSAD)
View GitHub Profile
@ThePyProgrammer
ThePyProgrammer / StringBuilder.kt
Last active April 2, 2021 17:27
StringBuilder extension with Kotlin
fun StringBuilder.write(
vararg objects: Any?,
sep: String = "",
end: String = "",
prefix: String = "",
postfix: String = ""
) {
append(objects.joinToString(separator = sep, prefix = prefix, postfix = postfix)+end)
}
@ThePyProgrammer
ThePyProgrammer / AndroidCalendar.java
Last active April 4, 2021 04:01
Implementing Calendar intent
// Begin code with LocalDate object date and LocalTime objects begin and end, and String objects title, content, location
Boolean allDay = begin.equals(LocalTime.of(0, 0)) && end.equals(LocalTime.of(23, 59))
LocalDateTime startTime = date.atTime(begin)
LocalDateTime endTime = date.atTime(end)
Calendar startCal = Calendar.getInstance()
@ThePyProgrammer
ThePyProgrammer / struct.kt
Last active May 24, 2021 15:58
A Logic-Based Declaration to integrate JavaScript or Swift Code easily into Kotlin.
infix fun <T, R> T.`=`(other: R) = this to other
class Object<T, R>(vararg vals: Pair<T, R>): HashMap<T, R>(hashMapOf(*vals)) {
/**
* duplicates the let keyword in JavaScript
* declare multiple keywords in the object
*/
fun let(vararg pairs: Pair<T, R>) {
putAll(hashMapOf(*pairs))
}
@ThePyProgrammer
ThePyProgrammer / SuperArray.cs
Created June 1, 2021 06:01
A Simplified Array System written in C#, made for Functionality.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace App
{
class SuperArray<R> : IEnumerable<R>
{
R[] BaseArray;
@ThePyProgrammer
ThePyProgrammer / Point.cpp
Last active June 5, 2021 17:42
A Point class in CPP.
//
// Created by ThePyProgrammer on 5/6/2021.
//
#include <cmath>
#include "Point.h"
#include <limits>
Point::Point(double x, double y) {
@ThePyProgrammer
ThePyProgrammer / commit.sh
Created July 18, 2021 14:28
A simple shell script to run commits in a single line
# First let's check the status
git status
# We now add the file as in the arguments
for i in $(seq 2 $#);
do git add ${!i};
done
# Commit files based on first argument
git commit -m "$1"
@ThePyProgrammer
ThePyProgrammer / convolution.py
Last active December 22, 2021 03:15
2D Convolution of Image using a complex Numpy algorithm with constant speed-up.
import numpy as np
def convolve(image, kernel):
# We start off by defining some constants, which are required for this code
kernelH, kernelW = kernel.shape
imageH, imageW = kernel.shape
h, w = imageH + 1 - kernelH, imageW + 1 - kernelW
# filter1 creates an index system that calculates the sum of the x and y indices at each point
# Shape of filter1 is h x kernelW
@ThePyProgrammer
ThePyProgrammer / pearson.py
Last active August 22, 2021 17:28
Computing the Pearson Correlation Coefficient in NumPy, without any involvement of SciPy.
import numpy as np
# Functions I painstakingly researched and coded with 2 shots of coffee at 3 am
def gamma(n):
"""
A Simplified Gamma Function for "powers" of 1/2
Gamma Function for Integers are given by: Γ(n) = (n-1)!
Gamma Function for Values ending with 1/2: Γ(n) = 0.5 * 1.5 * ... * (n-1) * √(π)
@ThePyProgrammer
ThePyProgrammer / image.py
Last active September 14, 2021 08:58
An Image Class for simplistic processing of images.
import numpy as np
import matplotlib.pyplot as plt
import cv2
from skimage.color import rgb2gray, gray2rgb
from skimage import filters
from skimage.transform import rescale, resize, downscale_local_mean, swirl
from skimage.filters import threshold_otsu, threshold_local, try_all_threshold
import skimage.io as skio
from PIL import Image, ImageOps
@ThePyProgrammer
ThePyProgrammer / panda.py
Created September 14, 2021 09:01
A utitlity function list that can allow simpler code.
import requests
import pandas as pd
import re
from io import StringIO
def read_csv(loc, *args, **kwargs):
if re.search(r"[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)", loc):
return read_csv(requests.get(loc, allow_redirects=True).content, *args, **kwargs)
loc = loc.strip("\n")
if re.search(r"[\n:<>\"/\|?*]", loc):