Skip to content

Instantly share code, notes, and snippets.

@smosher
smosher / phasedist.io
Created July 30, 2014 19:48
Phase Distortion Synthesis
// https://en.wikipedia.org/wiki/Phase_distortion_synthesis
// NB. completely untested
Range
pi := 3.14159265
tau := 2 * pi
FreqCtr := Object clone do(
@smosher
smosher / normals.pl6
Created September 20, 2011 12:15
basic normal calculation
sub vector-to-unit( @vec ) { @vec >>/>> sqrt( [+] @vec >>**>> 2 ) }
sub cross-product( @v1, @v2 ) {
( @v1[1,2,0] >>*<< @v2[2,0,1] )
>>-<<
( @v1[2,0,1] >>*<< @v2[1,2,0] )
}
sub surface-to-normal( @a, @b, @c ) {
my @b2 = @b >>-<< @a;
my @c2 = @c >>-<< @a;
my @normal = cross-product( @b2, @c2 );
function! BrightHome()
let s:col = col(".")
normal! 0
if s:col == col(".")
normal! ^
endif
endfunction
nnoremap <silent> <Home> :call BrightHome()<CR>
@smosher
smosher / simple_range.ml
Created December 28, 2011 21:10
OCaml -- simple infix range op.
let ( -- ) x y =
let step_y = match y > x with
| true -> ( fun n -> n - 1 )
| false -> ( fun n -> n + 1 )
in
let rec mklist x y ll =
if x == y then y::ll
else mklist x (step_y y) (y::ll)
in
@smosher
smosher / pushpath.sh
Created April 18, 2012 21:03
bash: exports PATH with operand appended
pushpath () { export PATH=${PATH}:${1}; }
# example: $ pushpath ~/bin
@smosher
smosher / introspection.io
Created April 4, 2013 05:45
http://rosettacode.org/wiki/Introspection — an Io solution exists, but makes no attempt at extra credit: Report the number of integer variables in global scope, and their sum.
// dumb test for int-ness, since Io doesn't have ints
// rather than being cheeky and doing Integer := Number clone
Number isInt := method(self == self roundDown)
countAndSumLobbyIntegers := method(
_ := Lobby slotNames select(x,
(Lobby getSlot(x) type == "Number")
) map(x, Lobby getSlot(x)) select(x, x isInt)
("There are " .. (_ size) .. " integer Numbers in Lobby") println
@smosher
smosher / MapLiteral.io
Last active December 15, 2015 18:59
DSL for Map literals using Map { ... } as a Map-scoped constructor
// mostly a guess:
OperatorTable addOperator(":", 13.5)
// : is a key-value pair (list) constructor on sequences:
Sequence : := method(a, return list(self, a) )
Message : := method(a, return list(self, a) )
Map curlyBrackets := method(
env := call sender clone
x := Map clone
@smosher
smosher / ListLiteral.io
Last active December 15, 2015 20:00
DSL for List literals using List [ ... ] as a List-scoped constructor
/* Unsafe version:
List squareBrackets := method(
call message arguments clone map(x,
call sender doMessage(x)
)
)
*/
// Safe version:
List squareBrackets := method(
@smosher
smosher / iolanguage_todo.md
Last active December 15, 2015 20:29
todo list for Io

Purpose

  • To set up a useful, non-toxic Io base environment for development.
  • To promote (and simplify) the better practices.

Things to investigate

  • Complete knowledge of scoping.
  • Embedded docs.
  • Testing.
@smosher
smosher / pattern_match.io
Created December 22, 2013 06:48
pattern matching demo in Io
// Work in progress, code coming soon:
Io> match(1) [2: 5, 4: 2, 1: "yay"]
==> yay
Io> match(2) [2: 5, 4: 2, 1: "yay"]
==> 5
Io> a := 10
==> 10
Io> match(a) [2: 5, 4: 2, 10: "yay"]
==> yay