Skip to content

Instantly share code, notes, and snippets.

View anuraagdjain's full-sized avatar

Anuraag D Jain anuraagdjain

View GitHub Profile
@anuraagdjain
anuraagdjain / hashing.js
Created December 26, 2024 10:16
A quick method which generates a base64 hash string for a given object for the purpose of caching the API response in redis when the request parameters match.
function isObject(obj) {
return typeof obj==='object' && !Array.isArray(obj) && obj !== null;
}
// object -> array
function paramStrGen(obj){
var finalKey = [];
Object.keys(obj).sort().forEach(key => {
"""
Give an file as input which has following data
3 love
6 computers
2 dogs
4 cats
1 I
5 you
@anuraagdjain
anuraagdjain / mysql-docker.sh
Created March 5, 2022 15:40 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@anuraagdjain
anuraagdjain / aws-lambda-redirect.js
Created October 1, 2020 20:35 — forked from DavidWells/aws-lambda-redirect.js
How to do a 301 redirect from an AWS lambda function
exports.handler = (event, context, callback) => {
const response = {
statusCode: 301,
headers: {
Location: 'https://google.com',
}
};
return callback(null, response);
}
# 5-fold cross validation
import numpy as np
import pandas as pd
from sklearn.model_selection import KFold
fold5 = KFold(n_splits=5,shuffle=False,random_state=1)
scores = []
df = pd.read_csv('iris.csv',header=None)
X = df.drop(columns=[4])
Y = df[4]
knn = KNeighborsClassifier(n_neighbors = 9)
@anuraagdjain
anuraagdjain / .gitlab-ci.yml
Created August 14, 2019 05:46
Multi-Environment Gitlab
image: ubuntu:latest
variables:
WORK_DIR: ${CI_PROJECT_NAME}
BRANCH: ${CI_COMMIT_REF_NAME}
stages:
- staging
- production
staging:
@anuraagdjain
anuraagdjain / linklist.js
Last active February 27, 2019 03:25
LinkedList
@anuraagdjain
anuraagdjain / FizzBuzz.js
Created January 26, 2019 13:34
FizzBuzz in JS
"use strict";
const fizzBuzz = () => {
for (let i = 1; i <= 100; i++) {
const mod5 = i % 5,
mod3 = i % 3;
if (mod3 === 0 && mod5 === 0) console.log("FizzBuzz");
else if (mod3 === 0) console.log("Fizz");
else if (mod5 === 0) console.log("Buzz");
else console.log(i);
@anuraagdjain
anuraagdjain / piglatin.js
Created January 22, 2019 18:16
convert strings into "Pig latin"
const vowelRegex = new RegExp('^[aeiou]', 'g');
function pigLatin(str){
if (vowelRegex.test(str)) {
return `${str}way`;
} else {
const first = str.slice(0, 1);
const rem = str.slice(1, str.length);
return `${rem}${first}ay`;
}
}
@anuraagdjain
anuraagdjain / CustomTableViewCell.swift
Created April 7, 2017 16:18
Custom Height for Delete (Swipe to Delete). Swift 3.X
override func layoutSubviews() {
super.layoutSubviews()
var subviews: [Any] = self.subviews
let subview = subviews[0] as! UIView
if subview.classForCoder.debugDescription() == "UITableViewCellDeleteConfirmationView" {
subview.frame.size.height = 50
subview.frame.origin.y = 10
subview.clipsToBounds = true
subview.layer.masksToBounds = true
}