This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2018, Venkatesh-Prasad Ranganath | |
* | |
* Licensed under BSD 3-clause License | |
* | |
* Author: Venkatesh-Prasad Ranganath | |
*/ | |
import groovy.transform.Field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: worker_raspi | |
remote_user: life | |
tasks: | |
- name: iperf | |
shell: iperf -t 20 -c 192.168.2.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chrono> | |
#include <fstream> | |
#include <iostream> | |
using namespace std; | |
int k = 256; | |
int numOfNums = k * 1024 * 1024; | |
int reps = 6; | |
void writeUsingFile(string fileName) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PermutationGenerator(numOfValues:Int) : Iterator<List<Int>> { | |
private val maxPos = numOfValues - 1 | |
private val values = (0..maxPos).shuffled() | |
private var currPerm = (0..maxPos).toMutableList() | |
@Synchronized override fun hasNext() = currPerm.isNotEmpty() | |
@Synchronized override fun next(): List<Int> { | |
val perm = currPerm.toList() | |
val j = (maxPos - 1 downTo 0).find { currPerm[it] < currPerm[it + 1] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.streams.asSequence | |
import kotlin.system.measureTimeMillis | |
val k = 500000000L | |
println(measureTimeMillis { | |
java.util.stream.LongStream.range(1, k) | |
.parallel() | |
.asSequence() | |
.map { it.toString().length.toLong() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable.ArrayBuffer | |
import scala.util.Random | |
object M { | |
def main(args: Array[String]) { | |
val t = new ArrayBuffer[Long]() | |
while (true) { | |
t += Random.nextLong | |
if (t.length % 10000 == 0) { | |
System.gc() |