Skip to content

Instantly share code, notes, and snippets.

Avatar

Venkatesh-Prasad Ranganath rvprasad

View GitHub Profile
@rvprasad
rvprasad / iperf-client-best-case.yml
Last active Feb 5, 2019
Measure network throughput in best case scenario -- one-to-one
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'
@rvprasad
rvprasad / iperf-client-worst-case.yml
Last active Feb 5, 2019
Measure network throughput in worst case scenario -- many-to-one
View iperf-client-worst-case.yml
- hosts: worker_raspi
remote_user: life
tasks:
- name: iperf
shell: iperf -t 20 -c 192.168.2.10
@rvprasad
rvprasad / overlapping_intervals.py
Created Nov 6, 2018
Calculate the maximum number of overlapping intervals
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)])
@rvprasad
rvprasad / extractCommentsWithPageNum.groovy
Last active Jul 20, 2018
Extracts comments associated with highlights in a PDF document along with page numbers
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
*/
@rvprasad
rvprasad / anonymizeNames.py
Last active May 5, 2018
Anonymizes the names (in names.txt) without disturbing the order and frequency of alphabet and number positions
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
@rvprasad
rvprasad / bfsSolver2.groovy
Created Apr 15, 2018
Identifies a queue-based BFS traversal order of nodes of a given directed graph using z3 solver
View bfsSolver2.groovy
/*
* Copyright (c) 2018, Venkatesh-Prasad Ranganath
*
* Licensed under BSD 3-clause License
*
* Author: Venkatesh-Prasad Ranganath
*/
import groovy.transform.Field
@rvprasad
rvprasad / dfsSolver.groovy
Last active Apr 16, 2018
Identifies a DFS traversal order of nodes of a given directed graph using z3 solver
View dfsSolver.groovy
/*
* Copyright (c) 2018, Venkatesh-Prasad Ranganath
*
* Licensed under BSD 3-clause License
*
* Author: Venkatesh-Prasad Ranganath
*/
import groovy.transform.Field
@rvprasad
rvprasad / bfsSolver.groovy
Created Apr 15, 2018
Identifies a BFS traversal order of nodes of a given directed graph using z3 solver
View bfsSolver.groovy
/*
* Copyright (c) 2018, Venkatesh-Prasad Ranganath
*
* Licensed under BSD 3-clause License
*
* Author: Venkatesh-Prasad Ranganath
*/
import groovy.transform.Field
@rvprasad
rvprasad / simpleSudokuSolver.groovy
Last active Apr 14, 2018
Solves a simplified version of sudoku (w/ only row and column constraints) using z3 SAT solver
View simpleSudokuSolver.groovy
/*
* Copyright (c) 2018, Venkatesh-Prasad Ranganath
*
* Licensed under BSD 3-clause License
*
* Author: Venkatesh-Prasad Ranganath
*/
// Solves a simplified version of sudoku (w/ only row and column constraints)
// using SAT solving
@rvprasad
rvprasad / 3NumSorter.groovy
Last active Apr 11, 2018
Sorts three numbers by encoding the sorting problem as a SAT problem
View 3NumSorter.groovy
/*
* Copyright (c) 2018, Venkatesh-Prasad Ranganath
*
* Licensed under BSD 3-clause License
*
* Author: Venkatesh-Prasad Ranganath
*/
// Sorts three numbers using SAT solving
// Script uses z3 solver (https://github.com/Z3Prover/z3)