Skip to content

Instantly share code, notes, and snippets.

@non
non / noise.py
Created December 16, 2012 06:09
Port of Java simplex noise code to Python for fizzix
#!/usr/bin/python
from math import floor, sqrt
from random import randint
import sys
# given floats x and y, generate noise values from -1.0 to 1.0.
#
# coordinate.
# based on code at:
@non
non / kleene.scala
Last active December 11, 2015 00:28
Rough Scala translation of http://r6.ca/blog/20110808T035622Z.html using Scala/Spire
package spire.example
import Predef.{any2stringadd => _, _}
import spire.algebra._
import spire.implicits._
import spire.syntax._
import scala.reflect.ClassTag
import scala.annotation.tailrec
@non
non / gist:4566540
Created January 18, 2013 17:47
Twine snippet to put in StoryMenu for audio player
<html>
<audio id="music" style="height:30px;width:300px" src="inevitable.mp3" loop="true" autoplay="true" controls="controls">
no audio
</audio>
</html>
@non
non / mandelbrot.scala
Created January 22, 2013 07:03
Simple example I'm cooking up...
package spire.example
import spire.implicits._
import spire.math._
import spire.syntax._
import scala.annotation.tailrec
object MandelbrotDemo {
/**
import scala.annotation.tailrec
object SnapToReal {
def apply(n: Double, limit: Int = 10, thresh: Double = 0.00000000001): (Double, Int, Int) = {
@tailrec
def outer(i: Int, ex: Int, div: Int): (Double, Int, Int) = {
if (i >= limit) {
(n, 1, 1)
} else if (div < 1) {
outer(i + 1, 1, i + 1)
d_m@vein ~ $ scala
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val f0 = () => 999
f0: () => Int = <function0>
scala> val f1 = (n: Int) => n + 123
f1: Int => Int = <function1>
package angles
import spire.algebra._
import scala.math.Pi
object Angle {
def apply(n: Double): Angle =
if (n < 0.0) new Angle(n % 360.0 + 360.0) else new Angle(n % 360.0)
def fromRadians(n: Double): Angle =
Angle(n * 360.0 / (2.0 * Pi))
@non
non / fizzugh.scala
Created August 30, 2013 15:26
This is the solution to a useless interview problem.
// fizzbuzz in 116 chars
(1 to 100)map{n=>val v=Seq(3->"fizz",5->"buzz").collect{case(m,s)if n%m==0=>s}.mkString;if(v=="")n.toString else v}
// less cryptic version
val mods = Seq(3 -> "fizz", 5 -> "buzz")
(1 to 100).map { n =>
val words = mods.collect {
case (m, s) if n % m == 0 => s
}
val v = words.mkString()
@non
non / infset.scala
Last active December 22, 2015 04:18
Examples of non-container set implementations for Scala.
package spire.examples
import spire.algebra._
import spire.math.{Natural, UInt}
import scala.collection.mutable
object SetUtil {
def powerStream[A](members: Stream[A]): Stream[Set[A]] = {
val done = Stream.empty[Set[A]]
[info] benchmark us linear runtime
[info] example 47.3 =
[info] integers 89.2 ==
[info] jp10 180.6 ====
[info] jp100 1089.3 =========================
[info] jp50 585.0 =============
[info] numbers 363.8 ========
[info] twitter1 15.4 =
[info] twitter10 96.8 ==
[info] twitter100 936.2 =====================