Skip to content

Instantly share code, notes, and snippets.

View singhkumarhemant's full-sized avatar
🎯
Focusing

Hemant Kumar Singh singhkumarhemant

🎯
Focusing
View GitHub Profile
@singhkumarhemant
singhkumarhemant / JavascriptBooks.md
Created September 2, 2021 05:23 — forked from WebRTCGame/JavascriptBooks.md
Free Javascript Books

Useful Links

23 Free JavaScript Books

A curated collection of awesome & free JavaScript books to help you learn the JavaScript programming language.

If you know of any other free JavaScript books that you think should be on this list, please let me know in the comments section and I will get them added.

const typeOfB = (value)=>Object.prototype.toString.call(value).split("]")[0].split(" ")[1].toLowerCase();
const crypto = require('crypto')
function encrypt (text, key) {
try {
const IV_LENGTH = 16 // For AES, this is always 16
let iv = crypto.randomBytes(IV_LENGTH)
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key), iv)
let encrypted = cipher.update(text)
encrypted = Buffer.concat([encrypted, cipher.final()])
@singhkumarhemant
singhkumarhemant / encryption.js
Created April 22, 2020 05:06 — forked from vlucas/encryption.ts
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
function delay(t) {
return new Promise(function(resolve) {
setTimeout(resolve, t);
});
}
work.create()
.then(work.publish) //remote work submission
.then(work.requestStatus)
.then(function() {
@singhkumarhemant
singhkumarhemant / create_new_ssh_key.md
Created January 13, 2020 10:23 — forked from JoaquimLey/create_new_ssh_key.md
Generating a new SSH key and adding it to the ssh-agent

Generating a new ssh-key

Open Terminal. Paste the text below, substituting in your GitHub email address.

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

This creates a new ssh key, using the provided email as a label

Generating public/private rsa key pair.

@singhkumarhemant
singhkumarhemant / async-foreach.js
Created January 9, 2020 18:56 — forked from atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@singhkumarhemant
singhkumarhemant / jQueryLoader.js
Created September 3, 2019 09:37 — forked from jenyayel/jQueryLoader.js
jQuery async loader to page
function ensureJquery(readyCallback) {
if (window.jQuery === undefined || parseFloat(window.jQuery.fn.jquery) < 1.9) {
var js = document.createElement('script');
js.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js";
if (js.readyState)
js.onreadystatechange = function () {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
jQueryLoadHandler();
}
};
function foo() {
console.log('sdjnkwjweujwkewkejbwekf')
return true; // if no return statement then typeof foo() will be undefined.
}
foo.bar = "hello world";
console.log(typeof foo); // "function"
console.log(typeof foo()); // "number"
console.log(typeof foo.bar);// string
const SPENDING_THRESHOLD = 200;
const TAX_RATE = 0.08;
const PHONE_PRICE = 99.99;
const ACCESSORY_PRICE = 9.99;
var bank_balance = 303.91;
var amount = 0;
function calculateTax(amount) {
return amount * TAX_RATE;