Skip to content

Instantly share code, notes, and snippets.

View deepduggal's full-sized avatar
🚀

Deep Duggal deepduggal

🚀
View GitHub Profile
/**
* TODO: Forgot to check constraints
* https://leetcode.com/problems/maximize-happiness-of-selected-children/
* @param {number[]} happiness
* @param {number} k
* @return {number}
*/
var maximumHappinessSum = function(happiness, k) {
let sorted = happiness.sort((a, b) => (a-b)); // sort for ease
let total = 0;
@deepduggal
deepduggal / demo.js
Created October 14, 2023 22:10
Reactive data from scratch. Maybe I'll turn it into useState() from react that doesn't depend on components.
// TODO: See design.md
// For ideas: https://dev.to/siddharthshyniben/implementing-reactivity-from-scratch-51op or github.com/facebook/react
// const [string, onStringChange] = reactiveData('Sam');
@deepduggal
deepduggal / memoize.js
Last active October 11, 2023 23:06
JavaScript - Memoize a Function
// TODO: Just moved cacheofcaches from global to private var in IIFE. Need to change .bind() with cacheofcaches.
/**
* TODO: Rewrite this comment
* Returns a memoized version of the provided function.
* Old description: Cache the input/output of a pure function
*/
const memo = (function() {
/* Maps functions to their caches (which are also Maps). */
const cacheofcaches = new Map();
const phoneRegex = /^1?\s*((\({1}(\d(\s?)){3}\){1})|(\d(\s?)){3})(-|\s?)(\d(\s?)){3}-?(\d(\s?)){4}$/;
function telephoneCheck(str) {
return !!str.match(phoneRegex);
}
telephoneCheck("555-555-5555");
@deepduggal
deepduggal / lastajax.js
Last active April 24, 2017 23:44
An attempt at making a really awesome, modern AJAX function.
/*
TODO:
- Is this needed for each post or only forms? --> xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- Handle timeout. Consider using setTimeout() and/or xhr.ontimeout event.
- Add support for username, password, json, jsonp, 'PUT' requests,
*/
/**
*
@param opts - [OPTIONAL] - Settings for the XHR request.
async (default: true) - Asynchronous or sycnhronous request.
@deepduggal
deepduggal / index.html
Created April 6, 2017 04:17
Simple Typing Carousel
<link href="http://fonts.googleapis.com/css?family=Raleway:200,100,400" rel="stylesheet" type="text/css" />
<h1>This website will be
<span
class="txt-rotate"
data-period="1500"
data-rotate='[ "cool.", "sexy.", "awesome.", "pretty.", "fun!" ]'></span>
</h1>
<h2>Unfortunately, it's still being made.</br>Please try again later. </h2>
<h4> - Deep Duggal (the developer)</h4>
@deepduggal
deepduggal / index.haml
Last active October 25, 2016 10:43
Normal Website Template
%nav
%a{:href=>"#"} Button A
%a{:href=>"#"} Button B
%a{:href=>"#"} Button C
%a{:href=>"#"} Button D
.main
%h2 Normal Website Template
%h4 By Deep Duggal - deep@deepduggal.me