Skip to content

Instantly share code, notes, and snippets.

@loneshark99
loneshark99 / RemoveDupsfromSortedArray.cs
Last active January 26, 2021 21:51
Write a program which takes an Sorted Array and removes duplicates
// Write a program which takes an Sorted Array [ 1,2,3,4,6,6,6,7,8,99,99,99,1000]
// and removed duplicates. http://share.linqpad.net/sbrxsw.linq
// IDEA :: The idea here is to push the elements to the Left, so that all the unique elements are to the left of the array.
// When the elements dont match, you swap the places with the last unique element.
// When they match just move to next element.
void Main()
{
// [i/p] : [1,1,1,1] [o/p] : [1,1,1,1] and n=1
// [i/p] : [0] [o/p] : [0] and n=1
@loneshark99
loneshark99 / uw420.py
Last active December 23, 2020 21:15
Download UW420 Course Materials
import sys
import os
import os.path
from os import path
import requests
import shutil
class UwCourse():
def __init__(self, courseName, destinationpath=""):
self.courseName = courseName
@loneshark99
loneshark99 / Spread-Rest-Destructuring.js
Created December 10, 2020 22:40
Spread Rest And Desctructing
// SPREAD OPERATOR
x = [1,2,3,4,5,6,7]
y = [8,9,10]
xAndy = [...x, ...y]
console.log("SPREAD OPERATOR", xAndy)
// REST OPERATOR
function test(...b){
@loneshark99
loneshark99 / Arrow Functions.html
Created December 10, 2020 21:34
Arrow Function Explanation
<!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>
<script>
@loneshark99
loneshark99 / Expression.cs
Created March 12, 2020 17:13
Expression usage like MOQ
void Main()
{
MyClass t = new MyClass()
{
MyProperty = 1,
MyProperty1 = "YAHOO"
};
Console.WriteLine(GetPropertyValue(() => t.MyProperty1));
Console.WriteLine(GetPropertyValue(() => t.MyProperty));
@loneshark99
loneshark99 / MonadMaybe.cs
Created March 10, 2020 16:45
Monad Maybe
// Define other methods, classes and namespaces here
public static class Maybe
{
public static TResult With<TInput, TResult>(this TInput o, Func<TInput, TResult> evaluator)
where TResult : class
where TInput : class
{
if (o == null) return null;
else return evaluator(o);
}
@loneshark99
loneshark99 / Correlatedquery.sql
Created February 12, 2020 06:15
Sql Correlated Subquery
Select * from tmpWkClassCode T
where T.TransSeqNo = (Select Max(TransSeqNo) from tmpWkClassCode T1
where T.ClassCd = T1.ClassCd)
@loneshark99
loneshark99 / StartAndEndMonthDate.sql
Created February 10, 2020 01:32
Start and End of the Month Date in Sql
DECLARE @DtTable TABLE
(
PolicyInceptionFromDate DATETIME NOT NULL,
PolicyInceptionToDate DATETIME NOT NULL,
ValuationDate DATETIME NOT NULL
)
DECLARE @START INT = 0;
DECLARE @ValuationDate DATETIME = '12/31/2019';
// Bubble Sort is O(N^2) since there are 2 nested loops.
// Issues :: Slow and no of Swaps are more.
let arr = [1,2,4,5,6,7,8,10.5,10];
function bubbleSort(arr) {
for (let i = 0; i < arr.length; i++) {
let isSorted = false;
for (let j = 0; j < arr.length - i - 1; j++) {
console.log(`Comparing ${j} with ${j+1}`)
@loneshark99
loneshark99 / HelperMethodRecusionPattern.js
Last active February 2, 2020 05:53
Helper Method Recursion Pattern
// Helper Method Recursion Pattern... (Nested Functions)
// You are collecting or Creating a subarray :: in such cases Helper Method Recursion comes in handy!
function FindAllOddNumbers(arr){
let oddNumbers = [];
function getOddNumbers(arr) {
if (arr.length === 0) {