Skip to content

Instantly share code, notes, and snippets.

View rishisidhu's full-sized avatar
🏠
Working from home

Rishi Sidhu rishisidhu

🏠
Working from home
  • https://aigraduate.com
View GitHub Profile
@rishisidhu
rishisidhu / spread_operator.js
Created July 10, 2020 12:48
Modern JS ES6+ features - Spread Operator
array1 = [1, 2, 3, 5];
object1 = {
key1: "value1",
key2: "value2",
};
//Spread operator in array
array2 = [10, ...array1];
console.log(array2);
@rishisidhu
rishisidhu / for_of_loop.js
Created July 10, 2020 12:30
Modern JS ES6+ features - For-Of Loops
let details = [11, 13, 17, "Prime Numbers"];
//Looping through array
for (const detail of details) {
console.log(detail);
}
@rishisidhu
rishisidhu / destructuring_objects.js
Last active July 10, 2020 11:39
Modern JS ES6+ features - Destructuring Objects
const financialInfo = {
City: "New York",
Artform: "Jazz",
Artist: "Miles Davis",
TicketCurrency: "$",
Cost: 200,
};
//Destructuring Object
const { Artist, TicketCurrency, Cost } = financialInfo;
@rishisidhu
rishisidhu / template_literal.js
Created July 10, 2020 11:25
Modern JS ES6+ features - Template Literals
const Currency1 = "Dollars";
const Currency2 = "Rupees";
const exchange_rate = 72;
news_string = "Today 100 " + Currency1 + " are trading for " + exchange_rate * 100 + " " + Currency2;
//The normal way
console.log(news_string);
//The template literal way
news_string_tl = `Today 100 ${Currency1} are trading for ${exchange_rate * 100} ${Currency2}`;
@rishisidhu
rishisidhu / validate_email.py
Created June 25, 2020 16:57
A python code that describes how regex can be used to validate an email ID
import re
test_email_1 = "Jane.doe1971@gmail.com"
test_email_2 = "JD@msn.org.edu"
test_email_3 = "J.A.N.E@web123.AI"
test_emails = [test_email_1, test_email_2, test_email_3]
def extract_info(email_string):
# Search for username
# Methodology
# All alphabets and numbers before @
@rishisidhu
rishisidhu / const.js
Created April 27, 2020 14:01
Javascript code to display the scope of const statement
function constExample() {
const k = 1;
k = 2;
}
function go() {
constExample();
}
@rishisidhu
rishisidhu / let.js
Created April 27, 2020 13:55
Javascript code to display the scope of let statement
// Let scope function
function letExample() {
for (let i = 0; i < 10; i++) {
console.log("i = ", i);
}
console.log("i outside of scope = ", i);
}
function go() {
letExample();
@rishisidhu
rishisidhu / var.js
Created April 27, 2020 13:46
javascript code to display the scope of var statement
// Var scope function
function varExample() {
for (var i = 0; i < 10; i++) {
console.log("i = ", i);
}
//console.log("i outside of scope = ", i);
}
function go() {
varExample();
@rishisidhu
rishisidhu / index.html
Created April 27, 2020 13:34
This file implements a button which can run a javascript file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>Javascript Var v/s Let v/s Code</h1>
<script src="index.js"></script>
@rishisidhu
rishisidhu / cluster_and_stack.R
Created April 25, 2020 06:17
An example of how to cluster and stack bars in a bar plot by different variables
dummy_data_1 <- tribble(
~Country, ~"Time", ~"Score", ~"Gender",
"INDIA", "AM", 20, "male",
"INDIA", "PM", 20, "female",
"INDIA", "AM", 50, "male",
"INDIA", "PM", 40, "male",
"INDIA", "AM", 20, "female",
"USA", "AM", 30, "male",
"USA", "PM", 30, "male",
"USA", "PM", 30, "female",