This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require ‘rubygems’ | |
| require ‘rmagick’ | |
| include Magick | |
| left = ImageList.new(ARGV[0]).gamma_correct(1,0,0) | |
| right = ImageList.new(ARGV[1]).gamma_correct(0,1,1) | |
| anaglyph = left.composite right, CenterGravity, ScreenCompositeOp | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| reader = Audio::MPEG::Decoder.new | |
| File.open('mrt_closing.mp3', 'rb') do |input| | |
| File.open('out.wav', 'wb') do |output| | |
| reader.decode(input, output) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FasterCSV.open('wavdata.csv', 'w') do |csv| | |
| csv << %w(ch1 ch2 combined) | |
| File.open('out.wav') do |file| | |
| while !file.eof? | |
| if file.read(4) == 'data' | |
| length = file.read(4).unpack('l').first | |
| wavedata = StringIO.new file.read(length) | |
| while !wavedata.eof? | |
| ch1, ch2 = wavedata.read(4).unpack('ss') | |
| csv << [ch1, ch2,ch1+ch2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| script=<<-EOF | |
| png(file='/Users/sausheong/projects/wavform/mrtplot.png', height=800, width=600, res=72) | |
| par(mfrow=c(3,1),cex=1.1) | |
| wav_data <- read.csv(file='/Users/sausheong/projects/wavform/wavdata.csv', header=TRUE) | |
| plot(wav_data$combined, type='n', main='Channel 1', xlab='Time', ylab='Frequency') | |
| lines(wav_data$ch1) | |
| plot(wav_data$combined, type='n', main='Channel 2', xlab='Time', ylab='Frequency') | |
| lines(wav_data$ch2) | |
| plot(wav_data$combined, type='n', main='Channel 1 + Channel 2', xlab='Time', ylab='Frequency') | |
| lines(wav_data$combined) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from recordtype import recordtype | |
| # weight is the priority of the task | |
| # duration is how long it will take to complete the task | |
| # due is the due date of the task | |
| # done is the date when the task is completed (starts with 0, | |
| # set to whenever the task is done) | |
| Task = recordtype('Task', 'weight duration due done') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| # create todo tasks | |
| def create_tasks(num): | |
| tasks = [] | |
| distribution = np.round(np.random.exponential(5,10000)) | |
| for i in range(num): | |
| weight = np.random.randint(1,100) | |
| due = np.random.choice(distribution)+1 | |
| duration = np.random.randint(0,due) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Tallies up the results from running the simulation. Calculates: | |
| # 1. percentage of completed tasks | |
| # 2. percentage of important tasks completed | |
| # 3. percentage of tasks completed in time | |
| def tally(completed_tasks, all_tasks): | |
| # percentage of tasks completed | |
| completed = len(completed_tasks)/len(all_tasks) | |
| # set the 75th percentile of all tasks based on weight | |
| # as the important tasks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def duration(task): return task.duration | |
| # run a single simulation | |
| def simulate(ratio, *tasks): | |
| deadline = ratio * sum(list(map(duration, tasks))) | |
| completed_tasks = [] | |
| elapsed_time = 0 | |
| for task in tasks: | |
| elapsed_time += task.duration | |
| if elapsed_time <= deadline: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add(a, b): return tuple(map(lambda x, y: x + y, a, b)) | |
| def divide(a, b): return tuple([x/b for x in a]) | |
| # Run multiple iterations of the simulation | |
| def run(ratio, iterations, num, algorithm): | |
| results, final_results = (0,0,0), (0,0,0) | |
| for i in range(iterations): | |
| tasks = create_tasks(num) | |
| results = simulate(ratio, *tuple(algorithm(*tasks))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %matplotlib inline | |
| import matplotlib.pyplot as plt | |
| def chart(data, title): | |
| labels=np.array(['Completed Tasks', 'Completed Weight', 'In Time Tasks']) | |
| angles=np.linspace(0, 2*np.pi, len(labels), endpoint=False) | |
| angles=np.concatenate((angles,[angles[0]])) | |
| colors = ['blue', 'red', 'green', 'violet', 'blueviolet', 'orange', 'deepskyblue'] | |
| for d, t, c in zip(data, title, colors): |