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
package org.asarkar.data | |
sealed trait Edge[T] { | |
def tail: T | |
def head: T | |
} | |
sealed trait WeightedEdge[T] extends Edge[T] { | |
def weight: Double |
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
#!/bin/bash | |
# description: Cisco Anyconnect CSD wrapper for OpenConnect | |
# author: https://github.com/asarkar/ | |
# gist: https://gist.github.com/asarkar/fb4452a4abdf9e4a9752a7d55d2cdc93 | |
# connect: sudo openconnect --background \ | |
# --user=<username> \ | |
# --authgroup=1 \ | |
# --csd-user=<localhost username> \ | |
# --csd-wrapper=<script location on localhost> \ | |
# --os=mac-intel \ |
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
#!/bin/bash | |
# Enter your vpn host here | |
CSD_HOSTNAME= | |
if [[ -z ${CSD_HOSTNAME} ]] | |
then | |
echo "Define CSD_HOSTNAME with vpn-host in script text. Exiting." | |
exit 1 | |
fi |
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
blocking-io-dispatcher { | |
type = Dispatcher | |
executor = "thread-pool-executor" | |
thread-pool-executor { | |
fixed-pool-size = 16 | |
} | |
throughput = 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
val l = (1 to 20) | |
val isEven = (i: Int) => i % 2 == 0 | |
val isLtTen = (i: Int) => i < 10 | |
val isGtTen = (i: Int) => i > 10 | |
val p1 = List(isEven, isLtTen) | |
val p2 = List(isEven, isGtTen) | |
val r1 = l.find(i => p1.forall(_ (i))) | |
val r2 = l.find(i => p2.forall(_ (i))) |
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
@SpringCloudApplication | |
@EnableFeignClients | |
public class DemoApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(DemoApplication.class, args); | |
} | |
@FeignClient(name = "httpbin", url = "httpbin.org") | |
public interface HttpBinClient { | |
@RequestMapping(path = "/post", method = POST, produces = APPLICATION_JSON_VALUE) |
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
ConnectableFlowable<Integer> pub = Flowable.range(1, 10000) | |
.publish(); | |
pub.debounce(1, SECONDS) | |
.subscribeOn(computation()) | |
.subscribe(new DefaultSubscriber<Integer>() { | |
@Override | |
public void onStart() { | |
request(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
public class FrequencyCalculator extends RecursiveTask<Map<Character, Integer>> { | |
private static final long serialVersionUID = -5328480156308631556L; | |
private static final int NUM_PROCESSORS = Runtime.getRuntime() | |
.availableProcessors(); | |
private final String word; | |
public FrequencyCalculator(String word) { | |
this.word = word; |
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
sealed abstract class BinaryTree | |
case class BinTreeLeaf(value: Int) extends BinaryTree | |
case class BinTreeNode(left: BinaryTree, right: BinaryTree) extends BinaryTree | |
def leafSum(tree: BinaryTree): Int = tree match { | |
case node: BinTreeNode => leafSum(node.left) + leafSum(node.right) | |
case leaf: BinTreeLeaf => leaf.value | |
} | |
"Method leafSum" should "traverse a binary tree in order" in { |
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
trait Logged { def log(msg: String) {} } | |
trait Chattery extends Logged { def chatter = log("I chatter. Do you mind?") } | |
trait ConsoleLogger extends Logged { override def log(msg: String) = println(msg) } | |
scala> val ch = new Chattery() with ConsoleLogger | |
ch: Chattery with ConsoleLogger = $anon$1@1ef7fe8e | |
scala> ch.chatter |
NewerOlder