Skip to content

Instantly share code, notes, and snippets.

View ashwinrs's full-sized avatar
💭
🍦

Ashwin S ashwinrs

💭
🍦
View GitHub Profile
@ashwinrs
ashwinrs / string_tokenizer.cpp
Last active July 17, 2017 15:48
String tokenizer in C++
// Based on - https://stackoverflow.com/a/53878/437894
#include <vector>
#include <string>
using namespace std;
vector<string> stringTokenizer(string input, char delimiter){
vector<string> result;
if(!input.length())
return result;
@ashwinrs
ashwinrs / s3_get.py
Last active June 20, 2017 19:08
Download s3 file using python3
#!/usr/bin/python3
import boto3
def get_s3_object(key, keyid, bucket, s3_file_location, local_file):
client = boto3.client('s3',aws_access_key_id=keyid,aws_secret_access_key=key)
client.download_file(bucket, s3_file_location, local_file)
return
@ashwinrs
ashwinrs / execute_shell_command.py
Last active June 15, 2017 00:37
Execute shell command from python
import subprocess
def execute_binary(args):
popen = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout,stderr = popen.communicate()
if popen.returncode != 0:
print("Process exited non zero: {0}".format(popen.returncode))
return False
return True
@ashwinrs
ashwinrs / migrate_collection.py
Created June 13, 2017 21:19
Copy a collection between two mongodbs
#!/usr/bin/python3
from pymongo import MongoClient
from datetime import datetime, timedelta
from pprint import pprint
mongo_parameters = {
'source_mongo': '',
'db' : '',
'dest_mongo' : ''
}