Freekode
FreeKode | Snippets

[email protected]

Log All Files In A Folder To The Console NodeJS

const fs = require("fs");

fs.readdir("./", (err, files) => {

files.forEach((file) => {

console.log(file);

});

if (err) {

console.log(err)

}

});

 

[email protected]

MongoDB Mongoose Connection - NodeJS

const mongoose = require('mongoose');

const connectDB = async () => {

mongoose

.connect('mongodb://localhost:27017', {

useCreateIndex: true,

useNewUrlParser: true,

useUnifiedTopology: true,

useFindAndModify: false

})

.then(() => console.log('Connected Successfully'))

.catch((err) => console.error('Not Connected'));

}

module.exports = connectDB;

[email protected]

JavaScript Trigger Function Every Second

(function loop() {
  setTimeout(function () {
    // execute script
    loop()
  }, 1000); // 1000 = 1000 milliseconds = 1s
}());

[email protected]

TensorFlowJS CDN Link

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>

[email protected]

JavaScript For Loop Through An Object

var person = {

    first_name:"John",

    last_name: "Doe",

    phone:"+1 123-456-7890"

};

for (var property in person) {

    console.log(property,":",person[property]);

}

 

[email protected]

JavaScript For Loop Through Array

var colors=["red","blue","green"];

for (let i = 0; i < colors.length; i++) {

 console.log(colors[i]);

}

[email protected]

Install OpenCV

pip install opencv-python

pip install opencv-contrib-python

# People usually get a few problems while installing OpenCV, so here is the correct procedure to install this module.

[email protected]

Basic Flask Application

from flask import Flask

app = Flask(__name__)

@app.route('/')

def hello_world():

    return 'Hello World’

if __name__ == '__main__':

    app.run()

[email protected]

Basic ExpressJS App

const express = require('express');

const app = express();

app.get('/', function (req, res) {

res.send('hello world');

});

app.listen(3000);

[email protected]

Copy a Numpy Array

# Imports

import numpy as np

# Create a Python list

lst = [1, 2, 3, 4, 5]

# Convert lst to a NumPy array

arr = np.array(lst)

# Copy arr

copied_arr = arr.copy()

# copy() creates a duplicate of the original array at that point in time.

# Print copied_arr

print(copied_arr)

# If you change the original array after copying, the copy will not update with the original array.



First 1 2 3 4 Last