Skip to content

Instantly share code, notes, and snippets.

View arccoder's full-sized avatar

Akshay Chavan arccoder

View GitHub Profile
@arccoder
arccoder / read-only-dict-1.py
Last active April 12, 2023 23:52
Python: Read only dictionary
class ReadOnlyDict(dict):
def __setitem__(self, key, value):
raise RuntimeError("Modification not supported")
rw_dict = {'key': 'original'}
print('Dict: ' + str(rw_dict))
ro_dict = ReadOnlyDict(rw_dict)
print('ReadOnlyDict: ' + str(ro_dict))
@arccoder
arccoder / cyclic_intersection_pts.py
Last active July 4, 2023 14:57
Straighten a page using OpenCV
def cyclic_intersection_pts(pts):
"""
Sorts 4 points in clockwise direction with the first point been closest to 0,0
Assumption:
There are exactly 4 points in the input and
from a rectangle which is not very distorted
"""
if pts.shape[0] != 4:
return None
import yfinance as yf
data = yf.download('TSLA', start='2021-02-21', end='2021-02-27', interval='1m')
data = data.iloc[:, 0:1]
data.to_csv('in/tsla-7day-1min.csv')
data = yf.download('TSLA', start='2021-02-01', end='2021-02-27', interval='30m')
data = data.iloc[:, 0:1]
data.to_csv('in/tsla-1month-30min.csv')
@arccoder
arccoder / help.txt
Last active January 23, 2021 21:18
Redact word documents using Python
> python redact.py -h
usage: redact.py [-h] -i INPUT -o OUTPUT -p PATTERNS [-r REPLACE] [-c COLOR]
optional arguments:
-h, --help show this help message and exit
-i INPUT, --input INPUT
Path to the document to be redacted
-o OUTPUT, --output OUTPUT
Path to save the redacted document
-p PATTERNS, --patterns PATTERNS
@arccoder
arccoder / pandas-sort-within-groups.py
Created October 2, 2019 22:32
Pandas: Sort within groups
# Load the Pandas libraries with alias 'pd'
import pandas as pd
# Read csv to dataframe
df = pd.read_csv("data.csv")
# Set column types
df['Submission Date'] = pd.to_datetime(df['Submission Date'], format="%Y-%m-%d %H:%M")
print(df)
@arccoder
arccoder / opencv_hough_lines.py
Last active March 1, 2024 12:16
Process the output of cv2.HoughLines from OpenCV using functions that do Polar to Cartesian line conversion, Intersection of Cartesian lines, Line end points on image. https://arccoder.medium.com/process-the-output-of-cv2-houghlines-f43c7546deae
"""
Script contains functions to process the lines in polar coordinate system
returned by the HoughLines function in OpenCV
Line equation from polar to cartesian coordinates
x = rho * cos(theta)
y = rho * sin(theta)
x, y are at a distance of rho from 0,0 at an angle of theta
@arccoder
arccoder / edgedetection1d.m
Last active January 16, 2017 02:35
Edge detection example explained using 1D toy example.
clc; clear all; close all;
% Data Generation
x = 0:10:2000;
y = sigmf(x,[0.1 1000]);
n = rand(1,201)/40 - 0.0125;
f = y;% + n;
fig = figure;
set(fig, 'PaperUnits', 'inches');
set(fig, 'PaperPosition', [0 0 8 2]);
@arccoder
arccoder / kmeans.py
Created October 28, 2016 18:06
K-means Algorithm
import numpy as np
def kmeans(data, numofclasses, options=None):
"""
Calculates the clusters using k-means algorithm and returns cluster labels and centroids
:param data: Data to cluster structured as [Number of observations x Data dimensions(variables)]
:param numofclasses: Number of classes you want to cluster the data into.
:param options: Optional data in dictionary form to overwrite the defaults
max_iterations - int: Maximum number of iterations
@arccoder
arccoder / create_gif_from_images.m
Last active October 30, 2016 23:19
Create gif using MATLAB
imageExt = '.png';
imagefiles = dir(['*' imageExt]);
outfilename = 'gifname.gif';
for n = 1:length(imagefiles)
im = imread(imagefiles(n).name);
[imind,cm] = rgb2ind(im,256);
% DelayTime in seconds
if n == 1
imwrite(imind,cm,outfilename,'gif','Loopcount',inf,'DelayTime',0.7);
@arccoder
arccoder / fastcv_meanshift.cpp
Last active October 5, 2016 00:37
How to use meanshift functionality from FastCV
#include "fastcv.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{