Skip to content

Instantly share code, notes, and snippets.

import scala.util.Random
object Sudoku {
lazy val localSquareLength = 3
lazy val length = localSquareLength * localSquareLength
lazy val totalCells = length * length
lazy val sideIndices = 0 to (length - 1)
lazy val legalValues = 1 to length
lazy val emptyCells = for {
y <- sideIndices
package music
import org.junit.Assert._
import org.junit.Test
import util.ControlStructures._
import util.ImplicitConversions._
object Candle {
def maxGap(len: Int) = len / 2
next week - 2 die
import Html exposing (..)
import Html.App as App
import Html.Events exposing (..)
import Html.Attributes exposing (..)
import Random
import Array
import List exposing (..)
object QInterpolatorExample extends App {
implicit class QInterpolator(val sc: StringContext) extends AnyVal {
def q(args: Any*): Seq[String] = sc.raw().split("\n").map(_.trim).filter(_.nonEmpty)
}
val urls:Seq[String] = q""" http://angel.co/mile-high-organics
http://angel.co/kindara
http://angel.co/precog
http://angel.co/pivotdesk"""
}
<html>
<body>
<a href="#" onclick="play()">Play</a>
</body>
</html>
<script type="text/javascript" src="https://www.dropbox.com/s/e0sejqv37b1g867/soundmanager2-jsmin.js?dl=1"></script>
<script type="text/javascript">
var sound;
var url = "https://www.dropbox.com/s/lu9wx75la7tkrsf/duck.mp3?dl=1";
function play() {
@adamrabung
adamrabung / sm2 replay problem: Safari
Created October 6, 2014 10:40
This log represents 3 clicks of the play button, in Safari. Each click of the play button logs a "play clicked". Line 24 is where the unexpected silence happens.
[Log] play clicked (sm.html, line 10)
[Log] soundManager.createSound(): s (https://www.dropbox.com/s/lu9wx75la7tkrsf/duck.mp3?dl=1) (X0zYxh3esNiu8tC7GRhK2YT10MyagcEeQFL32EbWZBlPMbO4iun8U7nD1GVIkjvg, line 32)
[Log] s: Merged options: (X0zYxh3esNiu8tC7GRhK2YT10MyagcEeQFL32EbWZBlPMbO4iun8U7nD1GVIkjvg, line 32)
Object
[Log] s: Using HTML5 (X0zYxh3esNiu8tC7GRhK2YT10MyagcEeQFL32EbWZBlPMbO4iun8U7nD1GVIkjvg, line 32)
[Log] s: play(): Attempting to load (X0zYxh3esNiu8tC7GRhK2YT10MyagcEeQFL32EbWZBlPMbO4iun8U7nD1GVIkjvg, line 32)
[Log] s: load (https://www.dropbox.com/s/lu9wx75la7tkrsf/duck.mp3?dl=1) (X0zYxh3esNiu8tC7GRhK2YT10MyagcEeQFL32EbWZBlPMbO4iun8U7nD1GVIkjvg, line 32)
[Log] s: waiting (X0zYxh3esNiu8tC7GRhK2YT10MyagcEeQFL32EbWZBlPMbO4iun8U7nD1GVIkjvg, line 32)
[Log] s: loadstart (X0zYxh3esNiu8tC7GRhK2YT10MyagcEeQFL32EbWZBlPMbO4iun8U7nD1GVIkjvg, line 32)
@adamrabung
adamrabung / sm2 replay problem: Chrome
Last active August 29, 2015 14:07
This log represents 3 clicks of the play button, in Chrome. Each click of the play button logs a "play clicked". Line 24 is where the unexpected silence happens.
SoundManager 2 HTML5 support: mp3 = true, mp4 = true, ogg = true, opus = true, wav = true 8Q0gAAmfUjObkPLwD7LIr1DOP2XYUnRw87akvFnF2I8unOk3duzaWAoXfH6eVlC2?dl=1:32
SoundManager 2: Ready. ✓ 8Q0gAAmfUjObkPLwD7LIr1DOP2XYUnRw87akvFnF2I8unOk3duzaWAoXfH6eVlC2?dl=1:32
play clicked sm.html:10
soundManager.createSound(): s (https://www.dropbox.com/s/lu9wx75la7tkrsf/duck.mp3?dl=1) 8Q0gAAmfUjObkPLwD7LIr1DOP2XYUnRw87akvFnF2I8unOk3duzaWAoXfH6eVlC2?dl=1:32
s: Merged options: Object {id: "s", url: "https://www.dropbox.com/s/lu9wx75la7tkrsf/duck.mp3?dl=1", autoLoad: false, autoPlay: false, from: null…} 8Q0gAAmfUjObkPLwD7LIr1DOP2XYUnRw87akvFnF2I8unOk3duzaWAoXfH6eVlC2?dl=1:32
s: Using HTML5 8Q0gAAmfUjObkPLwD7LIr1DOP2XYUnRw87akvFnF2I8unOk3duzaWAoXfH6eVlC2?dl=1:32
s: play(): Attempting to load 8Q0gAAmfUjObkPLwD7LIr1DOP2XYUnRw87akvFnF2I8unOk3duzaWAoXfH6eVlC2?dl=1:32
s: load (https://www.dropbox.com/s/lu9wx75la7tkrsf/duck.mp3?dl=1) 8Q0gAAmfUjObkPLwD7LIr1DOP2XYUnRw87akvFnF2I8unOk3duzaWAoXfH6eVlC2?dl=1:32
s: waiting 8Q0gAAmfUjObkPLwD
import State._
case class State[S, +A](run: S => (A, S)) {
def map[B](f: A => B): State[S, B] = flatMap(a => unit(f(a)))
def map2[B, C](sb: State[S, B])(f: (A, B) => C): State[S, C] = flatMap(a => sb.map(b => f(a, b)))
def flatMap[B](f: A => State[S, B]): State[S, B] = State(s => {
val (a, s1) = run(s)
f(a).run(s1)
})
}
<html>
<body>
<a href="#" onclick="play()">Play</a>
</body>
</html>
<script type="text/javascript" src="https://www.dropbox.com/s/e0sejqv37b1g867/soundmanager2-jsmin.js?dl=1"></script>
<script type="text/javascript">
function play() {
console.log("play clicked")
var sound = soundManager.createSound({
def weightedShuffle[T](ts: List[T], weight: T => Int): List[T] = {
case class ValueAndCumulativeWeight(t: T, cumWeight: Int)
@tailrec def weightedShuffle0(ts: List[T], weight: T => Int, acc: List[T]): List[T] = ts match {
case Nil => acc
case only :: Nil => acc :+ only
case head :: tail => {
val selection = Randoms.randomInt(0, ts.map(weight).sum)
val choice = tail
.scanLeft(ValueAndCumulativeWeight(head, weight(head)))((soFar, x) => ValueAndCumulativeWeight(x, soFar.cumWeight + weight(x)))
.find(_.cumWeight >= selection)