Skip to content

Instantly share code, notes, and snippets.

View SarasArya's full-sized avatar
🏠
Working from home

Saras Arya SarasArya

🏠
Working from home
View GitHub Profile
@SarasArya
SarasArya / django.txt
Last active February 8, 2017 10:18
How to get started with Django-Python-Pymongo on Pycharm Edu
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>
@SarasArya
SarasArya / mongo-backup-automate.sh
Created February 11, 2017 12:28
This script is used to automate the backup process of your mongodb instance. It's a very easy bash script and variables are provided for customization to script. If you don't know how to use mongodump, I suggest you start [here](https://docs.mongodb.com/manual/reference/program/mongodump/)
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
@SarasArya
SarasArya / support-promise-and-callback.js
Last active April 2, 2017 06:39
This gist is for people who are new to JS, and want to write libraries which support both callbacks and Promises architecture.
// 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
@SarasArya
SarasArya / chat-server.js
Created April 2, 2017 08:58
A chat server built purely in NodeJS without the socket.io module. Will help you chat with your roomates on the same router.
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()}`
};
@SarasArya
SarasArya / taxCalculator.js
Created April 13, 2017 10:52
Take home salary calculation when you need to tell someone what is your expected CTC. So enter the salary you want, it will tell you how much salary you will be taking home
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
@SarasArya
SarasArya / socket-test.js
Created April 29, 2017 08:53
Socket.io NodeJS and AngularJS clients demo
//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);
@SarasArya
SarasArya / mongocommands.txt
Created April 29, 2017 09:08
mongodb commands I find useful, especially when dealing with embedded documents.
//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"}})
@SarasArya
SarasArya / cherry-pick-by-author.sh
Created October 12, 2017 07:43
This gist lists the cherry pick by author and stores in a file and apply it on a branch
#!/usr/bin/env bash
if [ -z ${1} ]
then
echo "Enter first argument which is author name";
exit
fi
if [ -z {$2} ]
then
echo "enter second argument which is in which branch you want these commits to go"
exit
@SarasArya
SarasArya / webapp.conf
Last active April 10, 2019 19:16
Ngnix Configuration that works when you have a server running at some port
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;
@SarasArya
SarasArya / static server config
Created March 10, 2019 11:18
Nginx conf for static site serving
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;