This file contains hidden or 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
| require "open-uri" | |
| require "uri" | |
| playlist_uri = "http://127.0.0.1:9001/broadcasts/1/hls/index.m3u8" | |
| Segment = Struct.new :uri, :duration | |
| Playlist = Struct.new :seq_no, :segments | |
| def parse_m3u8(src, uri = "") |
This file contains hidden or 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
| def busyLoop(time: Int, threads: Int) = Action { implicit r => | |
| val started = System.currentTimeMillis() | |
| val workers = (0 until threads).map { _ => | |
| val out = new Thread({ () => | |
| val digest = MessageDigest.getInstance("SHA-256") | |
| while (started + time * 1000 >= System.currentTimeMillis()) { | |
| digest.update(UUID.randomUUID().toString.getBytes(StandardCharsets.US_ASCII)) | |
| } | |
| }) | |
| out.start() |
This file contains hidden or 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 * as Rx from "rxjs"; | |
| import * as CP from "child_process"; | |
| function spawn(cmd: string, args: string[] = []): Rx.Observable<ProcessOutput> { | |
| return Rx.Observable.create(observer => { | |
| let process = CP.spawn(cmd, args); | |
| process.addListener("error", err => { | |
| observer.error(err); | |
| }); | |
| process.addListener("exit", code => { |
This file contains hidden or 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
| lazy val generateBuildConfig = taskKey[Seq[File]]("Generates `build.conf`.") | |
| generateBuildConfig := { | |
| val dest = (resourceManaged in Compile).value / "build.conf" | |
| val hash = Process("git rev-parse HEAD").!!.trim() | |
| val time = java.time.Instant.now() | |
| streams.value.log.info(s"Generating a build.conf: $dest") | |
| IO.write(dest, | |
| s"""build.info { | |
| | hash: "$hash" |
This file contains hidden or 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
| netsh interface portproxy add v4tov4 listenport=443 listenaddress=127.0.0.1 connectport=9443 connectaddress=127.0.0.1 protocol=tcp | |
| netsh interface portproxy delete |
This file contains hidden or 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 sys, os, itertools, collections, zipfile | |
| if len(sys.argv) < 2: | |
| sys.stderr.writelines("Usage: python ziptree.py <path-to-zip>") | |
| sys.exit(-1) | |
| Entry = collections.namedtuple('Entry', ['name', 'children']) | |
| def tree_of_zip(path_to_zip, only_dir=False): | |
| stack = [Entry("", [])] |
This file contains hidden or 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 re | |
| # Strong Password Detection | |
| def is_strong_password(src): | |
| return all(re.compile(e).search(src) for e in [ | |
| r'.{8}', | |
| r'[a-z]', | |
| r'[A-Z]', | |
| r'[0-9]' | |
| ]) |
This file contains hidden or 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 akka.stream.Attributes | |
| import akka.stream.FlowShape | |
| import akka.stream.Inlet | |
| import akka.stream.Outlet | |
| import akka.stream.scaladsl.Flow | |
| import akka.stream.stage.GraphStage | |
| import akka.stream.stage.GraphStageLogic | |
| import akka.stream.stage.InHandler | |
| import akka.stream.stage.OutHandler |
This file contains hidden or 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
| def waitForSIGTERM(cv: AnyRef = new Object()) { | |
| Runtime.getRuntime.addShutdownHook( | |
| new Thread(() => cv.synchronized(cv.notify())) | |
| ) | |
| @tailrec | |
| def loop(): Unit = try cv.synchronized(cv.wait()) | |
| catch { | |
| case _: InterruptedException => loop() | |
| } | |
| loop() |
This file contains hidden or 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 itertools import * | |
| for e in takewhile(lambda e: e != 1, accumulate(chain([7], count()), lambda n, _: n // 2 if (n % 2) == 0 else n * 3 + 1)): | |
| print(e) |