Skip to content

Instantly share code, notes, and snippets.

View saraswatmks's full-sized avatar
💭
I may be slow to respond.

Manish Saraswat saraswatmks

💭
I may be slow to respond.
View GitHub Profile
@saraswatmks
saraswatmks / gist:99c53635a733ad27bd2416c66207256d
Last active October 29, 2023 20:48 — forked from teja156/gist:8c35a05f43635da4cbd06b47c0d91e93
Commands for deploying wordpress website on AWS EC2 shown in my YouTube video
YouTube video link: https://youtu.be/8Uofkq718n8
All the commands that are executed in the above youtube video are mentioned in this gist.
1. Install Apache server on Ubuntu
sudo apt install apache2
2. Install php runtime and php mysql connector
sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php8.1-imagick
3. Install MySQL server
@saraswatmks
saraswatmks / input.py
Created August 19, 2022 12:14
Validate input response
def validate_input(gross):
try:
return int(gross)
except ValueError as e:
print("Incorrect gross input. Please provide gross value as int or float.")
gross = input('provide gross input')
gross = validate_input(gross)
@saraswatmks
saraswatmks / infix.py
Last active May 18, 2019 12:46
Evaluate expression with infix operators in Python
from functools import reduce
def inifix_operator(expression, variables=None):
opr = set(['/','+','-','*'])
ex = expression.strip().split()
num_count = len(opr.difference(ex))
num_opr = len(opr.intersection(ex))
valid = num_count - num_opr
@saraswatmks
saraswatmks / feat.py
Created February 13, 2018 13:23
Kaza LGBM base features
lgb_params = {
'feature_fraction': 0.75,
'metric': 'rmse',
'nthread':1,
'min_data_in_leaf': 2**7,
'bagging_fraction': 0.75,
'learning_rate': 0.03,
'objective': 'mse',
'bagging_seed': 2**7,
'num_leaves': 2**7,
@saraswatmks
saraswatmks / Class_Python
Created January 13, 2018 11:49
Derived class from Base Class inheriting same methods - Python
class Employee(object):
"""Models real-life employees!"""
def __init__(self, employee_name):
self.employee_name = employee_name
def calculate_wage(self, hours):
self.hours = hours
return hours * 20.00
# Add your code below!
@saraswatmks
saraswatmks / split_to_cols.R
Created January 6, 2018 13:53
split to multiple columns in R
check1 <- data.table(name = c('a,b','a,b,c','a,b,d','b,d,e','e,f,g','a,b,f'))
to_columns <- function(df, col_name)
{
get_values <- unique(unlist(strsplit(df[[col_name]], split = ",")))
d <- strsplit(df[[col_name]], split = ",")
for(i in get_values)
{
df[[paste0("col_",i)]] <- sapply(d, function(x) as.integer(i %in% x))
@saraswatmks
saraswatmks / triplets.R
Created December 19, 2017 16:30
compare the triplets in R
# Enter your code here. Read input from STDIN. Print output to STDOUT
con <- file('stdin','r')
input <- readLines(con)
n1 <- input[[1]]
n2 <- input[[2]]
n1 <- as.numeric(unlist(strsplit(n1, ' ')))
n2 <- as.numeric(unlist(strsplit(n2, ' ')))
@saraswatmks
saraswatmks / statistics_calculations.R
Last active December 20, 2017 16:32
Statistics in R
### Median and Quartile
cal_med <- function(x)
{
### median
x<- sort(x)
l1 <- length(x)
mid <- c()
if(l1 %% 2 == 0) mid <- append(mid, c(l1/2, (l1/2)+1))
else mid <- append(mid, ceiling(l1/2))
@saraswatmks
saraswatmks / input.R
Created December 17, 2017 12:26
stdin,stdout in R
con = file('stdin', open='r')
inputs <- readLines(con)
n <- inputs[[1]]
n1 <- inputs[[2]]
n1 <- unlist(strsplit(n1, ' '))
n1 <- as.integer(as.factor(n1))
n1 <- n1[length(n1):1]
cat(n1)
ssh -i he-standalone.pem ubuntu@10.1.136.21