Skip to content

Instantly share code, notes, and snippets.

View tejashah88's full-sized avatar

Tejas Shah tejashah88

View GitHub Profile
@tejashah88
tejashah88 / lagrange-solver-two-constraints.py
Created October 30, 2019 23:49
A min/max finder based on Lagrange Multipliers with two constraints
from sympy import *
x, y, z, l1, l2 = symbols('x y z l1 l2')
f = x + y + 3*z
g = x - y + z
k1 = 2
h = x + 2*z**2
k2 = 59
@tejashah88
tejashah88 / lagrange-solver-one-constraint.py
Last active October 30, 2019 23:40
A min/max finder based on Lagrange Multipliers with one constraint
from sympy import *
from sympy.abc import x, y, z, l
f = x**2 + y**2 + z**2
g = x**4 + y**4 + z**4
k = 9
grad = lambda fn: Matrix([fn.diff(x), fn.diff(y), fn.diff(z)]).transpose()
# grad(f) = lambda * grad(g)
@tejashah88
tejashah88 / ros-install-ubuntu-cosmic.sh
Last active January 9, 2020 11:02
Installing ROS on an Kubuntu Cosmic (18.10) system by building from source
# Source: http://wiki.ros.org/melodic/Installation/Source
function install_ros_first_time() {
# Install bootstrap dependencies
sudo apt-get install python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential -y
# Initialize rosdep
sudo rosdep init
rosdep update
@tejashah88
tejashah88 / RainbowClock.m
Created May 12, 2019 13:23
A rainbow analog clock animation in MATLAB for my ENGIN-136 class.
% Final Project: Rainbow Analog Clock
% Author: Tejas Shah
% Class: ENGIN-136 - Intro to MATLAB
% Clear any vars and current figure and show it on top of screen
clear, clf, shg
% Setup drawing board for clock
axis([-1.1 1.1 -1.1 1.1]);
axis square
@tejashah88
tejashah88 / robot-mousemove-fix.kt
Created November 21, 2018 23:47
Fix for Java's Robot.mouseMove when accounting for High DPI Screens + Mathematical error analysis for modeling how the original mouseMove function is affected.
/* Robot.betterMouseMove is a function that's meant to fix Robot.mouseMove when dealing with Windows's
display scaling in order to make text easier to see. The 'scaleFactor' is the actual scaling factor
as a float > 1.0f.
This is the error vector field that represents the error caused by Robot.mouseMove in which to move
in the x and y direction towards its destination. It's not that useful in hindsight, but kind of cool
that one can model the error as a mathematical function.
"Error" Vector Field: F(x, y) = f(x, y) * i + g(x, y) * j
f(x, y) = (-x + t_x) / (width - t_x)
@tejashah88
tejashah88 / raspberry-pi-opencv-python-setup.sh
Last active November 16, 2018 11:23
Quick & dirty script to install Python 3 OpenCV libraries with main & contrib modules
# Get latest packages
sudo apt-get update && sudo apt-get dist-upgrade -y
sudo apt-get update && sudo apt-get upgrade -y
# Install needed packages to perform common I/O image/video operations and/or math calculations
sudo apt-get update
sudo apt-get install libhdf5-dev libhdf5-serial-dev libharfbuzz-dev liblapack-dev libcblas-dev libwebp-dev \
libilmbase-dev libopenexr-dev libgstreamer1.0-dev libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libatlas-base-dev \
gfortran libgstreamer1.0-dev libgtk-3-0 -y
@tejashah88
tejashah88 / libvexhelper.c
Created October 13, 2018 12:23
A (small) helper library for handling common tasks when programming in RobotC.
/* vexhelper library version 0.2 */
/*
Dictionary:
-variable -> a name which can contain a value (i.e 6, "hello", 3.14)
-constant -> a variable whose value cannot be modified
-function -> a block of reusable code
Description:
@tejashah88
tejashah88 / comsc-165-common-lib.c
Last active October 16, 2018 06:02
List of common functions used in COMSC-165.
int readInt();
char readChar();
float readFloat();
string readWord();
string readLine();
void swapInt(int &a, int &b);
void swapChar(char &a, char &b);
void swapFloat(float &a, float &b);
void swapString(string &a, string &b);
from time import time as stopwatch
def is_prime(n):
if n in [2, 3]: # shortcut for if n equals 2 or 3
return True
if n % 2 == 0 or n < 2: # skip even numbers, since they are not prime anyways
return False
# only iterate the odd numbers from 3 to the nearest whole number of sqrt(n), skipping even numbers
for i in range(3, round(n ** 0.5) + 1, 2):
if n % i == 0: # if this conditional is true, n isn't prime
@tejashah88
tejashah88 / numerical_integration.py
Last active September 25, 2018 16:18
numerical integration + error analysis in python 3 (Source: http://www2.engr.arizona.edu/~edatools/Phys305/integration.html)
def check_params(h, nbins):
assert type(nbins) == int
assert h > 0
get_delta = lambda a, b, nbins: float(b - a) / nbins
def integLeft(a, b, f, nbins):
"""Return the integral from a to b of function f using the left hand method"""
h = get_delta(a, b, nbins)
assert type(nbins) == int