Skip to content

Instantly share code, notes, and snippets.

@jasterix
jasterix / CreateLogsinMain.cs
Last active December 5, 2021 17:28
Create logs in Main -- The following code logs in Main by getting an ILogger instance from DI after building the host:
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
class Program
{
static Task Main(string[] args)
{
@jasterix
jasterix / pullFiles.js
Created August 19, 2020 15:05
Script to recursively pull all files from nested folders
const fs = require( "fs" )
const path = require( "path" )
const { basename } = require( "path" )
const fileDir = path.join( __dirname, "../../../fileConverter/files" )
// Get all files' names
const getAllFiles = function ( dirPath, arrayOfFiles = [] ) {
files = fs.readdirSync( dirPath )
arrayOfFiles = arrayOfFiles
@jasterix
jasterix / quickSort.jss
Created August 18, 2020 12:28
Quick Sort
function pivot(arr, start = 0, end = arr.length - 1) {
const swap = (arr, idx1, idx2) => {
[arr[idx1], arr[idx2]] = [arr[idx2], arr[idx1]];
};
// We are assuming the pivot is always the first element
let pivot = arr[start];
let swapIdx = start;
@jasterix
jasterix / priorityQueue.js
Last active August 16, 2020 17:18
Implementing a priority queue with a binary heap
class PriorityQueue {
constructor(){
this.values = [];
}
enqueue(val, priority){
let newNode = new Node(val, priority);
this.values.push(newNode);
this.bubbleUp();
}
bubbleUp(){
@jasterix
jasterix / binarySearchTreeTraversal.js
Created August 16, 2020 17:16
Depth first search and BST tree traversal
class Node {
constructor(value){
this.value = value;
this.left = null;
this.right = null;
}
}
class BinarySearchTree {
constructor(){
@jasterix
jasterix / binarySearchTree.js
Created August 16, 2020 17:15
Creating and working with a binary search tree
class Node {
constructor(value){
this.value = value;
this.left = null;
this.right = null;
}
}
class BinarySearchTree {
constructor(){
@jasterix
jasterix / stack.js
Created August 16, 2020 17:14
Implementing a stack with a singly linked list
class Node {
constructor(value){
this.value = value;
this.next = null;
}
}
class Stack {
constructor(){
this.first = null;
@jasterix
jasterix / queue.js
Last active August 18, 2020 12:03
Queue - Implementing a queue using a singly linked list
class Node {
constructor(value){
this.value = value;
this.next = null;
}
}
class Queue {
constructor(){
this.first = null;
@jasterix
jasterix / doublyLinkedList.js
Created August 16, 2020 17:12
Creating and working with Doubly Linked Lists
class Node{
constructor(val){
this.val = val;
this.next = null;
this.prev = null;
}
}
class DoublyLinkedList {
@jasterix
jasterix / singlyLinkedList.js
Created August 16, 2020 17:11
Creating and working with Singly Linked Lists
class Node{
constructor(val){
this.val = val;
this.next = null;
}
}
class SinglyLinkedList{
constructor(){
this.head = null;