Skip to content

Instantly share code, notes, and snippets.

View checkaayush's full-sized avatar

Aayush Sarva checkaayush

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / FRIENDS.py
Created September 18, 2016 15:30
Script I used to rename all F.R.I.E.N.D.S. epsiodes by fetching names from Wikipedia
from bs4 import BeautifulSoup
import requests
import os
def get_episode_names(season):
episodes = {}
print "Making request..."
url = "https://en.wikipedia.org/wiki/Friends_(season_%s)#Episodes" % season
print url
@checkaayush
checkaayush / gist:ec14e28aa08343e1e35f47d2c5b2ee3d
Last active October 4, 2016 07:55 — forked from jonleighton/base64ArrayBuffer.js
Encode an ArrayBuffer as a base64 string
// Converts an ArrayBuffer directly to base64, without any intermediate 'convert to string then
// use window.btoa' step. According to my tests, this appears to be a faster approach:
// http://jsperf.com/encoding-xhr-image-data/5
function base64ArrayBuffer(arrayBuffer) {
var base64 = ''
var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
var bytes = new Uint8Array(arrayBuffer)
var byteLength = bytes.byteLength