Math 115A
1.2-1.6
- Definition of a vector space
// async | |
encrypt(message).async { ciphertext in /* do somthing */ } | |
get(URL).async {(data, response, error) in /* do somthing */ } | |
// await | |
let ciphertext = encrypt(message).await() | |
let (data, response, error) = get(URL).await() |
// synchronous API | |
func encrypt(message: String) -> Task<String> { | |
return Task { | |
encrypt(message) | |
} | |
} | |
// asynchronous API | |
func get(URL: NSURL) -> Task<(NSData?, NSURLResponse?, NSError?)> { | |
return Task {completionHandler in | |
NSURLSession().dataTaskWithURL(URL, completionHandler: completionHandler).resume() |
Task { | |
let enhancedImage = self.applyImageFilter(image) | |
Task {self.imageView.image = enhancedImage}.async(.Main) | |
let completed = UIView.animateWithDurationAsync(0.3) { self.label.alpha = 1 }.await(.Main) | |
// add code to happen next here | |
}.async() |
dispatch_promise { | |
return self.applyImageFilter(image) | |
}.then { enhancedImage in | |
self.imageView.image = enhancedImage | |
return UIView.animateWithDurationPromise(0.3) { | |
self.label.alpha = 1 | |
} | |
}.then { | |
// add code to happen next here | |
} |
// get a global concurrent queue | |
let queue = dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0) | |
// submit a task to the queue for background execution | |
dispatch_async(queue) { | |
let enhancedImage = self.applyImageFilter(image) // expensive operation taking a few seconds | |
// update UI on the main queue | |
dispatch_async(dispatch_get_main_queue()) { | |
self.imageView.image = enhancedImage | |
UIView.animateWithDuration(0.3, animations: { | |
self.imageView.alpha = 1 |
function getCharCodes(s) { | |
return s.toUpperCase().split("").map(c => c.charCodeAt(0)) | |
} | |
function zip(a, b) { | |
return a.map((char,i) => [char, b[i % b.length]]); | |
} | |
function decrypt(ciphertext, key) { | |
const plaintextCharCode = zip(getCharCodes(ciphertext), getCharCodes(key)).map(pair => (pair[0] - pair[1] + 26) % 26 + "A".charCodeAt(0)) |
function click(el) { | |
var evt = document.createEvent("MouseEvents"); | |
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
el.dispatchEvent(evt); | |
} | |
function click2(el) { | |
var evt = document.createEvent("MouseEvents"); | |
evt.initMouseEvent("mousedown", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); |
// stores an array of images (PImage[]) for each scene | |
ArrayList<PImage[]> scenes; | |
// keeps track of the index of the current scene | |
int sceneIndex = 0; | |
// used to animate the images of the current scene | |
int frameIndex = 0; | |
// keep track of the last mouse position | |
float clickedX; | |
float clickedY; |
# To pngs 1 frame per second | |
# https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video | |
mkdir frames && ffmpeg -i video.mov -vf fps=1 frames/ffout%03d.png | |
# screen recording to gif | |
mkdir bufferFrames && ffmpeg -i video.mov -vf scale=320:-1 -r 30 bufferFrames/ffout%03d.png && convert -delay 4.167 -loop 0 bufferFrames/ffout*.png ZLHistogramAudioPlotBuffer.gif |