Skip to content

Instantly share code, notes, and snippets.

View IamManchanda's full-sized avatar
🖥️
Coding

Harry Manchanda IamManchanda

🖥️
Coding
View GitHub Profile
@IamManchanda
IamManchanda / .bash_profile
Created June 5, 2024 06:43
.bash_profile - Public
PARSE_GIT_BRANCH() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
EMOJI_DOCKER=🐳
EMOJI_FLAG=🇮🇳
EMOJIS_FACES=(😂 🤣 🤔 😄 😆 🙂 😎 😌 🙃 😉 🧐 😏 🤪 😜 😱 😬 🤫 🙄 😈 🙈 🙉 🙊)
EMOJIS_HANDS=(🙌 🤝 👌 🤘 🖖 🙏 👏 💪 🤙)
RANDOM_EMOJI_FACES() {
@IamManchanda
IamManchanda / run.sh
Created July 27, 2022 10:46
Bash Script for Running Main.java
!/bin/bash
clear
echo ""
echo "Compiling and Running Java Program..."
javac -d ./__prod Main.java
echo ""
echo "----------------------------------------------------------------------------------------------------------------------------------------------------------------"
echo ""
java -cp ./__prod Main
@IamManchanda
IamManchanda / curry.js
Created December 15, 2020 10:55
Currying function in JavaScript
/**
* Currying function in JavaScript
*/
// Normal function definition
function multiply(a, b, c) {
return a * b * c;
}
multiply(1, 2, 3); // 👉 Output: 6
@IamManchanda
IamManchanda / uuidv4-custom.js
Last active December 14, 2020 08:27
Create your own Universally Unique Identifier (UUID) - v4
function uuidv4() {
const init = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
return init.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
const v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
const memoize = (fn) => {
const cache = {};
return (...args) => {
if (cache[args]) { return cache[args]; }
cache[args] = fn.apply(this, args);
return cache[args];
};
};
const range = (count) => Array.from({ length: count }, (v, i) => i + 1);
var obj = {
values: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34],
start: 4,
end: 13,
*[Symbol.iterator]() {
for (var i = this.start; i <= this.end; i++) {
yield this.values[i];
}
},
};
var obj = {
values: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34],
start: 4,
end: 13,
[Symbol.iterator]() {
var idx = this.start;
var end = this.end;
var it = {
next: () => {
import idb from 'idb';
var dbPromise = idb.open('test-db', 4, function(upgradeDb) {
switch(upgradeDb.oldVersion) {
case 0:
var keyValStore = upgradeDb.createObjectStore('keyval');
keyValStore.put("world", "hello");
case 1:
upgradeDb.createObjectStore('people', { keyPath: 'name' });
case 2:
@IamManchanda
IamManchanda / jqueryMouseKey.js
Created June 17, 2018 22:19
jQuery Mouse and Keyboard events
$(document).ready(() => {
const onEvent = (event, eventLog = event) => {
let box;
let pageCoords;
if (event.startsWith('key')) {
box = $(document);
pageCoords = (e) => `(${e.which})`;
} else {
box = $('.element');
pageCoords = (e) => `(${e.pageX}, ${e.pageY})`;
@IamManchanda
IamManchanda / deepCopy.js
Last active June 9, 2018 23:07
Deep Copy By Value
const deepCopy = (value) => { // deepCopy by Value
let val;
if (Array.isArray(value)) {
val = [...value]; // Copy by Value
} else if (value && typeof value === 'object') {
val = { ...value }; // Copy by Value
} else {
return value; // Returns original value and stops!
}