Skip to content

Instantly share code, notes, and snippets.

@miguel-negrao
miguel-negrao / gist:1330241
Created November 1, 2011 09:55
Newton-Raphson Square Roots
/**
*
* Newton-Raphson Square Roots
* as is shown in "why functional programming matters"
* http://www.cs.utexas.edu/~shmat/courses/cs345/whyfp.pdf
*/
object NewtonRoots {
//algorithm to approach the square root of n
@miguel-negrao
miguel-negrao / MyTestApp
Created April 20, 2012 22:05
My take on synthesis with lazy infinite lists
/**
* User: miguelnegrao
* Date: 20/04/12
*/
import annotation.tailrec
import javax.sound.sampled._
import math._
import scalaz._
import Scalaz._
@miguel-negrao
miguel-negrao / gist:2654012
Created May 10, 2012 15:42
Gamelan practice
(
i = 2**(1/9);
~innerIntervals = [i,i,i**2,i,i,i,i**2];
~intervalsToRoot = ([1]++~innerIntervals).inject([], { |state,x|
if(state.size == 0){
[x]
} {
state ++ [state.last*x]
}
@miguel-negrao
miguel-negrao / gist:2718312
Created May 17, 2012 11:36
Saw waves through comb filters
(
var r = { |f| {
var combF, sawF, c, r, sine , pulse;
sine = { SinOsc.kr(rrand(0.01,0.03)).range(0.0,1.0) };
pulse = { Pulse.kr(rrand(0.1,0.3)) };
r = 10.collect{
sawF = 2.collect{ ( ( (pulse ! 2).sum + LFNoise2.kr(1) ) / 3).range(f,f+300) };
y = Saw.ar( sawF );
combF = ( ( (pulse ! 2).sum + (sine ! 3).sum ) /5).rangeExp(0.0001,0.009);
c = CombC.ar(y, 0.01, combF, 0.2);
@miguel-negrao
miguel-negrao / gist:2876191
Created June 5, 2012 16:50
FP3D - SuperCollider - drawing a cube
(
var width = 500, height = 400, rate = 0.005;
var u = UserView(nil, Rect(128, 64, width, height) );
var sides = [
// Front face
[[-1.0, -1.0, 1.0],
[1.0, -1.0, 1.0],
[1.0, 1.0, 1.0],
@miguel-negrao
miguel-negrao / gist:2905841
Created June 10, 2012 14:14
reactive-banana throttling events
{-----------------------------------------------------------------------------
------------------------------------------------------------------------------}
{-# LANGUAGE ScopedTypeVariables #-} -- allows "forall t. NetworkDescription t"
import Graphics.UI.WX hiding (Event)
import Reactive.Banana
import Reactive.Banana.WX
{-----------------------------------------------------------------------------
@miguel-negrao
miguel-negrao / create_ad_hoc.applescript
Created October 29, 2012 23:22
automate ad-hoc network creation
-- to create. This will also attempt to set the network location
-- to that name as well.
-- Set NetworkPassword to be your wireless network password. It MUST BE
-- 13 characters long (or 26 hex digits).
property NetworkName : "helloworld"
property NetworkPassword : "77777"
property CreateMenuName : "Criar rede…"
@miguel-negrao
miguel-negrao / gist:3977293
Created October 29, 2012 23:23
restore network config to default (dhcp)
try
do shell script "/usr/sbin/scselect " & 0
end try
@miguel-negrao
miguel-negrao / monadTransHelloWorld.hs
Created October 30, 2012 11:06
Monad Transformers hello world
module Main where
import Control.Monad.State
import Control.Monad.Trans
import Control.Monad.Maybe
import Control.Monad.Reader
import Control.Monad.Writer
type X = ReaderT String (WriterT [String] (StateT Int Maybe)) Int
@miguel-negrao
miguel-negrao / scalaColliderZExample1.scala
Created October 30, 2012 11:14
ScalaColliderZ example 1
import de.sciss.synth._
import ugen._
import scalaz._
import Scalaz._
import concurrent._
import org.friendlyvirus.mn.ScalaColliderZ._
object Test1 {
def main(args: Array[String]) {