This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The operating system used here is Ubuntu | |
Download and install Pycharm-edu | |
Open it and create a New Project | |
This will create a project folder and install all necessary base files | |
now inside that folder and create a virtual environment by typing `virtualenv -p /usr/bin/python3.4 <venv_name>` | |
Type `source <venv_name>/bin/activate` to activate that virtual environment. Node people consider this as your local node_modules folder. | |
Now install Django by typing `pip3 install Django` | |
This will create the django-admin.py file necessary to start a project. | |
Create your sub-app by typing `django-admin.py startproject <my_sub_app>` | |
This will create another folder with the name <sub_app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MONGO_DATABASE="your_db_name" | |
APP_NAME="your_app_name" #this is optional.Use this if you have more than 1 scripts for more than 1 app | |
MONGO_HOST="<db_name>/server0.example.com:27011,server1.example.com:27011,server2.example.com:27011" #for replica set config | |
#MONGO_HOST="127.0.0.1" in case running a standalone server | |
#MONGO_PORT=27001 in case running a standalone server on a port other than 27017 | |
TIMESTAMP=`date +"%d-%m-%y"` | |
MONGODUMP_PATH="/usr/bin/mongodump" #got it from whereis mongodump | |
#BACKUP_DIR="/home/oroborus/work/server-logs" #for my local machine to test it out | |
BACKUP_DIR="/home/ubuntu/server-logs" #ec2 instance where to put it | |
BACKUP_NAME="$APP_NAME/$TIMESTAMP" #folder structure optional again |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file provides an example of how you can expose both Promises and callback support to your functions | |
const fs = require('fs'); | |
//This function can be called via callbacks, as well as Promises | |
const readFileAsArray = function(file, cb = () => {}) { //callback is made an empty function in case I am using Promises, | |
// in which case I wont be passing this argument and it wouldn't throw and undefined variable error. | |
return new Promise((resolve, reject) => { //create a new promise | |
fs.readFile(file, (err, data) => { | |
if (err) { | |
reject(err); //To support promises |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.stdout.write('\u001B[2J\u001B[0;0f'); // Cleans up the console. | |
const server = require('net').createServer(); | |
let counter = 0; | |
let sockets = {}; | |
//function to return the current time | |
let timeStamp = () => { | |
let now = new Date(); | |
return `${now.getHours()}:${now.getMinutes()}` | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const salary = 246250; | |
const taxExempt = 250000; | |
const limit1 = 250000; | |
const taxPercentage1 = 0.1 // This should be changed to 0.05 from 2017-2018 fiscal | |
const limit2 = 500000; | |
const taxPercentage2 = 0.2 | |
const limit3 = 1000000; | |
const taxPercentage3 = 0.3; | |
let taxBracket = null; | |
//decide the tax bracket that you lie in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//On instruction of how to debug if sockets are working or not. Please check here https://socket.io/docs/logging-and-debugging/ | |
//NodeJS Side | |
const server = require('http').Server(app), | |
io = require('socket.io')(server); | |
io.sockets.on('connection', function (socket) { | |
socket.on('set', function (status, callback) { | |
console.log(status); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//To remove a field from each document. Whenever I introduce a field by mistake | |
db.example.update({}, {$unset: {words:1}} , {multi: true}); | |
//To search in array of objects in mongodb | |
db.collection.find( { field1: { $elemMatch: { one: 1 } } } ); | |
//To update array of objects in mongodb console | |
db.roles.update({"userId" : ObjectId("58a191b8d02dde3638a5a4ee"), "children.requestStatus" : 'Rejected'},{$set : {"children.$.requestStatus" : "Authorized"}}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name <your server name>; | |
return 301 https://$host$request_uri; | |
} | |
server { | |
listen 443 ssl; | |
server_name <your server name>; | |
ssl_certificate /etc/letsencrypt/live/<your website name>/fullchain.pem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name www.example.com example.com; | |
return 301 https://$host$request_uri; | |
} | |
server { | |
listen 443 ssl; | |
server_name www.example.com; | |
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; |
OlderNewer