Skip to content

Instantly share code, notes, and snippets.

@MSK61
MSK61 / decorators_functional.py
Last active May 30, 2020 19:20
implementing python decorators using functional programming
import functools
@functools.partial(lambda wrapper: lambda logger: lambda func: lambda x, y: wrapper(logger, func, x, y))
def exec_with_param_logging(logger, func, x, y):
print(f"{logger} calling in, inputs: {x}, {y}.")
res = func(x, y)
print(f"{logger} calling out, return: {res}.")
return res
import apiclient
import httplib2
import oauth2client.file
import operator
import re
files_api = apiclient.discovery.build('drive', 'v3', http=oauth2client.file.Storage('e:\creds.json').get().authorize(httplib2.Http())).files()
items = files_api.list(fields="files(id, name)", q="name = 'audioTest'").execute().get('files', [])
if items:
parent_id = items[0]['id']
@MSK61
MSK61 / inOrder_space(1)_time(N).cpp
Last active April 6, 2018 03:54
in-order BST traversal
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
using namespace std;
enum Dir {
topDir,
leftDir,
rightDir
};
@MSK61
MSK61 / shortestSubstringContainingChars_dynProg.cpp
Last active April 9, 2018 13:44
shortest substring containing all letters in a set of letters
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<bool> GetArrMap(const vector<char> &arr) {
vector<bool> arrMap(256, false);
for (char curChar : arr) arrMap[curChar] = true;
@MSK61
MSK61 / gDriveRenamer.py
Created March 4, 2018 06:08
Batch renaming for files on google drive
import apiclient
import argparse
import httplib2
from oauth2client import tools
import oauth2client.client
import oauth2client.file
import operator
import re
flow = oauth2client.client.flow_from_clientsecrets('e:\client_secret.json', 'https://www.googleapis.com/auth/drive.metadata')
# you can use print for debugging purposes, e.g.
# print "this is a debug message"
import itertools
def calc_cell(sol, m, n, sums):
sol[m][n] = min(itertools.imap(
lambda i: max(sol[m - 1][i], calc_sum(sums, i, n)), xrange(m - 1, n)))
def calc_sum(sums, i, j):
return sums[j] - sums[i]
@MSK61
MSK61 / hiLo.py
Created September 27, 2014 21:27
class Replier:
def __init__(self, secret):
self._diff = None
self._secret = secret
def answer(self, val):
last_diff = self._diff
self._diff = abs(val - self._secret)
return (-1 if last_diff and self._diff > last_diff else 1) if \
self._diff else 0
#include <iostream>
#include <map>
#include <stack>
bool IsBalanced(const char delimStr[]) {
using std::make_pair;
std::map< char, char > delims;
const char* curChar = delimStr;
std::stack< char > store;