Skip to content

Instantly share code, notes, and snippets.

UserSchema.pre("insertMany", async function (next, docs) {
if (Array.isArray(docs) && docs.length) {
const hashedUsers = docs.map(async (user) => {
return await new Promise((resolve, reject) => {
bcrypt.genSalt(10).then((salt) => {
let password = user.password.toString()
bcrypt.hash(password, salt).then(hash => {
user.password = hash
resolve(user)
}).catch(e => {
@bluerid
bluerid / frequencyDist.py
Created September 11, 2019 04:36
NLP using python NLTK Frequency Distribution
import nltk
import urllib.request
from bs4 import BeautifulSoup
from nltk.corpus import stopwords
response = urllib.request.urlopen('https://en.wikipedia.org/wiki/SpaceX')
html = response.read()
soup = BeautifulSoup(html,'html5lib')
text = soup.get_text(strip = True)
tokens = [t for t in text.split()]
@bluerid
bluerid / install.sh
Last active May 2, 2019 02:43
Install and Setup SSHFS with AWS EC2
#Install
sudo apt-get install sshfs
#Setup SSHFS with local folder
sudo sshfs ubuntu@34.236.201.31:/path/to/remote/ec2_folder /user_home_folder/local_ec2s/ec2_sh1 -o IdentityFile=~/Path/to/ssh-key.pem -o allow_other
@bluerid
bluerid / all_commands
Created December 25, 2018 08:29
Migration from MongoDB ReplicaSet setup to a Single Node Standalone setup: Example
someuser$ mongo
## Check Status and member replica sets
rs0:PRIMARY> rs.status()
{
"set" : "rs0",
"date" : ISODate("2018-12-25T07:28:19.390Z"),
"myState" : 1,
"term" : NumberLong(136),
"syncingTo" : "",
"syncSourceHost" : "",
@bluerid
bluerid / basic.docker.commands.txt
Created January 16, 2018 07:01
Basic Docker Commands
#Display system-wide information
>_ docker info
#List up Docker Images
>_ docker images
#List up docker images which are intermediary files created during build(s)
>_ docker images -q --filter dangling=true
#List and remove the intermediary files using xargs command
@bluerid
bluerid / create_laravel_app.sh
Created November 20, 2017 02:41 — forked from connor11528/create_laravel_app.sh
Create a new Laravel application
#!/bin/bash
laravel new $1
cd $1
composer install
yarn install
touch README.md
cp .env.example .env
git init
git add -A
@bluerid
bluerid / index.html
Last active October 7, 2017 11:19
XHR Example Request / Async Callback
<html>
<head>
<title>Blurb Card</title>
<style>
body{
background-color: #ccc;
}
p, ul, blockquote {
color: #333;
padding: 0 0 0 5px;