Instantly share code, notes, and snippets.

Venkatesh-Prasad Ranganath rvprasad

View GitHub Profile
View io-measure.cpp
#include <chrono>
#include <fstream>
#include <iostream>
using namespace std;
int k = 256;
int numOfNums = k * 1024 * 1024;
int reps = 6;
void writeUsingFile(string fileName) {
View iperf-client-best-case.yml
- hosts: worker_raspi
remote_user: life
strategy: free
tasks:
- name: iperf1
shell: iperf -t 20 -c 192.168.2.10
when: ansible_host == '192.168.2.13'
- name: iperf2
shell: iperf -t 20 -c 192.168.2.11
when: ansible_host == '192.168.2.14'
View iperf-client-worst-case.yml
- hosts: worker_raspi
remote_user: life
tasks:
- name: iperf
shell: iperf -t 20 -c 192.168.2.10
View overlapping_intervals.py
# Given a list of intervals, calculate the maximum number of overlapping intervals.
# Each interval is inclusive at both ends.
def solve(intervals): # list of pairs
tmp1 = set(y for x in intervals for y in x)
tmp2 = max(map(lambda x: sum(1 if y[0] <= x <= y[1] else 0 for y in intervals), tmp1))
print "%s %d" % (intervals, tmp2)
solve([(1,5), (2,4), (3, 6)])
solve([(1,5), (2,3), (4, 6), (7,9)])
View extractCommentsWithPageNum.groovy
/*
* Copyright (c) 2018, Venkatesh-Prasad Ranganath
*
* Licensed under BSD 3-clause License
*
* Author: Venkatesh-Prasad Ranganath
*
* Adapted from https://stackoverflow.com/questions/33253757/java-apache-pdfbox-extract-highlighted-text
*/
View max_subseq_sum2.py
# Given a sequence of positive numbers, pick a sub-sequence such that
# - the sum of numbers in the sub-sequence is maximal and
# - the sub-sequence does not contain consecutive numbers from the sequence.
#
# Assuming the index of the list goes from 1 thru n,
# f(l, n>0) = max(f(l, n-2) + l(n), f(l, n-1))
# f(l, n<1) = 0
def answer(L):
if len(L) == 1:
View max_subseq_sum.py
# Given a list of numbers L with
# - numbers between -100 and 100 (both inclusive)
# - at least one positive number
# - length between 3 and 7000 (both inclusive)
# and a number k between 3 and length of L (both inclusive)
# find the maximum number that can be formed by summing a
# contiguous sub-list of L that is not longer than k.
def answer(L, k):
len_L = len(L)
View num_to_winning_patterns.py
# A token is placed on the first cell of a sequence of n cells.
# There are t moves for the token -- 1 position to left, 1 position to right, or stay in the same cell.
# Find the number of sequences of t moves that will get the token to the n-th cell and there are no
# left moves once the token gets to the n-th cell.
def answer(T, N):
if T < N - 1:
return 0
pos_to_paths = {i:0 for i in range(1, N + 1)}
pos_to_paths[1] = 1
for t in range(1, T + 1):
View num_seqs_generating_same_BST.py
# A binary tree is created from a sequence of numbers seq.
# Find the number of permutations of the sequence that result in
# an identical tree.
def combo(n, r):
n_fact = reduce(lambda acc, v: acc * v, xrange(n - r + 1, n + 1))
r_fact = reduce(lambda acc, v: acc * v, xrange(1, r + 1))
return n_fact / r_fact
def get_num_seqs(seq_for_tree):
View anonymizeNames.py
from random import randrange, sample, shuffle
alphas = list('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
nums = list('1234567890')
shuffle(alphas)
shuffle(nums)
def scramble(s, seen):
while True:
ret = ''.join([(nums[int(x)] if x in nums else