Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One nice thing about this setup is that it's not specific to Clojure/Lisp; any scripting language with a REPL will do this well:

Python:

    import subprocess
    import json

    def osquery(query):
      return json.loads(subprocess.check_output(["osqueryi", "--json", query]))
    
    #>>> osquery("select * from routes where destination = '::1'")
    
    #>>> [{'destination': '::1', 'flags': '2098181', 'gateway': '::1', 'hopcount': '0', 'interface': 'lo0', 'metric': '0', 'mtu': '16384', 'netmask': '128', 'source': '', 'type': 'local'}]
Node:

    const { execFile } = require("child_process");

    async function osquery(query) {
      return new Promise((resolve, reject) => {
        execFile("osqueryi", ["--json", query], (error, out, _err) => {
          if (error) {
            reject(error);
            return;
          }

          resolve(JSON.parse(out));
        });
      });
    }
    
    //> await osquery("select * from routes where destination = '::1'");
    
    //> [
    //>   {
    //>     destination: '::1',
    //>     flags: '2098181',
    //>     gateway: '::1',
    //>     hopcount: '0',
    //>     interface: 'lo0',
    //>     metric: '0',
    //>     mtu: '16384',
    //>     netmask: '128',
    //>     source: '',
    //>     type: 'local'
    //>   }
    //> ]
Ruby:

    require "open3"
    require "json"

    def osquery(query)
      out, err, exit_status = Open3.capture3("osqueryi", "--json", query)
      if exit_status != 0
        raise err
      end
    
      return JSON.parse(out, symbolize_names: true)
    end
    
    #irb(main):1:0> osquery("select * from routes where destination = '::1'")
    #=>
    #[{:destination=>"::1",
    #  :flags=>"2098181",
    #  :gateway=>"::1",
    #  :hopcount=>"0",
    #  :interface=>"lo0",
    #  :metric=>"0",
    #  :mtu=>"16384",
    #  :netmask=>"128",
    #  :source=>"",
    #  :type=>"local"}]


That said, one nice advantage with a Lisp editor is that you can keep code in a file, and send it for the evaluation in the REPL instead of actually having to use the REPL as your editor.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: