Slide 1

Slide 1 text

How to lie, cheat and steal

Slide 2

Slide 2 text

@polarblau

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

How to lie, cheat and steal

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Ruby 2.0 Rails 4.0

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

http://blog.airbrake.io/guest-post/exploring-everything/

Slide 10

Slide 10 text

How does it work?

Slide 11

Slide 11 text

Not well …

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

ctx = $($canvas).get(0).getContext('2d') preview = $($preview).get(0) localMediaStream = null start = null

Slide 14

Slide 14 text

start: -> start = (new Date).getTime() started = true isStarted: -> started? and started stop: -> started = false isStopped: -> started == false

Slide 15

Slide 15 text

success = (stream) => preview.src = window.URL.createObjectURL(stream) localMediaStream = stream preview.addEventListener 'loadeddata', capture error = -> console.error arguments navigator.getUserMedia video: true, success, error

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

capture: => ctx.drawImage(preview, 0, 0) if localMediaStream? now = (new Date).getTime() pixels = ctx.getImageData(0, 0, WIDTH, HEIGHT).data timestamp = now - start createFrame(pixels, timestamp) requestAnimationFrame capture unless isStopped()

Slide 19

Slide 19 text

v [red, green, blue, alpha]

Slide 20

Slide 20 text

createFrame = (pixels, timestamp) -> intensity = 0 intensity += pixel for pixel in pixels by 4 when pixel? { intensity: intensity, timestamp: timestamp }

Slide 21

Slide 21 text

v [red, green, blue, alpha]

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

86

Slide 26

Slide 26 text

window.URL ?= window.webkitURL window.requestAnimationFrame ?= window.webkitRequestAnimationFrame navigator.getUserMedia ?= navigator.webkitGetUserMedia

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Server Client Request Response

Slide 29

Slide 29 text

Server Request Response Browser

Slide 30

Slide 30 text

Server Request Response Browser

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Can it run Crysis?

Slide 33

Slide 33 text

crack = (hash, maxLength = 10, charset) -> charset ?= ( 'abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + '0123456789' ).split('') stack = [''] for [1..maxLength] buffer = [] for item in stack for character in charset word = item + character if md5(word) == hash return word else buffer.push word stack = stack.concat buffer

Slide 34

Slide 34 text

hash = '3858f62230ac3c915f300c664312c63f' # "foobar" crack(hash)

Slide 35

Slide 35 text

def crack(hash, max_length = 10, charset = nil) charset ||= ( 'abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + '0123456789' ).split('') stack = [''] max_length.times do buffer = [] for item in stack for character in charset word = item + character if Digest::MD5.hexdigest(word) == hash return word else buffer << word end end end stack = stack + buffer end end

Slide 36

Slide 36 text

Javascript Ruby

Slide 37

Slide 37 text

v

Slide 38

Slide 38 text

Square one

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Try to solve problems closer to the GUI

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Slide 45

Slide 45 text

url = window.URL || window.webkitURL

Slide 46

Slide 46 text

# Creates a new object URL. window.URL.createObjectURL() # Revokes an object URL previously created window.URL.revokeObjectURL()

Slide 47

Slide 47 text

video = document.createElement 'video')

Slide 48

Slide 48 text

$('#source').on 'change', -> src = url.createObjectURL(@files[0]) video.src = src video.autoplay = false video.load()

Slide 49

Slide 49 text

THUMBNAILSIZE = 0.25 $(video).on 'canplaythrough', -> width = video.videoWidth * THUMBNAILSIZE height = video.videoHeight * THUMBNAILSIZE extractFrame(video, width, height)

Slide 50

Slide 50 text

step = 1 # extract a frame every on second extractFrame = (video, width, height, time = 0) -> video.currentTime = time $(video).one 'seeked', -> ctx = createAndInsertCanvas(width, height) ctx.drawImage(video, 0, 0, width, height) time += step if time < video.duration extractFrame(video, width, height, time) else $('#output') .show() .on('mousemove', scrub) .find('canvas:not(:last)') .hide()

Slide 51

Slide 51 text

$output = $('#output') outputOffset = $output.offset().left outputWidth = $output.width() pages = $output.find('canvas') pageCount = pages.length stepSize = outputWidth / (pageCount - 1) scrub = (e) -> page = Math.round((e.pageX - outputOffset) / stepSize) pages.hide().eq(page).show()

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

Potential issues —

Slide 54

Slide 54 text

Potential issues — Video format

Slide 55

Slide 55 text

Potential issues — Video format Canvas support

Slide 56

Slide 56 text

Potential issues — Video format Canvas support Javascript support

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

Strange things in space

Slide 61

Slide 61 text

width = $image.data('width') height = $image.data('height') src = $image.attr('src') $canvas = $('') $canvas.attr(width: width, height: height) ctx = $canvas.get(0).getContext('2d') image = new Image() image.onload = -> ratio = if width > height then height / width else height / height [sWidth, sHeight] = if width > height [@width, @width * ratio] else [@height * ratio, @height] ctx.drawImage(@, 0, 0, sWidth, sHeight, 0, 0, width, height) $image.replaceWith $canvas

Slide 62

Slide 62 text

ctx.drawImage( image, # image object sx, # crop positition sy, # sWidth, # crop size sHeight, # dx, # target position dy, # dWidth, # target size dHeight # )

Slide 63

Slide 63 text

Strange things in space

Slide 64

Slide 64 text

$('img.resize').resize() $('img.resize').resize(gravity: 'ne', zoom: false) # resize, crop if necessary to maintain aspect ratio # north-east gravity $('img.resize').resize('400x300#ne') # resize only if the image is smaller than this $('img.resize').resize('400x300<')

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

Potential issues —

Slide 67

Slide 67 text

Potential issues — Canvas support

Slide 68

Slide 68 text

Potential issues — Canvas support Javascript support

Slide 69

Slide 69 text

But, can it run Crysis?

Slide 70

Slide 70 text

ORANGE

Slide 71

Slide 71 text

v [red, green, blue, alpha]

Slide 72

Slide 72 text

createFrame = (pixels, timestamp) -> intensity = 0 intensity += pixel for pixel in pixels by 4 when pixel? { intensity: intensity, timestamp: timestamp } & requestAnimationFrame capture unless isStopped()

Slide 73

Slide 73 text

Web Workers

Slide 74

Slide 74 text

ORANGE

Slide 75

Slide 75 text

Orange = require 'orange'

Slide 76

Slide 76 text

set = new Orange.JobSet set.on 'complete', -> console.log 'All done'

Slide 77

Slide 77 text

job = new Orange.Job 'calculate_intensity', pixels : pixels timestamp: timestamp job.on 'complete', (data) => console.log data.intensity job.perform() # or run whole set at once set.push(job) set.perform()

Slide 78

Slide 78 text

self.onmessage = (event) -> [type, data] = [event.data.type, event.data.data] switch type when 'perform' intensity = 0 intensity += pixel for pixel in data.pixels by 4 ↵ when pixel? self.postMessage type: 'complete' data: intensity: intensity timestamp: data.timestamp

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

The Future —

Slide 81

Slide 81 text

The Future —

Slide 82

Slide 82 text

The Future — Worker API

Slide 83

Slide 83 text

The Future — Worker API Persistent jobs (?)

Slide 84

Slide 84 text

The Future — Worker API Persistent jobs (?) Worker class shim

Slide 85

Slide 85 text

The Future — Worker API Persistent jobs (?) Worker class shim Queue interface

Slide 86

Slide 86 text

The Future — Worker API Persistent jobs (?) Worker class shim Queue interface Custom events

Slide 87

Slide 87 text

The Future — Worker API Persistent jobs (?) Worker class shim Queue interface Custom events Job retry

Slide 88

Slide 88 text

The Future — Worker API Persistent jobs (?) Worker class shim Queue interface Custom events Job retry Error handling

Slide 89

Slide 89 text

Why not?

Slide 90

Slide 90 text

Fundamental lack of trust

Slide 91

Slide 91 text

window.onbeforeunload = -> 'Are you sure you want to leave?'

Slide 92

Slide 92 text

Local storage

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

Shims / Shivs https://github.com/Modernizr/Modernizr/wiki/ HTML5-Cross-Browser-Polyfills

Slide 95

Slide 95 text

Dziękuję! Thanks!