Skip to content

Instantly share code, notes, and snippets.

View amiika's full-sized avatar

Miika Alonen amiika

  • CSC - IT Center for Science
  • Espoo
View GitHub Profile
@amiika
amiika / chain.ts
Created August 17, 2023 12:19
Typescript method chaining example with the automatic evaluation at the end
export class Method {
originalValue: string;
value: string;
constructor(value: string) {
this.originalValue = value;
this.value = value;
}
add(value: string): Method {
@amiika
amiika / linkedlistwithnumbers.ts
Created August 16, 2023 12:10
Typescript linked list with number references for live coding method chaining
// Simple pattern class creating pattern from list of values
export class Pattern {
events: Event[];
_current : number | undefined = undefined;
constructor(values: number[]) {
this.events = values.map((value, index) => new Event(value));
this.buildLinks();
}
@amiika
amiika / linkedlistchaining.ts
Created August 15, 2023 12:44
Method chaining in typescript example
// Simple pattern class creating pattern from list of values
export class Pattern {
events: Event[];
_current : Event | undefined = undefined;
constructor(values: number[]) {
this.events = values.map((value, index) => new Event(value));
this.buildLinks();
}
# Does the same thing as: https://slonimsky.netlify.app/
def slonimsky(nodes, interpolations, divisions=1)
return [] if (nodes <= 0)
nodes.times.collect { |i| [i * divisions] + interpolations.map { |x| (i * divisions) + x }}.flatten
end
# Bresenhams Euclidean algorithm in Ruby
def euclidean_bresenham(pulses, steps)
return Array.new(steps,1) if pulses>=steps
previous = nil
rhythm = []
steps.times do |i|
div = ((pulses.to_f / steps) * i).to_i
rhythm.push(div == previous ? 0 : 1)
previous = div
@amiika
amiika / gist:1c01a48644f2d26d89ad70621599c4b3
Last active April 27, 2021 17:50
integer_sequences.rb
# Number sequence enumerators
define :fibonacci do
Enumerator.new do |y|
a = b = 1
while true do
y << a
a, b = b, a + b
end
end
end
@amiika
amiika / gist:4457de43aceab68508453c38819e32e0
Last active April 28, 2021 10:50
Sonic Mines - Minesweeper for Sonic Pi and Novation Launchpad Mini
Moved to https://github.com/amiika/novation_games
@amiika
amiika / markov_chain_launchpad.rb
Last active April 22, 2021 17:53
Markov chain launchpad for novation mini and Sonic Pi
# Markov chain player for novation mini launchpad
# Tested only on novation mini mk3 model but probably works on any novaion launchpad
use_debug false
use_midi_logging false
# Midi ports for the launchpad
launchpad_in = "/midi:midiin2_(lpminimk3_midi)_1:1/*"
launchpad_out = "midiout2_(lpminimk3_midi)_2"
@amiika
amiika / Sonic Pi cellular automaton 2
Created April 8, 2021 20:51
Cellular automaton version that changes only one note per loop
# https://in-thread.sonic-pi.net/t/self-modifying-algorithms/5360/21
use_debug false
generations = {
:gen1=>{:cells=>[0, 0, 1, 0, 0, 0, 0, 1, 1]},
:gen2=>{:cells=>[1, 0, 0, 0, 1, 0, 0, 0, 0]}
}
define :create_ruleset do |n|
define :create_ruleset do |n|
rules = Hash.new
return rules if n > 255
binary = "%08b" % n
8.times do |i|
key = "%03b" % i
rules[key] = binary[7-i].to_i
end
return rules
end