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

Automate Your Electronic Life With The JS Ecosy...

Vito Chin
November 26, 2016

Automate Your Electronic Life With The JS Ecosystem

Bots and machine learning are all the rave these days. But does it feel like we’re being force-fed pre-packaged AI that we do not have much autonomy over? The greatest potential in leveraging computer-based automation for the individual should be one that we can teach to serve the need of its personal owner. Sometimes, we may need robots that drives for us less than an automated process that helps us with the increasing chores that we do online, repetitively and sometimes seemingly futile. For example, how many times had you wondered if the computer can just download the CSV of your bank statement for you (in the absence of proper APIs), process it and augment it to your ledger automatically? Or the times where you wish there could be an easier way to tell the computer to do something on bash than to issue a command with 5 parameters? Javascript has all the answer for you, with tools such as Nightmare.JS to automate browser-based activities, CLI frameworks such as Vorpal and of course the biggest collection of packages in the world that is npm. The trick to continuous harmony is to find something that can gel all of these cool Javascript tech together and run itself as a continuous concern, essentially becoming a simpler computer-based version of yourself, augmented. In this quick talk, I will share my little adventure and experiment trying to automate the boring bits of my electronic life with such a JavaScript tool called Jodot.

Vito Chin

November 26, 2016
Tweet

More Decks by Vito Chin

Other Decks in Programming

Transcript

  1. [ # Duty to log that Jodot is alive {

    schedule: 1 * * * * * package: jodot-alive } ] • Centralised location for all automated "duties" • Can be created and modified either by myself, a team or Jodot duty • Text-based, because it is the universal interface • JSON, because... (hcl, YAML, maybe?) • hjson, because comments within are helpful • Centralised location for all automated "duties" • Can be created and modified either by myself or by another Jodot duty • Text-based, because it is the universal interface • JSON, because... (hcl, YAML, maybe?) • hjson, because comments within are helpful
  2. { "name": "jodot-alive", "version": "1.0.2", "description": "Jodot duty that logs

    to STDOUT that it is alive, implying that Jodot is alive too.", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [ "jodot", "monitor", "alive" ], "author": "Vito Chin <[email protected]> (http://www.vitochin.com)", "license": "MIT", "dependencies": { "jodot": "^1.0.0" } }
  3. [ # Duty to log that Jodot is alive {

    schedule: 1 * * * * * package: /path/to/duty/source/ localInstall: true } ]
  4. function(dutyDef, resolve, reject) { var options = { name: dutyDef.package,

    localInstall: dutyDef.localInstall, path: moduleDirectory() }; npmi(options, function (err, result) { if (err) { reject(err); } else { resolve(dutyDef); } }); }
  5. [ # Duty to log that Jodot is alive {

    schedule: 1 * * * * * package: /path/to/duty/source/ localInstall: true } ] Cron expression
  6. [ # Duty to log that Jodot is alive {

    schedule: 1 * * * * * package: jodot-alive }, # Duty to tail a file and e-mail upon specified error { package: jodot-tailnmail params: [ "/var/log/jodot.out.log", // log file to tail "I am alive!", // string to tail "key-9dsj43dsimb0sdf8ha507", // e-mail API key "[email protected]", // to "mail.golkipar.com", // domain ] }, ]
  7. Tail = require("tail").Tail; process.on("message", function(params) { tail = new Tail(params[0]);

    var mailgun = require("mailgun-js")({apiKey: params[2], domain: params[4]}); tail.on("line", functioån(data) { if (data === params[1]) { var mailMeta = { from: "Jodot <[email protected]>", to: params[3], subject: "Tailed", text: data }; mailgun.messages().send(mailMeta, function (error, body) { console.log(body); }); } }); tail.on("error", function(error) { console.log("ERROR: ", error); }); tail.watch(); console.log("Tailing " + params[0]); });
  8. jodot-bashprofile-add shelljs Add strings to the bash profile file jodot-pricesdb

    money, write Download currency exchange prices and updates prices.db for ledger-cli jodot-remember sqlite Remember a nugget of information along with relationships and metadata jodot-commitdo nodegit, shelljs Triggers shell command after each commit jodot-vault node-vault Jodot duty to interface with vault to keep secrets jodot-linkchecker get-urls, request Checks a page for links that are no longer valid periodically
  9. (O) <M o <M /| ...... /:M\------------------------------------------------,,,,,, (O)[ vorpal ]::@+}==========================================------------>

    \| ^^^^^^ \:W/------------------------------------------------'''''' o <W <W (O) $ jv jodot~$ help Commands: help [command] Provides help for a given command. exit [options] Exits instance of Vorpal. list List all installed duties find Find a specific duty from npm do Trigger a duty log Show log for a duty jodot-vorpal WIP!
  10. jodot-bot WIP! I need something to help me set reminders

    without going through forms May I suggest jodot-reminder? 15:30 15:30 jodot-reminder Set reminders via bot interface. Get reminded on the same channel. More Information 15:30
  11. Create Share Find Install Configure process.on jodot-* Only requirement Only

    requirement publish (package) keywords: jodot, duty dependedUpon dependencies: jodot? npmi Typescript parameters?
  12. FIN Packages mentioned, other brands copyright owned by their respective

    owners. Book shown for illustrative purposes earlier on in the presentation is The Art of Thinking Clearly by Rolf Dobelli. hjson (https://www.npmjs.com/package/hjson), npm (https://www.npmjs.com). Image sources: vorpal (http://vorpal.js.org/), grunt (http://gruntjs.com/), gulp (http://gulpjs.com/), pm2(https://github.com/Unitech/pm2)