Skip to content

Instantly share code, notes, and snippets.

implicit class VectorOps(x: Vector[Double]) {
def * (scalar: Double): Vector[Double] = x.map(_ * scalar)
def / (scalar: Double): Vector[Double] = x.map(_ / scalar)
def + (scalar: Double): Vector[Double] = x.map(_ + scalar)
def - (scalar: Double): Vector[Double] = x.map(_ - scalar)
def + (y: Vector[Double]): Vector[Double] = (x, y).zipped.map(_ + _)
def - (y: Vector[Double]): Vector[Double] = (x, y).zipped.map(_ - _)
}
def dot(u: Vector[Double], v: Vector[Double]): Double =
// quick translation from http://www.geeksforgeeks.org/inplace-m-x-n-size-matrix-transpose/
def matrixInplaceTranspose[A](a: Array[A], rows: Int, columns: Int): Unit = {
val size = rows * columns - 1
// bitset<HASH_SIZE> b; // hash to mark moved elements
val b = new collection.mutable.BitSet(size)
b.add(0)
b.add(size)
var i = 1; // Note that A[0] and A[size-1] won't move
while (i < size) {
val b = Buffer(s)
b.alloc(numFrames = 44100 * 10)
b.zero()
play {
val sig = PlayBuf.ar(numChannels = 1, buf = b.id, loop = 1)
// val in = WhiteNoise.ar(0.1)
val in = SinOsc.ar(XLine.kr(400, 1000, 10)) * 0.1
RecordBuf.ar(in = in, buf = b.id, offset = 44100 * 5, loop = 1)
val ref = SinOsc.ar(1000) * 0.1
import RPi.GPIO as GPIO
import time
colors = [0xFF00, 0x00FF, 0x0FF0, 0xF00F]
pins = {'pin_R':11, 'pin_G':12} # pins is a dict
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
for i in pins:
GPIO.setup(pins[i], GPIO.OUT) # Set pins' mode is output
GPIO.output(pins[i], GPIO.HIGH) # Set pins to high(+3.3V) to off led
#!/usr/bin/env python
# https://learn.adafruit.com/basic-resistor-sensor-reading-on-raspberry-pi/basic-photocell-reading
# Example for RC timing reading for Raspberry Pi
# Must be used with GPIO 0.3.1a or later - earlier verions
# are not fast enough!
import RPi.GPIO as GPIO, time, os
DEBUG = 1
# #####################################################
# Python Library for 3x4 matrix keypad using
# 7 of the avialable GPIO pins on the Raspberry Pi.
#
# This could easily be expanded to handle a 4x4 but I
# don't have one for testing. The KEYPAD constant
# would need to be updated. Also the setting/checking
# of the colVal part would need to be expanded to
# handle the extra column.
#

Installation and Setup

java.util.NoSuchElementException: key not found: Local(src,0)
at scala.collection.MapLike$class.default(MapLike.scala:228)
at scala.collection.AbstractMap.default(Map.scala:58)
at scala.collection.mutable.HashMap.apply(HashMap.scala:64)
at scala.scalanative.compiler.analysis.UseDef$$anonfun$scala$scalanative$compiler$analysis$UseDef$$enterDeps$1$1.apply(UseDef.scala:69)
at scala.scalanative.compiler.analysis.UseDef$$anonfun$scala$scalanative$compiler$analysis$UseDef$$enterDeps$1$1.apply(UseDef.scala:68)
at scala.collection.mutable.UnrolledBuffer$Unrolled.foreach(UnrolledBuffer.scala:224)
at scala.collection.mutable.UnrolledBuffer.foreach(UnrolledBuffer.scala:130)
at scala.scalanative.compiler.analysis.UseDef$.scala$scalanative$compiler$analysis$UseDef$$enterDeps$1(UseDef.scala:68)
at scala.scalanative.compiler.analysis.UseDef$$anonfun$apply$4$$anonfun$apply$5.apply(UseDef.scala:96)
Error:scalac: Error: native.this.FunctionPtr.fromFunction1(jack_shutdownFun) (of class scala.reflect.internal.Trees$ApplyImplicitView)
scala.MatchError: native.this.FunctionPtr.fromFunction1(jack_shutdownFun) (of class scala.reflect.internal.Trees$ApplyImplicitView)
at scala.scalanative.nscplugin.NirCodeGen$SaltyCodePhase.genFunPtrOp(NirCodeGen.scala:1314)
at scala.scalanative.nscplugin.NirCodeGen$SaltyCodePhase.genPrimitiveOp(NirCodeGen.scala:923)
at scala.scalanative.nscplugin.NirCodeGen$SaltyCodePhase.genApply(NirCodeGen.scala:874)
at scala.scalanative.nscplugin.NirCodeGen$SaltyCodePhase$$anonfun$genExpr$1.apply(NirCodeGen.scala:505)
at scala.scalanative.nscplugin.NirCodeGen$SaltyCodePhase$$anonfun$genExpr$1.apply(NirCodeGen.scala:463)
at scala.scalanative.nscplugin.NirCodeGen$SaltyCodePhase.notMergeableGuard(NirCodeGen.scala:417)
at scala.scalanative.nscplugin.NirCodeGen$SaltyCodePhase.genExpr(NirCodeGen.scala:462)
at scala.scalanative.nscplugin.NirCodeGen$SaltyCodePhase$$anonfun$genMethodArgs$2.a
Unresolved dependencies:
`@java.nio.Buffer::capacity_i32`
`@java.nio.Buffer::clear_class.java.nio.Buffer`
`@java.nio.Buffer::flip_class.java.nio.Buffer`
`@java.nio.Buffer::hasRemaining_bool`
`@java.nio.Buffer::limit_i32_class.java.nio.Buffer`
`@java.nio.Buffer::position_i32`
`@java.nio.Buffer`
`@java.nio.ByteBuffer$::allocate_i32_class.java.nio.ByteBuffer`
`@java.nio.ByteBuffer$`