Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2015年をズザザザザっと 振り返ってみる

pastak
March 13, 2016

2015年をズザザザザっと 振り返ってみる

京大マイコンクラブ( kmc.jp )の2016年春合宿で講座を行った際のスライドです

pastak

March 13, 2016
Tweet

More Decks by pastak

Other Decks in Technology

Transcript

  1. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: Gamepad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  2. 4݄ 5݄ 6݄ 7݄ 8݄ 9݄ 10 11 1݄ ɹɹ

    2݄ ɹɹ ࠓ͔Β͜ΕΒ શ෦ͷ࿩Λ βοͱ͢Δͧ
  3. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: Gamepad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  4. Web Audio API • ϒϥ΢βͰԻΛ໐Β͢ํ๏ͷ1ͭ • Ұ൪؆୯ͳͷ͸ <audio> • Google

    Chrome / Firefox ڞʹαϙʔτ • Firefox ʹ͸ Audio Data APIͱ͍͏ͷ͕࣮૷ ͞Ε͍͕ͯͨɺͪ͜Βʹ౷Ұ͢Δํ਑ͬΆ͍ • NodeΛ઀ଓ͢Δ͜ͱͰϑΟϧλʔͨ͠Γ৭ʑ ग़དྷΔ
  5. ภͬͨDTM༻ޠࣙయ - ΦγϨʔλʔ:Oscillatorͱ͸ - DTM / MIDI ༻ޠ ͷҙຯɾղઆ |

    g200kg Music & Software http://www.g200kg.com/jp/docs/dic/oscillator.html ൃৼثͷࣄɻγϯηαΠβʔͰ͸Իͷݩ ͱͳΔ೾ܗΛ࡞Γग़͢෦෼ʹ૬౰͢Δɻ লུͯ͠OSCͱॻ͔ΕΔࣄ΋ଟ͍ɻΧφ දهͷ৔߹͸ʮΦγϨʔλʔʯɺ·ͨ͸ ʮΦογϨʔλʔʯͱॻ͔ΕΔɻ
  6. var audioctx = new AudioContext(); var osc = audioctx.createOscillator(); osc.frequency.value

    = 440; osc.type = "square"; osc.connect(audioctx.destination); osc.start(1);
  7. var audioctx = new AudioContext(); var osc = audioctx.createOscillator(); osc.frequency.value

    = 440; osc.type = "square"; osc.connect(audioctx.destination); osc.start(1); प೾਺
  8. var audioctx = new AudioContext(); var osc = audioctx.createOscillator(); osc.frequency.value

    = 440; osc.type = "square"; osc.connect(audioctx.destination); osc.start(1); ೾ܗͷछྨ ɾ"sine" : αΠϯ೾ ɾ"square" : ۣܗ೾ ɾ"sawtooth":ڒࣃঢ়೾ ɾ"triangle":ࡾ֯೾
  9. var audioctx = new AudioContext(); var osc = audioctx.createOscillator(); osc.frequency.value

    = 440; osc.type = "square"; osc.connect(audioctx.destination); osc.start(1); ࠶ੜʂʂʂʂʂʂ
  10. var shaper = audioctx.createWaveShaper(); osc.connect(shaper); shaper.connect(audioctx.destination); var curve = new

    Float32Array(4096); // ディストーションカーブを表す配列を なんとかして作る shaper.curve = curve;
  11. var shaper = audioctx.createWaveShaper(); osc.connect(shaper); shaper.connect(audioctx.destination); var curve = new

    Float32Array(4096); // ディストーションカーブを表す配列を なんとかして作る shaper.curve = curve; ΦγϨʔλʔͱ઀ଓ͢Δ
  12. Web Audio APIͰଞʹग़དྷΔࣄ • ԻྔΛௐ੔͢Δ • ԻݯΛಡΈࠐΉ • ϑΟϧλʔΛ͔͚Δ •

    ೾ܗΛऔಘ͢Δ • ίϯϓϨοαʔΛ͔͚Δ • ΫϩεϑΣʔυͤ͞Δ ͳͲͳͲ
  13. ɍ

  14. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: Gamepad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  15. What’s “Scratch” • Scratch (εΫϥον) ͱ͸ॳ৺ऀ͕࠷ॳʹਖ਼͠ ͍ߏจͷॻ͖ํΛ֮͑Δ͜ͱແ݁͘ՌΛಘΒ ΕΔϓϩάϥϛϯάݴޠֶश؀ڥͰ͋ΔɻMIT ϝσΟΞϥϘ͕։ൃ͠ɺ༡ͼ৺ͷ͋Δ࣮ݧ΍ ΠϯλϥΫςΟϒΞχϝʔγϣϯɺήʔϜͳ

    Ͳͷ੡࡞Λ௨ͯ͠͞ΒͳΔֶशͷ΍ΔؾΛى ͤ͜͞Δ͜ͱΛҙਤ͍ͯ͠Δɻ https://ja.wikipedia.org/wiki/Scratch_(%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F %E3%83%B3%E3%82%B0%E8%A8%80%E8%AA%9E) ΑΓ
  16. $(window).on('devicelight', function(event) { ext.getLightSensor = function(){ return event.originalEvent.value; } })

    return event.originalEvent.accelerationIncludingGravity[direction] } }) ext.getLightSensor = function() {}; ext.getBatteryLevel = function() { return navigator.battery; }; var descriptor = { blocks: [ ['r', 'Light sensor', 'getLightSensor',null], ['r', 'Battery', 'getBatteryLevel',null] ] };
  17. ɍ

  18. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: Gamepad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  19. var doc = require('sdk/window/utils') .getMostRecentBrowserWindow().document; var urlBarIcons = doc.getElementById('urlbar-icons'); var

    btn = doc.createElement('toolbarbutton'); btn.setAttribute('id', option.id); btn.setAttribute('image', option.image); btn.addEventListener('command', option.onClick, false); urlBarIcons.appendChild(btn);
  20. var doc = require('sdk/window/utils') .getMostRecentBrowserWindow().document; var urlBarIcons = doc.getElementById('urlbar-icons'); var

    btn = doc.createElement('toolbarbutton'); btn.setAttribute('id', option.id); btn.setAttribute('image', option.image); btn.addEventListener('command', option.onClick, false); urlBarIcons.appendChild(btn); ͜ΕͰwindowࣗମͷDOM(ҙ༁)͕औΕΔ
  21. var doc = require('sdk/window/utils') .getMostRecentBrowserWindow().document; var urlBarIcons = doc.getElementById('urlbar-icons'); var

    btn = doc.createElement('toolbarbutton'); btn.setAttribute('id', option.id); btn.setAttribute('image', option.image); btn.addEventListener('command', option.onClick, false); urlBarIcons.appendChild(btn); ͋ͱ͸ҰൠతͳDOMૢ࡞Ͱ<toolbarbutton>Λ௥Ճ
  22. ɍ

  23. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: Gamepad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  24. • Debian / Ubuntu • % curl -s https://packagecloud.io/install/ repositories/gyazo/gyazo-for-linux/script.deb.sh

    | sudo bash • % sudo apt-get install gyazo • CentOS • curl -s https://packagecloud.io/install/ repositories/gyazo/gyazo-for-linux/script.rpm.sh | sudo bash • $ sudo yum install gyazo
  25. Ͱ

  26. packagecloud.ioΛར༻ • ެ։༻ͳΒແྉͰ݁ߏ࢖͑Δ • upload༻ͷίϚϯυ͸gem • gem install packagecloud •

    CircleCIͷυΩϡϝϯτʹ΋ࡌͬͯΔ • https://circleci.com/docs/pushing-packages-to- packagecloud
  27. ɍ

  28. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: Gamepad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  29. JT

  30. JavaScript for Automation(JXA) • Mac OSX 10.10 Yosemite ͔Βར༻Մೳʹ •

    ͦΕ·ͰͷApple Scriptͱಉ౳ͷ͜ͱΛJSͰදݱՄೳʹ • ެࣜυΩϡϝϯτ: https://developer.apple.com/library/ mac/releasenotes/InterapplicationCommunication/RN- JavaScriptForAutomation/Articles/Introduction.html • αϯϓϧ๛෋: https://github.com/dtinth/JXA-Cookbook • Script Editor.app > ΢Οϯυ΢ > ϥΠϒϥϦ
  31. on IsPlaying() tell ApplicationLib if ApplicationIsRunning("iTunes") then tell application "iTunes"

    return player state is playing end tell else return false end if end tell end IsPlaying on GetCurrentTrack() if IsPlaying() then tell application "iTunes" if not (exists current track) then return null set trackName to (get name of current track) set trackArtist to (get artist of current track) set trackAlbum to (get album of current track) return "{\"name\":\"" & trackName & "\",\"artist\":\"" & trackArtist & "\",\"album\":\"" & trackAlbum & "\"}" end tell else return "null" end if end GetCurrentTrack
  32. on IsPlaying() tell ApplicationLib if ApplicationIsRunning("iTunes") then tell application "iTunes"

    return player state is playing end tell else return false end if end tell end IsPlaying on GetCurrentTrack() if IsPlaying() then tell application "iTunes" if not (exists current track) then return null set trackName to (get name of current track) set trackArtist to (get artist of current track) set trackAlbum to (get album of current track) return "{\"name\":\"" & trackName & "\",\"artist\":\"" & trackArtist & "\",\"album\":\"" & trackAlbum & "\"}" end tell else return "null" end if end GetCurrentTrack
  33. function IsPlaying() { if (IsRunning()) { return Application('iTunes').playerState() === 'playing'

    } return false } function GetCurrentTrack() { if (!IsPlaying()) { return null } var iTunes = Application('iTunes') var track = iTunes.currentTrack return JSON.stringify({ name: track.name(), artist: track.artist(), album: track.album() }) }
  34. ɍ

  35. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: Gamepad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  36. GamePad API ֓ཁ • USB GamePad ͳͲͷೖྗΛऔಘͰ͖ΔJS API • https://www.w3.org/TR/gamepad/

    • https://developer.mozilla.org/en-US/docs/Web/API/ Gamepad_API/Using_the_Gamepad_API • gamepadconnected Event • event.gamepad • gamepaddisconnected Event • navigator.getGamepads() • Array͕ฦͬͯ͘Δ͕ɺChromeͩͱlength > 3 Ͱ undefinedͰຒ·ͬͨͷ͕ฦͬͯ͘Δʢͩͬͨ͸ͣ)
  37. GamePad API ֓ཁ • GamePad.index • GamePad.id • GamePad.buttons •

    Buttonͷ഑ྻʢϘλϯ͝ͱʹ൪஍͕ݻఆ͞Ε͍ͯΔʣ • GamePad.axes • εςΟοΫͷ܏͖۩߹ʢेࣈϘλϯ΋ؚ·ΕΔ৔߹΋ • Button.pressed • Button.value • Ϙλϯͷԡ͞Ε۩߹
  38. menubar ϞδϡʔϧΛར༻ const menubar = require('menubar') const mb = menubar()

    mb.on('ready', function ready () { const loadPath = 'file://'+ __dirname+'/static/view.html' mb.window.loadUrl(loadPath) })
  39. menubar Ϟδϡʔϧඇར༻ const Menu = require('electron').Menu const menu = new

    Menu(); menu.append(new MenuItem({ label: 'MenuItem1', click: function() { console.log('item 1 clicked') } })) menu.append(new MenuItem({type: 'separator'})) menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', checked: true }))
  40. ɍ

  41. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: GamePad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  42. Electron App Side const ws = require("nodejs-websocket") const server =

    ws.createServer(function (conn) { console.log("New connection") conn.on("text", function (text) { if (text !== 'open') return console.log('called') do_something() // ② }) conn.on("close", function (code, reason) { console.log("Connection closed") }) }).listen(3652)
  43. Chrome Extension Side var ws = new WebSocket('ws://localhost:3652/') ws.onmessage =

    function (event) { //適切にwsで飛んできたdataを渡す res(event.data) // ③ ws.close() } ws.onopen = function () { ws.send('open') // ① }
  44. ɍ

  45. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: Gamepad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  46. ɍ

  47. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: Gamepad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  48. LPB

  49. What’s “koa” • 1.x ͸ generator • 2.x ͸ await

    / async • CallBack஍ࠈͱexpress͔Βͷ୤٫
  50. koa’s middleware pattern • functionΛొ࿥ॱʹݺͿ const koa = require('koa') const

    app = koa() app.use(function *(next) { this.body = 'Hello' yield next }) app.use(function *(next) { this.body += 'World' yield next }) app.listen(3000)
  51. router.get('/callback', function *(next) { const callbackUrl = `${this.request.origin}/callback` const tokenData

    = yield chromeWebstoreManager.getAccessToken(query['code'], callbackUrl).then((data) => { data = JSON.parse(data) data.expired_at = Date.now() + (Number(data.expires_in) * 1000) return data }) try { yield setToken(JSON.stringify(tokenData)) this.body = 'Success!' } catch (e) { this.status = 500 this.body = 'failed...' } })
  52. ɍ

  53. 4݄: audio API 5݄: Electronࢼ࢝͠ΊΔ / ScratchX 6݄: Firefox Add-on

    module 7݄: Build deb package on Circle CI 8݄: JavaScript for Automation (JXA) 9݄: Gamepad API / Menubar with Electron 10݄: Connection Electron App with Chrome Extension 11݄: Chrome Extension Build Tool / heroku / koa.js 1݄: Fitbit ɹɹ Auto release Chrome Extension with heroku 2݄: Open CV with NodeJS on heroku by Docker ɹɹ Format manifest.json for Firefox WebExtension
  54. Build and Deploy Docker to Heroku % heroku plugins:install heroku-docker

    % echo “web: npm run start” > Procfile % heroku docker:init % docker-compose build % heroku docker:release heroku-dockerϓϥάΠϯΛΠϯετʔϧ ProcfileΛੜ੒ جຊతͳDockerfileͳͲ͕ੜ੒͞ΕΔ docker imageΛbuild herokuʹdeploy
  55. ࠷৽ͷݱঢ় • Firefox v46 (ݱࡏDE, Canary) Ͱalphaʹͳͬͨ • 2016-08-02ʹstableೖΓ͢Δ༧ఆͷFirefox v48Ͱ

    stableʹͳΔ໨ඪ • chrome -> browser • addon.mozilla.org ʹΞοϓϩʔυ͢Δ͜ͱͰॺ໊ Մೳʹ • ະ࣮૷ͷAPI΋͔ͳΓݮ͖ͬͯͨ • https://developer.mozilla.org/en-US/Add-ons/ WebExtensions/Chrome_incompatibilities
  56. What’s wemf • ඞؚͣ·Ε͍ͯΔ΂͖ΩʔͱରԠ͢Δ஋Λ௥Ճ • ෆ଍͍ͯ͠ΔΩʔ͕͋Δ৔߹͸ package.json ͳͲ͔Βੜ੒ͭ͠ ͭɺର࿩ΠϯλʔϑΣΠεͰੜ੒͠·͢ •

    ະରԠͷΩʔΛ࡟আ • ݱঢ়ະରԠͷΩʔ͕͋ΔͱΠϯετʔϧʹࣦഊ͢ΔͷͰɺͦͷ Α͏ͳΩʔΛ࡟আ͠·͢ɻ • ະରԠͷΩʔϫʔυͷ࢖༻Λ௨஌ • web_accessible_resourcesͰϫΠϧυΧʔυ͕࢖͑ͳ͍ͳͲ͕ ͋ΔͷͰɺͦͷΑ͏ͳΩʔϫʔυΛؚΜͰ͍Δ৔߹͸࡟আͤͣ ʹ௨஌͠·͢ɻ
  57. ɍ