Skip to content

Instantly share code, notes, and snippets.

// some old stuff
--trim-left 2240 --trim-top 760 -n 48 --gain 10 -o /home/hhrutz/Documents/projects/Imperfect/site-9b/frame-%d.jpg
// DifferenceProcess (b)
--trim-left 2240 --trim-top 760 -n 48 --gain 10 -i /home/hhrutz/Documents/projects/Imperfect/site-9/frame-%d.jpg -o /home/hhrutz/Documents/projects/Imperfect/site-9out_b/frame-%d.jpg --last 1627
// DifferenceProcess (cover)
-i /home/hhrutz/Documents/projects/Imperfect/site-9/frame-%d.jpg -o /home/hhrutz/Documents/projects/Imperfect/site-9out_cover/frame-%d.jpg --width 2528 --height 1288 --trim-left 351 --trim-top 436 --start 1480 --last 1627 --gain 16 --seq-len 40 --threshold 0.15
import java.nio.ByteBuffer
import com.ning.http.client
import com.ning.http.client.AsyncHandler.STATE
import com.ning.http.client.HttpResponseHeaders
import com.ning.http.client.resumable.ResumableAsyncHandler
import dispatch.OkHandler
object FileWithProgress {
def apply(file: File)(progress: (Long, Long) => Unit): ResumableAsyncHandler[_] = {
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: A6FA133D-46D9-4F65-AE64-57395075CF9E
Device Start End Sectors Size Type
/dev/sda1 2048 1953523711 1953521664 931.5G Linux filesystem
$ sudo update-grub
[sudo] password for hhrutz:
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-4.9.0-1-amd64
Found initrd image: /boot/initrd.img-4.9.0-1-amd64
Found linux image: /boot/vmlinuz-3.16.0-4-amd64
Found initrd image: /boot/initrd.img-3.16.0-4-amd64
Found Windows 10 on /dev/sdb1
done
s.boot;
(
~bufDur = 4.0; // total circular buf duration in seconds
~minBlobDur = 0.2; // minimum blob duration in seconds
~maxBlobDur = ~bufDur / 2; // maximum blob duration in seconds
~sr = 44100; // sample rate in Hz
~lowThresh = -20.dbamp; // lower envelope threshold
~highThresh = -12.dbamp; // upper envelope threshold

I have an API for reading multi-dimensional arrays, requiring to pass a vector of ranges to read sub-rectangles (or hypercubes) from the backing array. I want to read this array "linearly", all elements in some given order with arbitrary chunk sizes. Thus, the task is with an off and a len, to translate the elements covered by this range into the smallest possible set of hyper-cubes, i.e. the smallest number of read commands issued in the API.

For example, we can calculate index vectors for the set of dimensions giving a linear index:

def calcIndices(off: Int, shape: Vector[Int]): Vector[Int] = {
  val modsDivs = shape zip shape.scanRight(1)(_ * _).tail
  modsDivs.map { case (mod, div) =>
    (off / div) % mod
  }

}

I have an API for reading multi-dimensional variables that has a read method. For simplicity, I define these in a pseudo-Scala language here, but the question is really about the algorithm not the particular language. So:

trait Variable[A] {
  def shape: List[Int]

  def read(sections: List[Range]): List[A]
}

(in the concrete case the variable is ucar.nc2.Variable, the range is ucar.ma2.Section, and the data is ucar.ma2.Array in UCAR's NetCDF-Java library). I have an input spec for sections, e.g.

import scala.collection.{GenTraversableOnce, LinearSeq, LinearSeqLike, mutable}
import scala.collection.generic.CanBuildFrom
object Message {
def apply[A](args: A*): Message[A] = new Message(args)
def newBuilder[A]: mutable.Builder[A, Message[A]] =
new mutable.ArrayBuffer[A].mapResult(buf => new Message(buf))
implicit def builderFactory[A]: CanBuildFrom[Any, A, Message[A]] = new CanBuildFrom[Any, A, Message[A]] {
// note: this doesn't demonstrate anything useful yet
SynthDef.recv("SubsampleOffset") {
val addOff = "addOff".kr(3)
val in = Impulse.ar(2) * 0.3 // some input.
val sampDur = SampleDur.ir // duration of one sample
val pad = 4 // DelayC needs at least 4 samples buffer
val sampOff = 1 - SubsampleOffset.ir + // balance out subsample offset
MouseX.kr(0, addOff) // add a mouse dependent offset
import scala.collection.immutable.{IndexedSeq => Vec}
import scala.annotation.tailrec
import scala.util.Random
def coin()(implicit random: Random): Boolean = random.nextBoolean()
object StrangeUrn {
def apply[A](set: Set[A])(implicit random: Random): StrangeUrn[A] = {
require(set.nonEmpty)
new Impl(in = random.shuffle(set.toIndexedSeq), out = Vector.empty)