Skip to content

Instantly share code, notes, and snippets.

View sajith-rahim's full-sized avatar
🏠
Working from home

Sajith Rahim sajith-rahim

🏠
Working from home
View GitHub Profile
@sajith-rahim
sajith-rahim / ReadProps.java
Created September 16, 2021 18:54
Java Props - Old Way
package com.examples.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertiesReadWrite {
@sajith-rahim
sajith-rahim / custom-domain-git-page.md
Created July 25, 2021 20:49
Add custom domain to your github page.

Add custom domain to your github page.

  1. Log in to your domain registrar and find where to change your host records.
  2. Change your domain's Address Record to 204.232.175.78. This is GitHub's IP address, which allows GitHub to resolve your URL and serve the correct files.
  3. In your website's directory folder on your computer, create a file called "CNAME". On the first line, type your domain name. Save the file.
  4. In your GitHub application, you should see the file in the left column. Make sure it is checked and enter your commit message.
  5. Click "Sync branches."
  6. It can take as long as 48 hours for your domain to resolve to your GitHub page. However, it is usually pretty quick, so check back in an hour or so.
@sajith-rahim
sajith-rahim / logger.py
Created July 25, 2021 20:40
Basic logger
import datetime
import logging
import ntpath
import os
from typing import Optional
def create_folder(directory):
if not os.path.exists(directory):
os.makedirs(directory)
@sajith-rahim
sajith-rahim / vec_sum_plot.py
Created July 11, 2021 14:06
vec_sum_plot.py
u = [0, 0, 1, 6]
v = [0, 0, 4, 2]
u_bis = [1, 6, v[2], v[3]]
w = [0, 0, 5, 8]
plt.quiver([u[0], u_bis[0], w[0]],
[u[1], u_bis[1], w[1]],
[u[2], u_bis[2], w[2]],
[u[3], u_bis[3], w[3]],
angles='xy', scale_units='xy', scale=1, color=sns.color_palette())
plt.xlim(-2, 6)
def cosine_sim(vec1, vec2):
if isinstance(vec1, list) and isinstance(vec2, list):
dot_prod = 0
for i, v in enumerate(vec1):
dot_prod += v * vec2[i]
mag_1 = math.sqrt(sum([x ** 2 for x in vec1]))
mag_2 = math.sqrt(sum([x ** 2 for x in vec2]))
return dot_prod / (mag_1 * mag_2)
@sajith-rahim
sajith-rahim / linear_regression_gd.py
Created July 10, 2021 21:09
linear regression on diabetes dataset
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.metrics import mean_squared_error
class LinearRegression:
"""
Linear Regression
Parameters:
@sajith-rahim
sajith-rahim / simple_linear_regression_snv.py
Last active July 10, 2021 19:01
Simple Linear Regression with Centering and Scaling
import numpy as np;
def gradient_descent(x, y):
m = 0.0
b = 0.0
iterations = 10000
learning_rate = 1e-4
x_mean = np.mean(x)