Skip to content

Instantly share code, notes, and snippets.

View pujansrt's full-sized avatar

Pujan Srivastava pujansrt

View GitHub Profile
@pujansrt
pujansrt / top-brew-packages.txt
Last active July 2, 2022 19:23 — forked from pmkay/top-brew-packages.txt
Top homebrew packages
node: Platform built on V8 to build network applications
git: Distributed revision control system
wget: Internet file retriever
yarn: JavaScript package manager
python3: Interpreted, interactive, object-oriented programming language
coreutils: GNU File, Shell, and Text utilities
awscli: Official Amazon AWS command-line interface
automake: Tool for generating GNU Standards-compliant Makefiles
youtube-dl: Download YouTube videos from the command-line
readline: Library for command-line editing
@pujansrt
pujansrt / MapIteration.java
Last active November 21, 2021 20:45
Collections
map.forEach((k, v) -> System.out.println(k + "=" + v));
for (Map.Entry<?, ?> entry : m.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
Iterator it = m.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
@pujansrt
pujansrt / README.md
Last active September 16, 2021 12:24
Cross Account Lambda to Lambda Call

Cross Account Lambda to Lambda Call

Source Lambda

in source serverless.yaml file add. This account no is 111100001111

resources:
  Resources:
    LambdaResourcePolicy:
      Type: AWS::Lambda::Permission
@pujansrt
pujansrt / sreda.test.js
Created December 4, 2020 14:25 — forked from igorkosta/sreda.test.js
Mock promisified AWS service operation calls
/* eslint-env jest */
'use strict'
const { read, keys } = require('../sreda')
const AWS = require('aws-sdk')
let ssm = new AWS.SSM()
var ssmPromise = {
promise: jest.fn().mockImplementation((request) => {
return new Promise((resolve, reject) => {
// if you see anywhere in js file that fetch is not defined.
// then use following to fix
global.fetch = require('node-fetch')
@pujansrt
pujansrt / asyn_await_best_practices.js
Created March 17, 2019 17:11
Async Await Best Pratices
// The Async/Await section spreads some misinformation and bad practices. It explains that try/catch must be used whenever an await expression is used, but that is not the case. For example, this snippet:
function getGithubUser(username) {
return new Promise((resolve, reject) => {
fetch(`https://api.github.com/users/${username}`)
.then(response => {
const user = response.json();
resolve(user);
})
.catch(err => reject(err));
async getUrlInfo(url: string) {
const reg = new RegExp("https?://([a-z0-9]+[.])*.?ea[.]com");
const reg2 = new RegExp("^(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$");
async function reachability() {
const responseReachable: any = await fetch(url, {method: 'HEAD'}).catch(() => false);
return responseReachable.status === 200;
}
return {
@pujansrt
pujansrt / generatePassword.js
Last active March 24, 2019 06:23
Generate Random Password (JS)
const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split('');
function generatePassword(L){
return Array.from({length: L})
.map(i => alphabet[Math.floor(Math.random() * alphabet.length)])
.join("")
}
console.log(generatePassword(14));
@pujansrt
pujansrt / TwoWayHashing.js
Last active July 8, 2022 15:04
Two way hashing (JS)
const crypto = require('crypto');
const algorithm = 'aes256';
const salt = '900150983cd24fb0d6963f7d28e17f72';
const cryptoEncoding = 'base64';
const cipher = crypto.createCipher(algorithm, salt);
const encryptedText = cipher.update(text, 'utf8', cryptoEncoding) + cipher.final(cryptoEncoding);
@pujansrt
pujansrt / dynamic_orderBy.sql
Last active March 24, 2019 06:24
Dynamic Order by (SQL)
-- Make sure whatever _order is passed, is selected in SELECT.
@delimiter %%%;
CREATE PROCEDURE prime1(_order VARCHAR(32)) NOT DETERMINISTIC READS SQL DATA
BEGIN
SET @order = _order;
SELECT ID, TITLE, SUMMARY FROM articles a ORDER BY
CASE WHEN _order = 'SUMMARY ASC' THEN SUMMARY END ASC,
CASE WHEN _order = 'ID ASC' THEN ID END ASC,
CASE WHEN _order = 'TITLE ASC' THEN TITLE END ASC,