Skip to content

Instantly share code, notes, and snippets.

View sumanthratna's full-sized avatar
♥️
418 I'm a teapot

Sumanth Ratna sumanthratna

♥️
418 I'm a teapot
View GitHub Profile
@sumanthratna
sumanthratna / install-python.bash
Created October 5, 2020 13:46
How to install Python 3 on Linux without sudo access.
# adapted from https://web.archive.org/save/https://randomwalk.in/python/2019/10/27/Install-Python-copy.html
wget https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tgz
tar zxfv Python-3.6.10.tgz
rm Python-3.6.10.tgz
find ./Python-3.6.10/Python -type d | xargs chmod 0755
cd Python-3.6.10
./configure --prefix=$PWD/Python-3.6.10/Python
make
make install
export PATH=$CWD:$PATH # adds python3.6 to PATH
@sumanthratna
sumanthratna / tf2_random_index.py
Last active May 25, 2020 23:41
Randomly select a value from a Python list in TensorFlow 2.
import tensorflow as tf
my_list = ['item1', 'item2', 'item3']
index = tf.random.uniform(
[],
maxval=len(my_list),
dtype=tf.int32
)
@sumanthratna
sumanthratna / user_icon.py
Last active May 1, 2020 00:28
Generate a macOS user icon that blends in with the login or desktop background.
import numpy as np
from PIL import Image
sub = np.abs(np.array(Image.open('LESGO.png').convert('RGB')) - np.array(Image.open('day.png').convert('RGB')))
mask = np.zeros((sub.shape[0], sub.shape[1]))
sub_gs = np.array(Image.fromarray(sub).convert('L'))
mask[sub_gs > 0] = 1
final = np.array(Image.open('day.png').convert('RGB'))
final[mask == 0] = [0, 0, 0]
Image.fromarray(final).save('final.png')
@sumanthratna
sumanthratna / triplab.R
Last active February 8, 2020 17:44
R code for generating the graph for the Trip Lab in AP Calculus AB.
library("ggplot2")
library("ggalt")
odo <- data.frame(time = seq(0, 600, 15), speed = c(0, 5.866666667, 5.866666667, 11.73333333, 33.73333333, 30.8, 33.73333333, 7.333333333, 45.46666667, 48.4, 45.46666667, 30.8, 32.26666667, 55.73333333, 55.73333333, 0, 0, 48.4, 58.66666667, 45.46666667, 45.46666667, 16.13333333, 33.73333333, 74.8, 73.33333333, 70.4, 60.13333333, 45.46666667, 48.4, 57.2, 55.73333333, 49.86666667, 46.93333333, 30.8, 35.2, 33.73333333, 30.8, 35.2, 30.8, 30.8, 27.86666667))
ggplot(odo, aes(odo$time, odo$speed)) + geom_point(aes(x = time, y = speed), stat = "identity") + ggtitle("Speed of a Car Over a 10 Minute Interval") + xlab("Time (s)") + ylab("Speed (ft/s)") + geom_smooth() + geom_xspline() + scale_x_continuous(breaks = round(seq(min(odo$time), max(odo$time), by = 30), 1)) + scale_y_continuous(breaks = round(seq(min(odo$speed), max(odo$speed), by = 5), 1))
lhs = 30*sum(odo$speed[seq(1, 40, 2)])
rhs = 30*sum(odo$speed[seq(3, 41, 2)])
@sumanthratna
sumanthratna / ibet-graphs.R
Last active February 8, 2020 17:45
Code to generate graphs for our IBET paper, "Road Salt: at Fault? The Effect of Chloride Concentration on the Mass of Ambystoma maculatum Egg Masses"
# ourdata is data we collected (from the 2018-2019 school year)
ourdata <-
data.frame(
chloride = c(
1.233333333,
0.866666667,
2.8,
1,
1.2,
0.6,
@sumanthratna
sumanthratna / send_msg.py
Last active July 22, 2019 01:09
A Python script to send messages from a GMail account to an email account or phone number.
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
Type = input("Enter 1 for eMail, 2 for SMS: ")
toaddr = 0
if Type == '1':
toaddr = input("Enter to address: ")
else:

Keybase proof

I hereby claim:

  • I am sumanthratna on github.
  • I am sumanthratna (https://keybase.io/sumanthratna) on keybase.
  • I have a public key whose fingerprint is A930 4ABC E8CB DC50 9185 CB95 FC40 F670 A4F6 54CA

To claim this, I am signing this object: