Skip to content

Instantly share code, notes, and snippets.

View modeware's full-sized avatar

Safiq Lodi modeware

  • India
  • 22:04 (UTC +05:30)
View GitHub Profile
@modeware
modeware / server.js
Created September 25, 2023 03:45
Run a .ts extension file on a browser (Was wondering how vite was able to run a ts file on a browser, in memory transpilation, browser only cares for the header that tells file type.)
var http = require("http");
var { readFileSync } = require("fs");
var path = require("path");
//create a server object:
http
.createServer(function (req, res) {
if (req.method === "GET" && req.url == "/") {
const file = readFileSync(path.join(__dirname, "/index.html"));
res.writeHead(200, { "Content-Type": "text/html" });
@modeware
modeware / observableTimeout.js
Created November 22, 2021 06:36
Basic Observable Implementation From Scratch
class Observable {
constructor(subscribe){
this._subscribe = subscribe;
}
subscribe(observer){
return this._subscribe(observer);
}
static timeout(time){
@modeware
modeware / shortest_balanced_fragment.js
Created August 14, 2021 16:28
Program to return the shortest balanced fragment of a string
// Author: Safiq Lodi
//Goal: To find the shortest balanced fragment in a string.
/*
A balanced string that has equal number of lower and upper case characters.
For example - AaBb is a balanced string but TacoCat is not.
*/
@modeware
modeware / subarray_sum0.js
Last active August 14, 2021 17:47
Program to find the number of subarrays in an array that have sum 0.
//Goal - To find the number of sub arrays in an array whose sum is 0
const test1 = [1,2,3, -1, -5, -3, -2, 0]
function sum0(array) {
let subarrays = {}
let count = 0;
//Iterate over the array to find subarrays corresponding to the value of i