Skip to content

Instantly share code, notes, and snippets.

@navin-mohan
navin-mohan / add-new-user-passwordless.sh
Last active July 3, 2018 13:38
Shell script to add new user to a remote debian server and set up password less login
#!/bin/bash
# This script adds a new user to the remote server , adds it to sudoers list and enables passwordless login
# follow on my blog https://www.coderew.com/computers/ssh-add-user-remotely-script/
read -p "Enter your Server IP:" serverIP #get server IP address
read -p "Enter a new username:" newusername #username for the new user
read -s -p "Enter the password for $newusername:" password #password
printf "\nEnter the root password of the server when prompted\n"
@navin-mohan
navin-mohan / runningkey.cpp
Last active March 9, 2018 19:46
Running key cipher implementation in C++
/*
The Running Key
----------------
The running key cryptographic algorithm is a classical cipher that uses a long key
such as random sentences from books to encrypt another message. It uses a table for
mapping the cipher text using the key and the plain-text.
get more info here
@navin-mohan
navin-mohan / harden-ssh.sh
Last active December 31, 2023 12:01
A script to harden openSSH on ubuntu or debian server
#!/bin/bash
# Script to harden ssh on ubuntu/debian server
# follow on my blog http://www.coderew.com/hardening_ssh_on_remote_ubuntu_debian_server/
# checkout the repo for more scripts https://github.com/nvnmo/handy-scripts
read -p "Enter your server IP:" serverIP # prompt for server IP
read -p "Enter your username(requires root privileges):" username # prompt for username
printf "\nChanging the default SSH port is one of the easiest\n things you can do to help harden you servers security. \nIt will protect you from robots that are programmed \nto scan for port 22 openings, and commence \ntheir attack."
printf "\n"
read -p "Do you want to change default SSH port?[Y/n]" -n 1 portChange
@navin-mohan
navin-mohan / sketch.ino
Last active May 12, 2016 12:26
Arduino Based Automatic Plant Watering System Using Soil Moisture Sensor
/*
Automatic Plant Watering System Using Soil Moisture Sensor
-------------------------------------------------------------
This is an Arduino based Plant watering system that uses a soil moisture sensor
to monitor the garden soil and automatically water the plants when the moisture
level falls below a threshold value. The minimum moisture level can be set using
a Potentiometer.
Arduino Pin Config:
-> A0 : The analog output from the moisture sensor
#include <IRremote.h> //include the IR library
//#define DEBUG 0 //enable debug mode
#define LED_PIN 13 //the pin showing the output
int IR_pin = 4; //digital pin connected to output of the TSOP
unsigned long currentCode=0,storedCode=0; //to store the recieved code for comparison
bool outputState = 0; //stores the default output state of the lED that is OFF
@navin-mohan
navin-mohan / diff.py
Created August 9, 2016 15:38
Subtracting Two Images - OpenCV Python
import cv2
def diff(img,img1): # returns just the difference of the two images
return cv2.absdiff(img,img1)
def diff_remove_bg(img0,img,img1): # removes the background but requires three images
d1 = diff(img0,img)
d2 = diff(img,img1)
return cv2.bitwise_and(d1,d2)
@navin-mohan
navin-mohan / bracket_matching.cpp
Created January 21, 2017 13:37
Bracket Matching C++ code
#include <iostream>
#include <stack>
using namespace std;
class bracket_matcher: public stack<char>{
public:
bracket_matcher(): stack<char>() { matching = 1;}
void push_bracket(const char &arg){
@navin-mohan
navin-mohan / ship.cpp
Created February 12, 2017 07:36
Arduino Leonardo Joystick Library
#include <Joystick.h>
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_MULTI_AXIS, 32, 0,
false, false, false, false, false, false,
true, true, false, false, false); // only rudder and throttle
const int rudderPin = A1;
const int throttlePin = A2;
@navin-mohan
navin-mohan / kernel.sh
Last active April 2, 2017 11:15
Configure Debian
#!/bin/bash
cat << EOF > ~/src
deb [arch=amd64] http://mirror.cse.iitk.ac.in/debian/ jessie main contrib non-free
deb-src [arch=amd64] http://mirror.cse.iitk.ac.in/debian/ jessie main contrib non-free
deb [arch=amd64] http://mirror.cse.iitk.ac.in/debian/ jessie-updates main contrib non-free
deb-src [arch=amd64] http://mirror.cse.iitk.ac.in/debian/ jessie-updates main contrib non-free
deb [arch=amd64] http://security.debian.org/ jessie/updates main contrib non-free
#!/bin/bash
if [ -e ~/.nvm/nvm.sh ]; then
. ~/.nvm/nvm.sh
fi
if [ -e ~/.profile ]; then
. ~/.profile
fi
if [ -e ~/.bashrc ]; then
. ~/.bashrc