Skip to content

Instantly share code, notes, and snippets.

View checkaayush's full-sized avatar

Aayush Sarva checkaayush

View GitHub Profile
@checkaayush
checkaayush / run_script_on_remote.sh
Last active May 14, 2022 07:58
SSH: Run local bash script on remote server
#!/bin/bash
# Run local bash script on remote server via SSH connection
# Login variables
USER="username"
HOST="host_address" #Remote host
PATH_TO_SCRIPT="path/to/your_script.sh"
ssh -l $USER $HOST 'bash -s' < $PATH_TO_SCRIPT
@checkaayush
checkaayush / chinese_cipher.py
Created June 28, 2015 07:26
Decrypt Chinese Transposition Ciphers.
# Solving Chinese Columnar Transposition Cipher
list_of_words = ['KLTNS AUEIA RDNHC', 'NABEK TYRBO', 'ENDTW YSILA',
'OJS BET SVE', 'RASRF EUQUO', 'TAB EGI SLL', 'KMNE SUOL',
'OONC DRAR LOII ANTS', 'IENIREA NTSETBL', 'OSAJAHM NKCLECI']
def solve_chinese_cipher(cipher_text):
""" Given encrypted cipher_text, returns decrypted secret_message."""
components = cipher_text.split(' ')
@checkaayush
checkaayush / ess_upstart.conf
Created June 28, 2015 08:22
Create your own service using Upstart.
#!upstart
description "ESS Server"
author "Aayush Sarva, <aayush@socialcops.org>"
env DIRECTORY=/home/dev/electoralsearch_server/
# Specify Runlevel events (Refer [1])
# When to start the service
start on runlevel [2345]
@checkaayush
checkaayush / grofersPatternProblem_Logic1.c
Last active August 26, 2015 14:04
Grofers - Campus Recruitment - Programming Problems
#include <stdio.h>
// Pattern (n = 4):
// 1*2*3*4*17*18*19*20
// --5*6*7*14*15*16
// ----8*9*12*13
// ------10*11
int calcOveralLastNum(int n)
{
@checkaayush
checkaayush / gcd_n_numbers.py
Created September 17, 2015 09:00
GCD of 'n' numbers using Python's built-in function 'reduce'
"GCD - Greatest Common Divisor"
def gcd(a, b):
'''Returns GCD of 2 numbers.'''
if not b:
return a
else:
return gcd(b, a % b)
@checkaayush
checkaayush / mainProgram.c
Last active October 18, 2015 14:21
Creating and using your own header file in C
// Instructions:
// Compilation Command: gcc mainProgram.c myLibrary.c
// Creates required object files.
// Execution Command: ./a.out
#include <stdio.h>
// Including my library
@checkaayush
checkaayush / scdocker.sh
Last active August 6, 2016 15:48
Automate Docker workflow
########## Default Values #########################
# GitHub Repo URL (Both SSH and HTTPS work)
REPO_URL="<YOUR_REPO_URL>"
# GitHub branch
BRANCH="master"
# Docker Image Tag
TAG="latest"
@checkaayush
checkaayush / asyncHttpGet.js
Last active June 11, 2016 11:12
Node.js script to load .txt files from a set of URLs asynchronously and combine results in order of URLs using default modules (and with non-default modules)
// Task using default Node.js packages
var http = require('http');
var urls = ['http://screeningtest.vdocipher.com/file1.txt',
'http://screeningtest.vdocipher.com/file2.txt',
'http://screeningtest.vdocipher.com/file3.txt',
'http://screeningtest.vdocipher.com/file4.txt',
'http://screeningtest.vdocipher.com/file5.txt',
'http://screeningtest.vdocipher.com/file6.txt',
@checkaayush
checkaayush / magicbricks_property_coords.py
Last active June 20, 2016 06:23
Get Address of properties on Magicbricks.com using Reverse-Geocoding
"""
Project: Apartment Hunt
Get Address of properties on Magicbricks.com using Reverse-Geocoding
This script asks for the target property URL, reverse geocodes it
and prints the address of the property
Need: Magicbricks map functionality doesn't let users get directions.
Even the exact property address is not visible on the webpage.
@checkaayush
checkaayush / timer.py
Last active May 14, 2019 08:06
Python decorator function to calculate time taken by function to run
from functools import wraps
import time
def timeit(func):
"""Decorator to calculate time taken by a function to run"""
@wraps(func)
def timed(*args, **kw):
start = time.time()
result = func(*args, **kw)