├── bundler ├── bin │ └── test.k ├── pug.js ├── markdown.js ├── get.js ├── snippets.js ├── k.js ├── download.js └── postprocess.js ├── pty ├── Makefile ├── pty.c └── k.h ├── validate.py ├── static ├── fonts │ └── vinila-cf2202a5.woff2 ├── svg │ └── kei_logo.svg └── js │ ├── jquery.easy-autocomplete.min.js │ └── jquery.min.js ├── src ├── css │ ├── fonts.css │ ├── media.css │ ├── solarized.css │ ├── monokai.css │ └── core.css ├── js │ ├── autocomplete.js │ ├── theme.js │ └── noise.js ├── pug │ └── index.pug ├── txt │ ├── h.txt │ └── l.txt └── md │ └── index.md ├── README.md ├── LICENSE ├── Gruntfile.js ├── package.json └── .gitignore /bundler/bin/test.k: -------------------------------------------------------------------------------- 1 | ?[!3;2;`abc] 2 | ?[!3;2;"abc"] 3 | -------------------------------------------------------------------------------- /pty/Makefile: -------------------------------------------------------------------------------- 1 | pty: pty.c 2 | gcc -o "../bundler/bin/pty" pty.c 3 | -------------------------------------------------------------------------------- /validate.py: -------------------------------------------------------------------------------- 1 | from shakti.dc import fix 2 | 3 | fix("ref_detail.md") -------------------------------------------------------------------------------- /static/fonts/vinila-cf2202a5.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kparc/ref/HEAD/static/fonts/vinila-cf2202a5.woff2 -------------------------------------------------------------------------------- /bundler/pug.js: -------------------------------------------------------------------------------- 1 | const md = require('./markdown.js') 2 | const postprocess = require('./postprocess.js') 3 | const fs = require('fs') 4 | 5 | module.exports = function() { 6 | const indexmd = fs.readFileSync('./src/md/index.md', 'utf-8') 7 | return postprocess(md(indexmd)) 8 | } 9 | -------------------------------------------------------------------------------- /bundler/markdown.js: -------------------------------------------------------------------------------- 1 | var unified = require('unified') 2 | var markdown = require('remark-parse') 3 | var remark2rehype = require('remark-rehype') 4 | var html = require('rehype-stringify') 5 | 6 | module.exports = text => 7 | unified() 8 | .use(markdown) 9 | .use(remark2rehype) 10 | .use(html) 11 | .processSync(text) 12 | .contents 13 | -------------------------------------------------------------------------------- /bundler/get.js: -------------------------------------------------------------------------------- 1 | const https = require('https') 2 | 3 | module.exports = (url, headers = {}) => new Promise((resolve, reject) => 4 | https.request(url, {headers}, (response) => { 5 | let data = '' 6 | response.setEncoding('utf8') 7 | response.on('data', d => data+=d) 8 | response.on('end', () => resolve({statusCode: response.statusCode, data})) 9 | }) 10 | .on('error', e => reject(e)) 11 | .end() 12 | ) 13 | -------------------------------------------------------------------------------- /src/css/fonts.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-display: swap; 3 | font-family: "Lab 2"; 4 | src: url("../fonts/lab-c1ed1828.eot"); 5 | src: url("../fonts/lab-c1ed1828.eot#iefix") format("embedded-opentype"), url("../fonts/lab-8df87c2d.woff2") format("woff2"),url("../fonts/lab-bcb1f8a4.woff") format("woff"); 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | @font-face { 11 | font-display: swap; 12 | font-family: "Vinila"; 13 | src: url("../fonts/vinila-cf2202a5.woff2") format("woff2"); 14 | font-style: normal; 15 | font-weight: 100 900; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## unofficial k reference card 2 | 3 | ### features 4 | 5 | * build script that produces static html 6 | * server-side markdown render 7 | * links to \h in markdown (you can even use regexp) 8 | * \h is loaded from the latest k binary at the build time 9 | * `pug` template engine for html 10 | * minified css and client-side javascript 11 | * themes (click *kei_logo.svg* for now. if you find a better place for this button - put it there) 12 | 13 | ### how to run 14 | 15 | ``` 16 | npm i 17 | npm run build 18 | ``` 19 | and serve the `./build/` directory over http 20 | 21 | -------------------------------------------------------------------------------- /src/css/media.css: -------------------------------------------------------------------------------- 1 | @media (min-width: 42rem) { 2 | header pre { 3 | display: block; 4 | font-size: .7em; 5 | padding: 1rem; 6 | } 7 | body { 8 | font-size: 1.6rem; 9 | } 10 | header::before { 11 | height: 6rem; 12 | } 13 | } 14 | 15 | @media (min-width: 70rem) { 16 | header { 17 | width: 40rem; 18 | float: left; 19 | height: 100vh; 20 | position: fixed; 21 | overflow-y: auto; 22 | } 23 | header::before { 24 | display: none; 25 | } 26 | header h1 { 27 | position: relative !important; 28 | } 29 | 30 | main, footer { 31 | margin-left: 40rem; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /bundler/snippets.js: -------------------------------------------------------------------------------- 1 | const k = require('./k') 2 | 3 | module.exports = s => { 4 | let inout = s 5 | .split('\n') 6 | .reduce((a, v) => v[0] == '•' ? ({ input: a.input.concat([v.slice(1)]), output: a.output }) : ({ input: a.input, output: a.output.concat([v]) }), { 7 | input: [], 8 | output: [] 9 | }) 10 | inout.input = inout.input.join('\n') 11 | inout.output = inout.output.join('\n').trimEnd('\n') 12 | if (!inout.input.length) { 13 | inout.valid = true 14 | inout.k = '' 15 | } else { 16 | inout.k = k(inout.input) 17 | inout.valid = inout.k.split('\n').join('') == inout.output.split('\n').join('') 18 | } 19 | return inout 20 | } 21 | -------------------------------------------------------------------------------- /src/js/autocomplete.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | var data = $('h2,h3') 3 | .toArray() 4 | .map(function(v) { 5 | return { code: $(v).find('code').text() , label: v.innerText, id: '#' + v.id } 6 | }); 7 | $('#autocomplete').easyAutocomplete({ 8 | data: data, 9 | getValue: function(el) { 10 | return el.code + ' ' + el.label.replace(el.code, '').trim() 11 | }, 12 | template: { 13 | type: "links", 14 | fields: { 15 | link: "id" 16 | } 17 | }, 18 | list: { 19 | match: { 20 | enabled: true, 21 | caseSensitive: false, 22 | method: function (el, ph) { 23 | return el.indexOf(ph) > -1 24 | } 25 | } 26 | } 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /src/js/theme.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | var themes = [ 3 | '', 4 | './css/solarized.css', 5 | './css/monokai.css', 6 | ]; 7 | 8 | try { 9 | var all = JSON.parse(localStorage.getItem('kref-theme')); 10 | if (!all.length || all.length < themes.length) 11 | throw "¯\\_(ツ)_/¯"; 12 | } catch (e) { 13 | console.log(e) 14 | all = themes; 15 | } 16 | 17 | $('#theme').attr('href', all[all.length - 1]); 18 | 19 | $('.avatar').click(function() { 20 | var t = all.shift(); 21 | all.push(t); 22 | $('#theme').attr('href', t); 23 | localStorage.setItem('kref-theme', JSON.stringify(all)); 24 | }); 25 | 26 | var p = 0; 27 | $(window).on('scroll', function(e) { 28 | $('h1').css('position', window.scrollY < p ? 'fixed' : 'absolute'); 29 | p = window.scrollY; 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /src/js/noise.js: -------------------------------------------------------------------------------- 1 | async function noise() { 2 | const black = new Uint8ClampedArray([0, 0, 0, 255]); 3 | const white = new Uint8ClampedArray([255, 255, 255, 255]); 4 | // i had to hardcode --noise-size value since i was too successful in removing css variables 5 | const size = 64; 6 | const data = new Uint8ClampedArray(size * size * 4); 7 | for(let y = 0; y < size; y++) { 8 | for(let x = 0; x < size; x++) { 9 | data.set(Math.random() > .5 ? white : black, (y * size + x) * 4); 10 | } 11 | } 12 | const canvas = document.createElement("canvas"); 13 | canvas.width = canvas.height = size; 14 | const ctx = canvas.getContext("2d"); 15 | ctx.putImageData(new ImageData(data, size, size), 0, 0); 16 | const png = await new Promise(resolve => canvas.toBlob(resolve, "image/png")); 17 | const url = URL.createObjectURL(png); 18 | const div = document.createElement("div"); 19 | div.classList.add("noise"); 20 | div.style = `background-image: url(${url})`; 21 | document.body.appendChild(div); 22 | } 23 | noise(); 24 | -------------------------------------------------------------------------------- /bundler/k.js: -------------------------------------------------------------------------------- 1 | const execSync = require('child_process').execSync 2 | const os = require('os').platform() 3 | 4 | const linux = (i='') => { 5 | let s = execSync(`./pty ./k`, { 6 | cwd: process.cwd() + '/bundler/bin', 7 | input: i + '\n', 8 | encoding: 'utf8' 9 | }) 10 | .split('\n') 11 | .map(m => m.trim()) 12 | //while (s.length && !s[s.length - 1].length) s.pop() 13 | i.length && s.shift() 14 | return s.join('\n').trimEnd('\n') 15 | } 16 | 17 | const osx = (i='') => { 18 | const cmd = 'script -q /dev/null "./k" | cat'//'script -qc "./k" /dev/null | cat' 19 | let s = execSync(cmd, { 20 | cwd: process.cwd() + '/bundler/bin', 21 | input: i + '\n', 22 | encoding: 'utf8' 23 | }) 24 | .split('\n') 25 | .map(m => m.trim()) 26 | while (s.length && !s[0].includes('© shakti')) s.shift() 27 | i.length && s.shift() 28 | //while (s.length && !s[s.length - 1].length) s.pop() 29 | return s.join('\n').trimEnd('\n') 30 | } 31 | 32 | module.exports = os === 'darwin' ? osx : linux 33 | -------------------------------------------------------------------------------- /src/pug/index.pug: -------------------------------------------------------------------------------- 1 | doctype html 2 | html(lang="en") 3 | head 4 | meta(charset="utf-8") 5 | meta(name="viewport" content="width=device-width, initial-scale=1") 6 | title +/kei | K reference card 7 | link(rel="stylesheet" href="./css/core.css") 8 | link(rel="stylesheet" href="./css/media.css") 9 | link(rel="stylesheet" href="./css/fonts.css") 10 | link#theme(rel="stylesheet" href="./css/monokai.css") 11 | body 12 | header 13 | h1#top 14 | span ref #[code#k-item k] 15 | span.right 16 | .easy-autocomplete 17 | input#autocomplete(placeholder="Search...") 18 | img.avatar(src="./svg/kei_logo.svg" alt="kei") 19 | pre.refcard !{h} 20 | main !{md} 21 | footer 22 | span built with love on !{date} 23 | script(src="./js/jquery.min.js") 24 | script(src="./js/theme.js") 25 | script(src="./js/jquery.easy-autocomplete.min.js") 26 | script(src="./js/autocomplete.js") 27 | script(src="./js/noise.js") 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 kparc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bundler/download.js: -------------------------------------------------------------------------------- 1 | const get = require('./get') 2 | const exec = require('child_process').exec 3 | const os = require('os').platform() 4 | 5 | const ex = (s, i='') => new Promise((res, rej) => { 6 | let stdin = exec(s, { 7 | cwd: process.cwd() + '/bundler', 8 | encoding: 'utf8' 9 | }, (e, out, err) => e ? rej(err) : res({e, out, err})).stdin 10 | stdin.write(i) 11 | stdin.end() 12 | }) 13 | 14 | const platform = os === 'darwin' ? 'osx' : 'linux' 15 | 16 | get('https://api.anaconda.org/package/shaktidb/shakti/files', { 17 | 'Accept': 'application/json' 18 | }) 19 | .then(({data}) => JSON.parse(data)) 20 | .then(data => data.filter(i => 21 | i.attrs && i.attrs.platform == platform 22 | ) 23 | .filter(i => 24 | i.labels && i.labels[0] == 'dev' 25 | ) 26 | .reduce((a, b) => a.upload_time > b.upload_time ? a : b).download_url 27 | ) 28 | .then(url => 'https:' + url) 29 | .then(url => console.log(`downloading k from ${url}`) || url) 30 | .then(url => ex(`curl -m 10 -LGs "${url}" | tar -jxf - "bin/k"`)) 31 | .then(nothing => console.log('done')) 32 | .then(nothing => process.exit(0)) 33 | .catch(e => console.error(e) || process.exit(1)) 34 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | const getPugData = require('./bundler/pug.js') 2 | 3 | module.exports = function(grunt) { 4 | 5 | grunt.initConfig({ 6 | uglify: { 7 | files: { 8 | expand: true, 9 | cwd: 'src/js', 10 | src: '**/*.js', 11 | dest: 'build/js' 12 | } 13 | }, 14 | cssmin: { 15 | files: { 16 | expand: true, 17 | cwd: 'src/css', 18 | src: '**/*.css', 19 | dest: 'build/css' 20 | } 21 | }, 22 | pug: { 23 | files: { 24 | src: 'src/pug/index.pug', 25 | dest: 'build/index.html' 26 | }, 27 | options: { 28 | data: getPugData() 29 | } 30 | }, 31 | copy: { 32 | files: { 33 | expand: true, 34 | cwd: 'static', 35 | src: '**', 36 | dest: 'build/' 37 | } 38 | }, 39 | 'gh-pages': { 40 | options: { 41 | base: 'build' 42 | }, 43 | src: ['**'] 44 | } 45 | }); 46 | 47 | grunt.loadNpmTasks('grunt-contrib-uglify-es'); 48 | grunt.loadNpmTasks('grunt-contrib-cssmin'); 49 | grunt.loadNpmTasks('grunt-contrib-pug'); 50 | grunt.loadNpmTasks('grunt-contrib-copy'); 51 | 52 | const tasks = ['uglify', 'cssmin', 'pug', 'copy']; 53 | 54 | grunt.registerTask('default', tasks); 55 | 56 | }; 57 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@kparc/ref", 3 | "version": "1.1.0", 4 | "description": "K reference card", 5 | "keywords": [ 6 | "k", 7 | "help", 8 | "ref" 9 | ], 10 | "main": "grunt", 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1", 13 | "build": "grunt", 14 | "install": "node bundler/download.js && make -C pty", 15 | "dev": "grunt watch", 16 | "clean": "rm -r build" 17 | }, 18 | "author": "", 19 | "license": "MIT", 20 | "engine": { 21 | "node": ">=0.11.15" 22 | }, 23 | "dependencies": { 24 | "cheerio": "^1.0.0-rc.3", 25 | "grunt": "^1.0.4", 26 | "grunt-contrib-copy": "^1.0.0", 27 | "grunt-contrib-cssmin": "^3.0.0", 28 | "grunt-contrib-pug": "^2.0.0", 29 | "grunt-contrib-uglify-es": "^3.3.0", 30 | "grunt-gh-pages": "^3.1.0", 31 | "lodash": "^4.17.19", 32 | "moment": "^2.24.0", 33 | "prismjs": "^1.23.0", 34 | "pug": "^2.0.3", 35 | "rehype-stringify": "^6.0.0", 36 | "remark-parse": "^6.0.3", 37 | "remark-rehype": "^4.0.0", 38 | "unified": "^7.1.0" 39 | }, 40 | "repository": { 41 | "type": "git", 42 | "url": "https://github.com/kparc/ref" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # dotenv environment variables file 55 | .env 56 | 57 | # built files 58 | build/ 59 | bin/ 60 | 61 | # Mac files 62 | .DS_Store 63 | 64 | # Yarn 65 | yarn-error.log 66 | .pnp/ 67 | .pnp.js 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # PPro font family (it's a proprietary font that we can't distribute under MIT) 72 | r.ttf 73 | 74 | # k 75 | k 76 | k.so 77 | -------------------------------------------------------------------------------- /src/css/solarized.css: -------------------------------------------------------------------------------- 1 | /* solarized */ 2 | body { 3 | font-family: "Vinila", "Helvetica", sans-serif; 4 | } 5 | 6 | pre, code, header { 7 | background-color: #f5f5f5; 8 | color: #657b83; 9 | color: #657b83; 10 | /* font-family: PPro,Consolas,Monaco,Andale Mono,Ubuntu Mono,monospace; */ 11 | } 12 | 13 | a, a:hover, a:active, a:visited { 14 | color: #dc322f; 15 | text-decoration: none; 16 | } 17 | 18 | a:hover { 19 | text-decoration: underline; 20 | } 21 | 22 | h1>code, h2>code, h3>code, h4>code, p>code { 23 | background-color: rgba(207,121,100,.06)!important; 24 | } 25 | 26 | h1 { 27 | background-color: #0a3144; 28 | color: #f5f5f5; 29 | } 30 | 31 | h2 { 32 | background-color: #0c6979; 33 | color: #f5f5f5; 34 | } 35 | 36 | #k-item { 37 | background-color: hsla(0,0%,100%,.05)!important; 38 | color: #ddd; 39 | } 40 | 41 | .avatar { 42 | background-color: transparent; 43 | } 44 | 45 | header h1 input, header h1 input:focus { 46 | color: #f5f5f5; 47 | border-color: #f5f5f5; 48 | } 49 | 50 | .easy-autocomplete a:hover { 51 | text-decoration: none; 52 | } 53 | 54 | footer { 55 | background-color: #657b83; 56 | color: #f5f5f5; 57 | } 58 | 59 | .token.verb { 60 | color: #dc322f; 61 | } 62 | 63 | .token.number, .token.symbol { 64 | color: #268bd2; 65 | } 66 | 67 | .token.string { 68 | color: #2aa198; 69 | } 70 | 71 | .token.keyword { 72 | color: #859900; 73 | } 74 | 75 | .token.adverb, .token.function { 76 | color: #859900; 77 | } 78 | -------------------------------------------------------------------------------- /pty/pty.c: -------------------------------------------------------------------------------- 1 | #define _DEFAULT_SOURCE 2 | #define _XOPEN_SOURCE 600 3 | #include "k.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define BSZ 8192 11 | 12 | S USAGE = "usage: %s \n"; 13 | C alt = 4; 14 | 15 | I p(I i, I o, fd_set *r, S b) { 16 | I sz; 17 | if (FD_ISSET(i, r)) { 18 | sz = read(i, b, BSZ); 19 | if (sz > 0) write(o, b, sz); 20 | else if (sz < 0) R1; 21 | else write(o, &alt, 1); 22 | } 23 | R0; 24 | } 25 | 26 | I main(I argc, S* argv) { 27 | I m, s, pid; 28 | fd_set r; 29 | struct termios ts; 30 | C b[BSZ]; 31 | X(argc < 2, fprintf(stderr, USAGE, argv[0]), 1) 32 | m = posix_openpt(O_RDWR); 33 | grantpt(m); 34 | unlockpt(m); 35 | s = open(ptsname(m), O_RDWR); 36 | tcgetattr(s, &ts); 37 | ts.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); 38 | tcsetattr(s, TCSANOW, &ts); 39 | pid = fork(); 40 | if (!pid) { 41 | // child process 42 | close(m); 43 | DO(3,dup2(s,i)) 44 | close(s); 45 | setsid(); 46 | ioctl(0, TIOCSCTTY, 1); 47 | execvp(argv[1], argv + 1); 48 | } else { 49 | // parent process 50 | close(s); 51 | W (1) { 52 | FD_ZERO(&r); 53 | FD_SET(0, &r); 54 | FD_SET(m, &r); 55 | if (!select(m + 1, &r, NULL, NULL, NULL)) break; 56 | if (p(0, m, &r, b)) break; 57 | if (p(m, 1, &r, b)) break; 58 | } 59 | close(m); 60 | } 61 | R0; 62 | } 63 | -------------------------------------------------------------------------------- /pty/k.h: -------------------------------------------------------------------------------- 1 | //! \file k.h \brief less is more 2 | #pragma once 3 | 4 | #define _GNU_SOURCE 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | //! arthur way 11 | typedef char C; 12 | typedef char* S; 13 | typedef int I; 14 | typedef short H; 15 | typedef void V; 16 | typedef float E; 17 | typedef double F; 18 | typedef long J; 19 | typedef unsigned long UJ; 20 | typedef unsigned int UI; 21 | typedef unsigned short UH; 22 | typedef unsigned char G; 23 | 24 | //! no stinking loops 25 | #define DO(n,x) {UJ i=0,_i=(n);for(;i<_i;++i){x;}} 26 | #define W(x) while((x)) 27 | 28 | //! unclutter 29 | #define R return 30 | #define Z static 31 | #define O printf 32 | #define PC putchar 33 | #define SZ sizeof 34 | #define ZV Z V 35 | #define ZI Z I 36 | #define ZC Z C 37 | #define ZH Z H 38 | #define ZS Z S 39 | #define ZE Z E 40 | #define ZF Z F 41 | #define ZJ Z J 42 | #define R0 R 0 43 | #define R1 R 1 44 | 45 | //! safer switch 46 | #define SW switch 47 | #define CD default 48 | #define CS(n,x) case n:;x;break; 49 | 50 | //! fail fast 51 | #define P(x,y) {if(x)R(y);} //< panic 52 | #define X(x,y,z) {if(x){(y);R(z);}} //< clean+panic 53 | 54 | //! easy math 55 | #define ABS(x) (((x)>0)?(x):-(x)) 56 | #define MIN(x,y) ((y)>(x)?(x):(y)) 57 | #define MAX(x,y) ((y)>(x)?(y):(x)) 58 | #define IN(l,x,r) ((l)<=(x)&&(x)<=(r)) 59 | 60 | //! usual suspects 61 | #define scnt(x) (UJ)strlen((S)(x)) 62 | #define scmp(x,y) strcmp((S)(x),(S)(y)) 63 | #define sstr(h,n) strstr((S)(h),(S)(n)) 64 | #define schr(h,n) (S)strchr((S)(h),n) 65 | #define rchr(h,n) (S)strrchr((S)(h),n) 66 | #define mcpy(d,s,n) memcpy((d),(s),n) 67 | #define mcmp(d,s,n) memcmp((d),(s),n) 68 | #define scpy(d,s,n) (S)mcpy((S)d,(S)s,1+MIN(scnt((S)s),n)) 69 | #define lcse(s,n) {DO(n,s[i]=tolower(s[i]))} 70 | 71 | //:~ 72 | -------------------------------------------------------------------------------- /src/css/monokai.css: -------------------------------------------------------------------------------- 1 | /* monokai */ 2 | .noise { 3 | opacity: 0.008; 4 | } 5 | 6 | body { 7 | font-family: "Vinila", "Helvetica", sans-serif; 8 | background-color: #222222; 9 | color: #f7f1ff; 10 | } 11 | 12 | pre, code, header { 13 | background-color: #2a2a2a; 14 | color: #8b888f; 15 | /* font-family: PPro,Consolas,Monaco,Andale Mono,Ubuntu Mono,monospace; */ 16 | } 17 | 18 | a, a:hover, a:active, a:visited { 19 | color: #fc618d; 20 | text-decoration: none; 21 | } 22 | 23 | a:hover { 24 | text-decoration: underline; 25 | } 26 | 27 | h1>code, h2>code, h3>code, h4>code, p>code { 28 | background-color: #363537!important; 29 | } 30 | 31 | h1 { 32 | background-color: #525053; 33 | color: #f7f1ff; 34 | } 35 | 36 | h2 { 37 | background-color: #363537; 38 | } 39 | 40 | #k-item { 41 | background-color: hsla(0,0%,100%,.05)!important; 42 | color: #ddd; 43 | } 44 | 45 | .avatar { 46 | background-color: transparent; 47 | } 48 | 49 | header h1 input, header h1 input:focus { 50 | color: #f7f1ff; 51 | border-color: #f7f1ff; 52 | } 53 | 54 | .easy-autocomplete a:hover { 55 | text-decoration: none; 56 | } 57 | 58 | .easy-autocomplete-container { 59 | background-color: #2a2a2a; 60 | } 61 | 62 | .easy-autocomplete li:hover { 63 | background-color: #363537; 64 | } 65 | 66 | footer { 67 | background-color: #191919; 68 | color: #525053; 69 | } 70 | 71 | .token.verb { 72 | color: #fc618d; 73 | } 74 | 75 | .token.number { 76 | color: #948ae3; 77 | } 78 | 79 | .token.symbol { 80 | color: #5ad4e6; 81 | } 82 | 83 | .token.string { 84 | color: #fce566; 85 | } 86 | 87 | .token.keyword { 88 | color: #7bd88f; 89 | } 90 | 91 | .token.adverb, .token.function { 92 | color: #fd9353; 93 | } 94 | 95 | .token.punctuation { 96 | color: #525053; 97 | } 98 | -------------------------------------------------------------------------------- /src/txt/h.txt: -------------------------------------------------------------------------------- 1 | $k [-p 1234] [f.k] .z.i(pid) .z.x(arg) .z.e(env) 2 | 3 | Verb Adverb Noun Type 4 | : assign ' each n bar char " ab" `c 5 | + add flip / over n div name ``a`b `n 6 | - subtract negate \ scan n mod int Ø 0 2 `i 7 | * multiply first ': eachprior float ø 2.3 π ∞ `f 8 | % divideby inverse /: eachright join|sv date 2019-06-28 `D .z.D 9 | & min|and where \: eachleft split|vs time 12:34:56.789 `t .z.t 10 | | max|or reverse 11 | < less up System list (2;3.4;`c) `. 12 | > more down 0: read/write line dict {a:2;b:`c} `a 13 | = equal group 1: read/write byte tabl +{a:2 3 4} `A 14 | ~ match not 2: read/write data expr :32+9*f%5 `0 15 | ! key enum 3: conn/set (.z.ms) func {(+/x)%#x} `1 16 | , catenate enlist 4: http/get (.z.mg) xtab `a`b!+`c`d!(2 3;4 5) 17 | ^ except asc 18 | # take count #[t;c;b[;a]] select \l f.k load \h help 19 | _ drop floor _[t;c;b[;a]] update \t[:n]x milli/time \l log 20 | ? find unique ?[x;i;f[;y]] splice \u[:n]x micro/trace 21 | @ index type @[x;i;f[;y]] amend \v[d] vars \f[d] fns 22 | . apply value .[x;i;f[;y]] dmend \lf file \lc char \ll line 23 | $ cast|pad string $[c;t;f] cond \cd [d] get[set] \gr x file 24 | 25 | util: in within bin like find freq prm cmb 26 | math: sqrt sin cos abs [n]log [n]exp [n]rand 27 | aggr: count first last min max sum avg var dev med 28 | tabl: [f]asc [f]dsc [f]key [select|update|delete]A by B from T where C 29 | 30 | datetime:YMDHRSTUV+duration:ymdhrstuv; .z.D+.z.t; day:7\ mth:12\ b5:5' 31 | `year`month`date`hour`minute`second`millisecond`microsecond`nanosecond 32 | 33 | bool: `ascii`utf8 34 | 1way: `p`m`crc`sha`rip`bad e.g. hash: `sha@"crypto" 35 | 2way:``j`k`csv`b64`hex`aes e.g. json: `j?`j@{a:2;b:`c} 36 | 37 | if[c;..];while[c;..] 38 | 39 | K:key k:key`k1 /public private 40 | K key k key"hi" /verify sign 41 | "(;)"/:$`x`y`z 42 | \\ exit 43 | attr: ?x ^x =x 44 | -------------------------------------------------------------------------------- /static/svg/kei_logo.svg: -------------------------------------------------------------------------------- 1 | 2 | kei_logo 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/txt/l.txt: -------------------------------------------------------------------------------- 1 | 20190608 2 | f#x revert to f' 3 | 4 | 20190606 5 | 5'12:34 / 5 minute bar 6 | 1s'.z.t / 1 second bar etc. 7 | FIX 8 | .z.D+.z.t 9 | 10 | 20190604 11 | trap: f/:x e.g. (1+)/:` 12 | time: [n]f\:x e.g. (1+)\:2o 13 | NUC 14 | `.=@(2;`a) 15 | 16 | 20190528 17 | FIX 18 | select #a from t 19 | 20 | 20190526 21 | 2/ 2\ (div/mod) 22 | =0 2!2 5 / step function 23 | 24 | 20190524 25 | FIX 26 | ,/,(:) 27 | 28 | 20190522 29 | ?2 3 5 30 | ^2 3 5 31 | FIX 32 | \lc 33 | \ll 34 | 35 | 20190517 36 | FIX 37 | left join(missing) (+`a`b!(2 3 4;4 5 6)),(+`a!2 4)!+`b!7 8 38 | 39 | 20190508 40 | +("**";"***") /flip pad 41 | (0>)+/0 1 -1 -1 0 1 1 1 / early exit 42 | 43 | 20190506 44 | recursion 45 | r:{[a;b;f;g;x]$[x~a;b;f[x]r[a;b;f;g]g x]} 46 | r[1;1;*;-1+]4 47 | 1 1(*;-1+)/4 48 | (3;,2)({y,1_&&/x#'!:'y};1+_sqrt)/100 49 | 50 | NUC 51 | ^x /sort 52 | =x /sortkey 53 | PRF 54 | n^ 55 | !n 56 | *|: /composition 57 | ,/+: /composition 58 | 59 | 20190504 60 | `aes?`aes@"kei" /encrypt&xdecrypt 4GB per second 61 | freq"alibababa" /frequency histogram 1Billion per second 62 | 63 | 20190503 64 | FIX 65 | select #n by b from +`b!2 2 3 4 66 | 67 | 20190501 68 | v:2 3 69 | @[`v;0;7] 70 | PRF 71 | n^i i ? -i : '' 10 | const ifregexp = s => /^\/.*\/$/.test(s) ? new RegExp(s.slice(1, -1)) : s 11 | loadLang(['q']) 12 | 13 | module.exports = function(html) { 14 | var $ = ch.load(html) 15 | var text = k('\\h') 16 | 17 | // get rid of trailing whitespace 18 | text = text.split('\n').map(s => s.trimRight()).join('\n') 19 | 20 | // validate snippets 21 | let snippets = [] 22 | console.log('validating snippets') 23 | console.log(k()) 24 | $('code.language-kc').each((k,v) => console.log(`ran ${k} tests so far`) ||snippets.push(validate($(v).text()))) 25 | snippets = snippets.filter(f => !f.valid) 26 | if (snippets.length) { 27 | console.error(snippets) 28 | // uncomment the following line to make the build fail if errors were detected 29 | throw "invalid snippets detected" 30 | } 31 | 32 | // invoke syntax highlighter, but only on the input lines 33 | $('code.language-kc, code.language-kc-no-tests, code.language-kc-nyi').each((k, v) => $(v).replaceWith( 34 | $(v) 35 | .text() 36 | .split('\n') 37 | .map(s => { 38 | if(!s.length) 39 | return s 40 | return s[0] == '•' 41 | ? `${prism.highlight(s.slice(1), prism.languages.q, 'q')}` 42 | // : `${prism.highlight(s, prism.languages.q, 'q')}` 43 | : `${s}` 44 | }) 45 | .join('\n') 46 | || $.html($(v)) 47 | )) 48 | 49 | // linking the refcard to the text 50 | var d = {} 51 | $('h2,h3,h4').each((k, v) => { 52 | let a = $(v).find('strong') 53 | if (!a.length) 54 | return 55 | 56 | // in case you need an actual in your heading for some reason 57 | // i steal only the last one of them 58 | a = $(a[a.length - 1]) 59 | let id = a.text() 60 | a.replaceWith('') 61 | let kebab = _.kebabCase($(v).text()) 62 | if (!kebab) 63 | return 64 | if (!d[kebab]) 65 | d[kebab] = [] 66 | d[kebab].push({ el: $(v), id }) 67 | }) 68 | 69 | _(d).forOwn((v, k) => { 70 | let id = v[0].id 71 | let i = 0 72 | let r = ifregexp(id) 73 | let t = typeof(r) == "string" ? id : text.match(r) 74 | if (!t) 75 | throw `Lost a link to the refcard: ${id}, ${i}` 76 | text = text 77 | .split(r) 78 | .reduce((a, b) => { 79 | i++; 80 | if (!v.length) 81 | return a + id + b 82 | v.shift().el.attr('id', `${k}${e(i - 1)}`) 83 | return `${a}${t}${b}` 84 | }) 85 | if (v.length) 86 | throw `Lost a link to the refcard: ${id}, ${i}` 87 | }) 88 | 89 | // tables will screw with us unless contaminated in a div 90 | $('table').each((i, el) => $(el).replaceWith(`
${$.html($(el))}
`)) 91 | return { h: k() + '\n' + text, md: $.html(), date: moment().format("LL") } 92 | } 93 | -------------------------------------------------------------------------------- /src/css/core.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | margin: 0; 3 | overflow-x: hidden; 4 | width: 100%; 5 | font-size: 1rem; 6 | font-variation-settings: "wdth" 300, "wght" 300, "slnt" 0; 7 | position: relative; 8 | } 9 | 10 | header { 11 | width: 100%; 12 | position: relative; 13 | } 14 | 15 | header::before { 16 | display: block; 17 | height: 4rem; 18 | content: ' '; 19 | } 20 | 21 | header h1 { 22 | margin: 0; 23 | display: flex; 24 | flex-direction: row; 25 | align-items: center; 26 | padding: 1.2rem 1rem 1rem .5rem; 27 | font-size: 1.5em; 28 | justify-content: space-between; 29 | position: absolute; 30 | top: 0; 31 | left: 0; 32 | right: 0; 33 | } 34 | 35 | h1 { 36 | background-color: white; 37 | } 38 | 39 | h1, h2, h3, h4 { 40 | margin: 0; 41 | font-variation-settings: "size" 500,"quad" 0,"bevl" 0,"oval" 1000; 42 | } 43 | 44 | b, strong { 45 | font-weight: 700; 46 | font-variation-settings: "wdth" 300,"wght" 700,"slnt" 0; 47 | } 48 | 49 | code[class*=language-] { 50 | text-align: left; 51 | white-space: pre; 52 | word-spacing: normal; 53 | word-break: normal; 54 | word-wrap: normal; 55 | line-height: 1.5; 56 | -moz-tab-size: 4; 57 | -o-tab-size: 4; 58 | tab-size: 4; 59 | -webkit-hyphens: none; 60 | -moz-hyphens: none; 61 | -ms-hyphens: none; 62 | hyphens: none; 63 | } 64 | 65 | h1 .right { 66 | display: flex; 67 | flex-direction: row; 68 | align-items: center; 69 | } 70 | 71 | .easy-autocomplete { 72 | font-size: 1rem; 73 | width: 10rem!important; 74 | /* position: relative; */ 75 | height: 1.5rem; 76 | overflow-y: visible; 77 | font-size: 1.4rem; 78 | margin-right: 1rem; 79 | font-family: monospace; 80 | } 81 | 82 | .easy-autocomplete-container { 83 | background-color: white; 84 | position: absolute; 85 | z-index: 9000; 86 | width: 18rem; 87 | right: .5rem; 88 | overflow-x: hidden; 89 | margin-top: .4rem; 90 | } 91 | 92 | .easy-autocomplete ul { 93 | display: block; 94 | margin: 0; 95 | padding: 0; 96 | width: 100%; 97 | } 98 | 99 | .easy-autocomplete li:hover { 100 | background-color: rgba(144, 144, 144, 0.2); 101 | } 102 | 103 | .easy-autocomplete li { 104 | display: block; 105 | margin: 0; 106 | box-sizing: border-box; 107 | width: 100%; 108 | } 109 | 110 | .easy-autocomplete a { 111 | text-decoration: none; 112 | font-weight: normal; 113 | display: block; 114 | padding: .4em .4em; 115 | width: 100%; 116 | } 117 | 118 | h1 input { 119 | background-color: transparent; 120 | border-radius: 0; 121 | border: none; 122 | border-bottom: 1px solid #999; 123 | outline: none; 124 | line-height: 1.4; 125 | font-size: 1.1rem; 126 | width: 100%!important; 127 | font-family: monospace; 128 | } 129 | 130 | .avatar { 131 | width: 1.5em; 132 | padding: 0; 133 | margin: 0; 134 | height: 1.5em; 135 | background-color: black; 136 | border-radius: 1.5em; 137 | z-index: 9001; 138 | cursor: pointer; 139 | } 140 | 141 | header h1 input:focus { 142 | border-bottom-color: #000; 143 | } 144 | 145 | header h1 input::placeholder { 146 | color: #999; 147 | } 148 | 149 | a, a:hover, a:active, a:visited { 150 | color: black; 151 | } 152 | 153 | .refcard { 154 | margin-left: auto; 155 | margin-right: auto; 156 | width: fit-content; 157 | margin-top: 0; 158 | letter-spacing: -0.1em; 159 | } 160 | 161 | h2, h3, h4 { 162 | text-transform: lowercase; 163 | margin: 0; 164 | } 165 | h2 { 166 | margin-top: 1rem; 167 | margin-bottom: .75rem; 168 | padding: 1.5rem 1.5rem 1rem .5rem; 169 | } 170 | 171 | h3 { 172 | padding: 1rem 1.5rem 1rem .5rem; 173 | } 174 | 175 | h4 { 176 | padding-right: 1.45rem; 177 | padding-left: .8rem; 178 | } 179 | 180 | p { 181 | margin-top: .2rem; 182 | margin-bottom: .5rem; 183 | padding-left: .8rem; 184 | padding-right: 1.5rem; 185 | } 186 | 187 | pre { 188 | padding: 1rem; 189 | margin: 0 0 1rem 0; 190 | overflow-x: auto; 191 | } 192 | 193 | header pre { 194 | display: none; 195 | } 196 | 197 | main h2:first-of-type { 198 | margin-top: 0; 199 | } 200 | 201 | code.in::before { 202 | display: inline; 203 | content: ' '; 204 | } 205 | 206 | footer { 207 | box-sizing: border-box; 208 | padding: 1.5rem 1rem 1.5rem 0; 209 | font-size: .7em; 210 | text-align: right; 211 | } 212 | 213 | h1 code, h2 code, h3 code, h4 code, p>code { 214 | padding-left: .15em; 215 | padding-right: .15em; 216 | border-radius: .25rem!important; 217 | display: inline-block; 218 | font-weight: 400!important; 219 | } 220 | 221 | .noise { 222 | position: absolute; 223 | top: 0; 224 | left: 0; 225 | right: 0; 226 | bottom: 0; 227 | background-size: 128px; 228 | pointer-events: none; 229 | opacity: 0.012; 230 | z-index: 999; 231 | animation: fade-in 4s; 232 | } 233 | 234 | #k-item { 235 | border-radius: .25rem; 236 | padding: .2em .15em; 237 | } 238 | -------------------------------------------------------------------------------- /static/js/jquery.easy-autocomplete.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | * easy-autocomplete 3 | * jQuery plugin for autocompletion 4 | * 5 | * @author Łukasz Pawełczak (http://github.com/pawelczak) 6 | * @version 1.3.5 7 | * Copyright License: 8 | */ 9 | 10 | var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){if("xml"===a.dataType&&(a.getValue||(a.getValue=function(a){return $(a).text()}),a.list||(a.list={}),a.list.sort||(a.list.sort={}),a.list.sort.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),c>b?-1:b>c?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(a,b){return a.search(b)>-1}),void 0!==a.categories&&a.categories instanceof Array){for(var b=[],c=0,d=a.categories.length;d>c;c+=1){var e=a.categories[c];for(var f in h.categories[0])void 0===e[f]&&(e[f]=h.categories[0][f]);b.push(e)}a.categories=b}}function c(){function b(a,c){var d=a||{};for(var e in a)void 0!==c[e]&&null!==c[e]&&("object"!=typeof c[e]||c[e]instanceof Array?d[e]=c[e]:b(a[e],c[e]));return void 0!==c.data&&null!==c.data&&"object"==typeof c.data&&(d.data=c.data),d}h=b(h,a)}function d(){if("list-required"!==h.url&&"function"!=typeof h.url){var b=h.url;h.url=function(){return b}}if(void 0!==h.ajaxSettings.url&&"function"!=typeof h.ajaxSettings.url){var b=h.ajaxSettings.url;h.ajaxSettings.url=function(){return b}}if("string"==typeof h.listLocation){var c=h.listLocation;"XML"===h.dataType.toUpperCase()?h.listLocation=function(a){return $(a).find(c)}:h.listLocation=function(a){return a[c]}}if("string"==typeof h.getValue){var d=h.getValue;h.getValue=function(a){return a[d]}}void 0!==a.categories&&(h.categoriesAssigned=!0)}function e(){void 0!==a.ajaxSettings&&"object"==typeof a.ajaxSettings?h.ajaxSettings=a.ajaxSettings:h.ajaxSettings={}}function f(a){return void 0!==h[a]&&null!==h[a]}function g(a,b){function c(b,d){for(var e in d)void 0===b[e]&&a.log("Property '"+e+"' does not exist in EasyAutocomplete options API."),"object"==typeof b[e]&&-1===$.inArray(e,i)&&c(b[e],d[e])}c(h,b)}var h={data:"list-required",url:"list-required",dataType:"json",listLocation:function(a){return a},xmlElementName:"",getValue:function(a){return a},autocompleteOff:!0,placeholder:!1,ajaxCallback:function(){},matchResponseProperty:!1,list:{sort:{enabled:!1,method:function(a,b){return a=h.getValue(a),b=h.getValue(b),b>a?-1:a>b?1:0}},maxNumberOfElements:6,hideOnEmptyPhrase:!0,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a.search(b)>-1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onChooseEvent:function(){},onKeyEnterEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){},onShowListEvent:function(){},onHideListEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,requestDelay:0,adjustWidth:!0,ajaxSettings:{},preparePostData:function(a,b){return a},loggerEnabled:!0,template:"",categoriesAssigned:!1,categories:[{maxNumberOfElements:4}]},i=["ajaxSettings","template"];this.get=function(a){return h[a]},this.equals=function(a,b){return!(!f(a)||h[a]!==b)},this.checkDataUrlProperties=function(){return"list-required"!==h.url||"list-required"!==h.data},this.checkRequiredProperties=function(){for(var a in h)if("required"===h[a])return logger.error("Option "+a+" must be defined"),!1;return!0},this.printPropertiesThatDoesntExist=function(a,b){g(a,b)},b(),c(),h.loggerEnabled===!0&&g(console,a),e(),d()},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Logger=function(){this.error=function(a){console.log("ERROR: "+a)},this.warning=function(a){console.log("WARNING: "+a)}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Constans=function(){var a={CONTAINER_CLASS:"easy-autocomplete-container",CONTAINER_ID:"eac-container-",WRAPPER_CSS_CLASS:"easy-autocomplete"};this.getValue=function(b){return a[b]}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.ListBuilderService=function(a,b){function c(b,c){function d(){var d,e={};return void 0!==b.xmlElementName&&(e.xmlElementName=b.xmlElementName),void 0!==b.listLocation?d=b.listLocation:void 0!==a.get("listLocation")&&(d=a.get("listLocation")),void 0!==d?"string"==typeof d?e.data=$(c).find(d):"function"==typeof d&&(e.data=d(c)):e.data=c,e}function e(){var a={};return void 0!==b.listLocation?"string"==typeof b.listLocation?a.data=c[b.listLocation]:"function"==typeof b.listLocation&&(a.data=b.listLocation(c)):a.data=c,a}var f={};if(f="XML"===a.get("dataType").toUpperCase()?d():e(),void 0!==b.header&&(f.header=b.header),void 0!==b.maxNumberOfElements&&(f.maxNumberOfElements=b.maxNumberOfElements),void 0!==a.get("list").maxNumberOfElements&&(f.maxListSize=a.get("list").maxNumberOfElements),void 0!==b.getValue)if("string"==typeof b.getValue){var g=b.getValue;f.getValue=function(a){return a[g]}}else"function"==typeof b.getValue&&(f.getValue=b.getValue);else f.getValue=a.get("getValue");return f}function d(b){var c=[];return void 0===b.xmlElementName&&(b.xmlElementName=a.get("xmlElementName")),$(b.data).find(b.xmlElementName).each(function(){c.push(this)}),c}this.init=function(b){var c=[],d={};return d.data=a.get("listLocation")(b),d.getValue=a.get("getValue"),d.maxListSize=a.get("list").maxNumberOfElements,c.push(d),c},this.updateCategories=function(b,d){if(a.get("categoriesAssigned")){b=[];for(var e=0;ee;e+=1)c[e].data=b(a,c[e],d);return c},this.checkIfDataExists=function(a){for(var b=0,c=a.length;c>b;b+=1)if(void 0!==a[b].data&&a[b].data instanceof Array&&a[b].data.length>0)return!0;return!1}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.proccess=function(b,c,d){function e(a,c){var d=[],e="";if(b.get("list").match.enabled)for(var g=0,h=a.length;h>g;g+=1)e=b.get("getValue")(a[g]),f(e,c)&&d.push(a[g]);else d=a;return d}function f(a,c){return b.get("list").match.caseSensitive||("string"==typeof a&&(a=a.toLowerCase()),c=c.toLowerCase()),!!b.get("list").match.method(a,c)}function g(a){return void 0!==c.maxNumberOfElements&&a.length>c.maxNumberOfElements&&(a=a.slice(0,c.maxNumberOfElements)),a}function h(a){return b.get("list").sort.enabled&&a.sort(b.get("list").sort.method),a}a.proccess.match=f;var i=c.data,j=d;return i=e(i,j),i=g(i),i=h(i)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a},cssClass:""},description:{type:"description",fields:{description:"description"},method:function(a){return a+" - description"},cssClass:"eac-description"},iconLeft:{type:"iconLeft",fields:{icon:""},method:function(a){return a},cssClass:"eac-icon-left"},iconRight:{type:"iconRight",fields:{iconSrc:""},method:function(a){return a},cssClass:"eac-icon-right"},links:{type:"links",fields:{link:""},method:function(a){return a},cssClass:""},custom:{type:"custom",method:function(){},cssClass:""}},c=function(a){var c,d=a.fields;return"description"===a.type?(c=b.description.method,"string"==typeof d.description?c=function(a,b){return a+" - "+b[d.description]+""}:"function"==typeof d.description&&(c=function(a,b){return a+" - "+d.description(b)+""}),c):"iconRight"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return a+""}:"function"==typeof d.iconSrc&&(c=function(a,b){return a+""}),c):"iconLeft"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return""+a}:"function"==typeof d.iconSrc&&(c=function(a,b){return""+a}),c):"links"===a.type?("string"==typeof d.link?c=function(a,b){return""+a+""}:"function"==typeof d.link&&(c=function(a,b){return""+a+""}),c):"custom"===a.type?a.method:b.basic.method},d=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},e=function(a){var c=function(){return""};return a&&a.type&&a.type&&b[a.type]?function(){var c=b[a.type].cssClass;return function(){return c}}():c};this.getTemplateClass=e(a),this.build=d(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return 0===t.length?void p.error("Input field doesn't exist."):o.checkDataUrlProperties()?o.checkRequiredProperties()?(e(),void g()):void p.error("Will not work without mentioned properties."):void p.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
"),c=n.getValue("WRAPPER_CSS_CLASS");o.get("theme")&&""!==o.get("theme")&&(c+=" eac-"+o.get("theme")),o.get("cssClasses")&&""!==o.get("cssClasses")&&(c+=" "+o.get("cssClasses")),""!==q.getTemplateClass()&&(c+=" "+q.getTemplateClass()),a.addClass(c),t.wrap(a),o.get("adjustWidth")===!0&&b()}function b(){var a=t.outerWidth();t.parent().css("width",a)}function c(){t.unwrap()}function d(){var a=$("
").addClass(n.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
    ")),function(){a.on("show.eac",function(){switch(o.get("list").showAnimation.type){case"slide":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").fadeIn(b),c;break;default:a.find("ul").show()}o.get("list").onShowListEvent()}).on("hide.eac",function(){switch(o.get("list").hideAnimation.type){case"slide":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}o.get("list").onHideListEvent()}).on("selectElement.eac",function(){a.find("ul li").removeClass("selected"),a.find("ul li").eq(w).addClass("selected"),o.get("list").onSelectItemEvent()}).on("loadElements.eac",function(b,c,d){var e="",f=a.find("ul");f.empty().detach(),v=[];for(var h=0,i=0,k=c.length;k>i;i+=1){var l=c[i].data;if(0!==l.length){void 0!==c[i].header&&c[i].header.length>0&&f.append("
    "+c[i].header+"
    ");for(var m=0,n=l.length;n>m&&h
    "),function(){var a=m,b=h,f=c[i].getValue(l[a]);e.find(" > div").on("click",function(){t.val(f).trigger("change"),w=b,j(b),o.get("list").onClickEvent(),o.get("list").onChooseEvent()}).mouseover(function(){w=b,j(b),o.get("list").onMouseOverEvent()}).mouseout(function(){o.get("list").onMouseOutEvent()}).html(q.build(g(f,d),l[a]))}(),f.append(e),v.push(l[m]),h+=1}}a.append(f),o.get("list").onLoadEvent()})}(),t.after(a)}function e(){t.next("."+n.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return o.get("highlightPhrase")&&""!==b?i(a,b):a}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(a,b){var c=h(b);return(a+"").replace(new RegExp("("+c+")","gi"),"$1")}t.parent().hasClass(n.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),u=$("#"+f()),o.get("placeholder")&&t.attr("placeholder",o.get("placeholder"))}function f(){var a=t.attr("id");return a=n.getValue("CONTAINER_ID")+a}function g(){function a(){s("autocompleteOff",!0)&&n(),b(),c(),d(),e(),f(),g()}function b(){t.focusout(function(){var a,b=t.val();o.get("list").match.caseSensitive||(b=b.toLowerCase());for(var c=0,d=v.length;d>c;c+=1)if(a=o.get("getValue")(v[c]),o.get("list").match.caseSensitive||(a=a.toLowerCase()),a===b)return w=c,void j(w)})}function c(){t.off("keyup").keyup(function(a){function b(a){function b(){var a={},b=o.get("ajaxSettings")||{};for(var c in b)a[c]=b[c];return a}function c(a,b){return o.get("matchResponseProperty")!==!1?"string"==typeof o.get("matchResponseProperty")?b[o.get("matchResponseProperty")]===a:"function"==typeof o.get("matchResponseProperty")?o.get("matchResponseProperty")(b)===a:!0:!0}if(!(a.length0?h():i()}var f=b();void 0!==f.url&&""!==f.url||(f.url=o.get("url")),void 0!==f.dataType&&""!==f.dataType||(f.dataType=o.get("dataType")),void 0!==f.url&&"list-required"!==f.url&&(f.url=f.url(a),f.data=o.get("preparePostData")(f.data,a),$.ajax(f).done(function(b){var d=r.init(b);d=r.updateCategories(d,b),d=r.convertXml(d),c(a,b)&&(d=r.processData(d,a),k(d,a)),r.checkIfDataExists(d)&&t.parent().find("li").length>0?h():i(),o.get("ajaxCallback")()}).fail(function(){p.warning("Fail to load response data")}).always(function(){}))}}switch(a.keyCode){case 27:i(),l();break;case 38:a.preventDefault(),v.length>0&&w>0&&(w-=1,t.val(o.get("getValue")(v[w])),j(w));break;case 40:a.preventDefault(),v.length>0&&w40||8===a.keyCode){var c=t.val();o.get("list").hideOnEmptyPhrase!==!0||8!==a.keyCode||""!==c?o.get("requestDelay")>0?(void 0!==m&&clearTimeout(m),m=setTimeout(function(){b(c)},o.get("requestDelay"))):b(c):i()}}})}function d(){t.on("keydown",function(a){a=a||window.event;var b=a.keyCode;return 38===b?(suppressKeypress=!0,!1):void 0}).keydown(function(a){13===a.keyCode&&w>-1&&(t.val(o.get("getValue")(v[w])),o.get("list").onKeyEnterEvent(),o.get("list").onChooseEvent(),w=-1,i(),a.preventDefault())})}function e(){t.off("keypress")}function f(){t.focus(function(){""!==t.val()&&v.length>0&&(w=-1,h())})}function g(){t.blur(function(){setTimeout(function(){w=-1,i()},250)})}function n(){t.attr("autocomplete","off")}a()}function h(){u.trigger("show.eac")}function i(){u.trigger("hide.eac")}function j(a){u.trigger("selectElement.eac",a)}function k(a,b){u.trigger("loadElements.eac",[a,b])}function l(){t.trigger("blur")}var m,n=new a.Constans,o=new a.Configuration(c),p=new a.Logger,q=new a.Template(c.template),r=new a.ListBuilderService(o,a.proccess),s=o.equals,t=b,u="",v=[],w=-1;a.consts=n,this.getConstants=function(){return n},this.getConfiguration=function(){return o},this.getContainer=function(){return u},this.getSelectedItemIndex=function(){return w},this.getItems=function(){return v},this.getItemData=function(a){return v.length0},a.assignRandomId=function(b){var c="";do c="eac-"+Math.floor(1e4*Math.random());while(0!==$("#"+c).length);elementId=a.consts.getValue("CONTAINER_ID")+c,$(b).attr("id",c)},a.setHandle=function(b,c){a.eacHandles[c]=b},a}(EasyAutocomplete||{});!function(a){a.fn.easyAutocomplete=function(b){return this.each(function(){var c=a(this),d=new EasyAutocomplete.main(c,b);EasyAutocomplete.inputHasId(c)||EasyAutocomplete.assignRandomId(c),d.init(),EasyAutocomplete.setHandle(d,c.attr("id"))})},a.fn.getSelectedItemIndex=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemIndex():-1},a.fn.getItems=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getItems():-1},a.fn.getItemData=function(b){var c=a(this).attr("id");return void 0!==c&&b>-1?EasyAutocomplete.getHandle(c).getItemData(b):-1},a.fn.getSelectedItemData=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemData():-1}}(jQuery); -------------------------------------------------------------------------------- /src/md/index.md: -------------------------------------------------------------------------------- 1 | ## Verbs **Verb** 2 | 3 | Force the monadic case by applying a `:` suffix. 4 | 5 | Force the dyadic case by putting the verb in parentheses: 6 | 7 | ```kc 8 | •@1 9 | `i 10 | •(@)1 11 | 1@ 12 | ``` 13 | 14 | Monadic and dyadic versions of a character are **different verbs** - it's not just a case of how many arguments they are called with. 15 | 16 | For example, with a bracket call with one argument, the monadic verb will work fine, while the dyadic verb will project: 17 | 18 | ```kc 19 | •@:["abc"] 20 | `c 21 | •@["abc"] 22 | "abc"@ 23 | ``` 24 | 25 | For dyadic verbs, `x` is on the left and `y` is on the right: 26 | 27 | ```kc 28 | •1,2 29 | 1 2 30 | •,[1;2] 31 | 1 2 32 | ``` 33 | 34 | Project over the first argument by omitting it entirely: 35 | 36 | ```kc 37 | •@[;1] "abc" 38 | "b" 39 | ``` 40 | 41 | Triadic versions of a verb are the same as the dyadic version (except for [`cond`](#cond)): 42 | 43 | ```kc 44 | •(?) . ("abcb"; "b") 45 | 1 46 | •(?) . ("abcb"; 1; "d") 47 | "adbcb" 48 | ``` 49 | 50 | ### Assign `:` **assign** 51 | 52 | Where an assignment is used in a function, consider rewriting code like this ([source](https://groups.google.com/d/msg/shaktidb/zejmh3vxdAg/6uCxAA2aAwAJ)): 53 | 54 | ```kc 55 | f: {a: reusedtempdata; a*a} 56 | ``` 57 | 58 | As this: 59 | 60 | ```kc 61 | f: {a*a:reusedtempdata} 62 | ``` 63 | 64 | Or this: 65 | 66 | ```kc 67 | f: { {x*x} reusedtempdata } 68 | ``` 69 | 70 | You can assign a value to a list index, or a dictionary key: 71 | 72 | ```kc 73 | •a:!3 74 | •a[1]:4 75 | •a 76 | 0 4 2 77 | 78 | •d:`a`b!1 2 79 | •d[`a`c]:3 4 80 | •d 81 | a:3 82 | b:2 83 | c:4 84 | ``` 85 | 86 | You can combine assignment with other verbs: 87 | 88 | ```kc 89 | •a:1 90 | •a+:1 91 | •a 92 | 2 93 | 94 | •l:() 95 | •l,:1 2 3 96 | •l 97 | 1 2 3 98 | 99 | •l[0],:0 100 | •l 101 | 1 0 102 | 2 103 | 3 104 | ``` 105 | 106 | Assign doesn't appear to be callable with square brackets; in fact the parse tree suggests it has an unconventional evaluation order: 107 | 108 | ```kc 109 | •`p "I[0]:4" 110 | :: 111 | (`I;0) 112 | 4 113 | ``` 114 | 115 | Under normal bracket precedence, you'd lose info about where to assign to before the assign verb is invoked, because `` (`I;0) `` would resolve to the first element of `I`. 116 | 117 | ### Add `+` **add** 118 | 119 | ```kc-no-tests 120 | •{a:1}+{a:2} 121 | {a:3} 122 | •{a:1}+{b:2} 123 | a|1 124 | b|2 125 | 126 | •"a"+`c$25 127 | "z" 128 | ``` 129 | 130 | ### Flip `+:` **flip** 131 | 132 | ```kc 133 | • ("a";"bc") 134 | "a" 135 | "bc" 136 | 137 | •+("a";"bc") 138 | ab 139 | ac 140 | 141 | •+(1 2 3;4 5) 142 | 1 4 143 | 2 5 144 | 3 Ø 145 | 146 | •*++("##";"###") 147 | "## " 148 | ``` 149 | 150 | ### First `*:` **first** 151 | 152 | First of an empty list is null of the type of the list: 153 | 154 | ```kc 155 | •*0#,1 156 | Ø 157 | ``` 158 | 159 | ### Divide by `%` **divideby** 160 | 161 | ```kc 162 | •1 % 2 163 | 0.5 164 | ``` 165 | 166 | ### Min `&` **min** 167 | 168 | ```kc 169 | •2 & 1 170 | 1 171 | •2 & 1 3 172 | 1 2 173 | •1 3 & 2 174 | 1 2 175 | •1 3 & 2 0 176 | 1 0 177 | ``` 178 | 179 | 180 | 181 | ### Where `&:` **where** 182 | 183 | Generate an ascending list of numbers, where the number of times number *i* appears is equal to the number at position *i* of the input list. 184 | 185 | ```kc 186 | •&1 0 2 1 187 | ^0 2 2 3 188 | ``` 189 | 190 | ### Up `<:` **up** 191 | 192 | ```kc 193 | •< "abracadabra" 194 | ?0 3 5 7 10 1 8 4 6 2 9 195 | •s@#x} {x,"k"}/"o" 631 | "okkk" 632 | ``` 633 | 634 | ### Scan `\` **scan** 635 | 636 | n f\x 637 | 638 | ```kc 639 | •3 {x+1}\10 640 | 10 11 12 13 641 | ``` 642 | 643 | p f\x 644 | 645 | ```kc 646 | •{4>#x} {x,"k"}\"o" 647 | "o" 648 | "ok" 649 | "okk" 650 | "okkk" 651 | ``` 652 | 653 | ### Each prior `':` **eachprior** 654 | 655 | The null chosen for the first pairing is of the type of the first member of the list. 656 | 657 | ```kc 658 | •{y,x}': !3 659 | Ø 0 660 | 0 1 661 | 1 2 662 | •{y,x}': 1.0 2.1 4.7 663 | ø 1 664 | 1 2.1 665 | 2.1 4.7 666 | •{y,x}': ("a";1;`ok) 667 | " a" 668 | ("a";1) 669 | (1;`ok) 670 | ``` 671 | 672 | Specify a number to seed the scan: 673 | 674 | ```kc 675 | •+':!5 676 | 0 1 3 5 7 677 | •8+':!5 678 | 8 1 3 5 7 679 | ``` 680 | 681 | `':` can also provide a 'sliding window' of size `x` over `y`: 682 | 683 | ```kc 684 | •3': !5 685 | 0 1 2 686 | 1 2 3 687 | 2 3 4 688 | ``` 689 | 690 | ### Each right `/:` **eachright** 691 | 692 | Compare to each: 693 | 694 | ```kc 695 | •"ab" ,' "cd" 696 | ac 697 | bd 698 | •"ab" ,/: "cd" 699 | abc 700 | abd 701 | ``` 702 | 703 | ### Each left `\:` **eachleft** 704 | 705 | ```kc 706 | •"ab" ,\: "cd" 707 | acd 708 | bcd 709 | ``` 710 | 711 | ### Join `/:` **join** 712 | 713 | The following work with **lists of strings**. 714 | 715 | Prepend the separator to `/:`, [without a space in between](https://groups.google.com/d/msg/shaktidb/FRNnOgPgZWA/so4euXj7AAAJ). 716 | 717 | ```kc 718 | •"-"/: ("la";"li";"lu";"le";"lo") 719 | "la-li-lu-le-lo" 720 | ``` 721 | 722 | With empty symbol as 'separator', appends a carriage return and newline to each string and joins. (This is also known as 'sS' or 'string from String', with capitalisation following the k7 convention of lower for atom, upper for list of atoms of same type). 723 | 724 | ```kc 725 | •`/: ("ab";"cd") 726 | "ab\r\ncd\r\n" 727 | ``` 728 | 729 | With three characters instead of just a separator, prepends/appends the first and last: 730 | 731 | ```kc 732 | •"(;)"/: (,:' "abcd") 733 | "(a;b;c;d)" 734 | ``` 735 | 736 | That means 'join' can't be used for multi-character separators, but you can always do this ([source](https://groups.google.com/d/msg/shaktidb/ttIdJiWx9xI/hiTjuX7_BAAJ)): 737 | 738 | ```kc 739 | •{y,x,z}[", "]/$`ab`cd`ef 740 | "ab, cd, ef" 741 | ``` 742 | 743 | ### Split `\:` **split** 744 | 745 | Prepend the separator to `\:`, [without a space in between](https://groups.google.com/d/msg/shaktidb/FRNnOgPgZWA/so4euXj7AAAJ). 746 | 747 | ```kc 748 | •"-"\: "la-li-lu-le-lo" 749 | la 750 | li 751 | lu 752 | le 753 | lo 754 | ``` 755 | 756 | With empty symbol as 'separator', splits on newlines, including (if present) at the end of the last word. (This is also known as 'Ss' or 'String from string'.) 757 | 758 | ```kc 759 | •`\: "ab\ncd\n" 760 | ab 761 | cd 762 | •`\: "ab\ncd" 763 | ab 764 | cd 765 | ``` 766 | 767 | ### Scalar from vector (sv) `/:` **sv** 768 | 769 | Mnemonic tip: read 'sv' in k evaluation order, ie right to left. 770 | 771 | Convert a vector of numbers from a specified base into base 10: 772 | 773 | ```kc 774 | •2/: 1 0 1 0 775 | 10 776 | ``` 777 | 778 | Zero is represented as an empty integer list `!0`, not `0`: 779 | 780 | ```kc-nyi 781 | •10/: !0 782 | 0 783 | •10/: 0 784 | { {z+y*x} / [0;x;y] } 785 | ^ 786 | class error 787 | ``` 788 | 789 | ### Vector from scalar (vs) `\:` **vs** 790 | 791 | Mnemonic tip: read 'vs' in k evaluation order, ie right to left. 792 | 793 | Convert a number from base 10 into a specified base: 794 | 795 | ```kc 796 | •10\: 1000 797 | 1 0 0 0 798 | •2\: 10 799 | 1 0 1 0 800 | ``` 801 | 802 | Conversion of zero into a base may be surprising (empty list), but is consistent: 803 | 804 | ```kc 805 | •10\: 0 806 | !0 807 | ``` 808 | 809 | ## Nouns **Noun** 810 | 811 | ### Names **name** 812 | 813 | Names start with a backtick `` ` ``. Name literals can be: 814 | 815 | - naked (eg `` `abc ``) - contain alphanumerics only 816 | - quoted (eg `` `"a_b" ``) - contain any character, but zero byte (`"\0"`) ends the name. 817 | 818 | Names are also known as symbols. 819 | 820 | ### Floats **float** 821 | 822 | 823 | 824 | 825 | All of `1.0`, `.5`, `1.`, `1f` are valid float literals. 826 | 827 | ```kc 828 | •Ø=ø 829 | 1 830 | •Ø~ø 831 | 0 832 | ``` 833 | 834 | ### Lists **list** 835 | 836 | Although two lists may be zero length, and have the same type, they may not be the same: 837 | 838 | ```kc 839 | •(@()) = @0 2 # 0 840 | 1 841 | •(#()) = #0 2 # 0 842 | 1 843 | •() ~ 0 2 # 0 844 | 0 845 | ``` 846 | 847 | The 'extra dimensions' can matter for matrix multiplication: 848 | 849 | ```kc-nyi 850 | •() $ (0 2 # 0) 851 | 0#,ø ø 852 | •(!0) $ (0 2 # 0) 853 | 0 0f 854 | •(0 2 # 0) $ !0 855 | (0 2 # 0) $ !0 856 | ^ 857 | length error 858 | ``` 859 | 860 | Empty list `()` is the same as `0 0#""`, but not `0#""` or `0 0 0#""`: 861 | 862 | ```kc 863 | •0#"" 864 | "" 865 | •0 0#"" 866 | () 867 | •()~0 0#"" 868 | 1 869 | •()~0 0 0#"" 870 | 0 871 | ``` 872 | 873 | `` (2;3.4;`c) `` (or any list of atoms, functions etc) can also be written `` 2,3.4,`c ``: 874 | 875 | ```kc 876 | •(2;3.4;`c)~2,3.4,`c 877 | 1 878 | ``` 879 | 880 | But it breaks down when you include nested lists such as strings: 881 | 882 | ```kc 883 | •2,"hi",`c 884 | 2 885 | "h" 886 | "i" 887 | `c 888 | ``` 889 | 890 | ### Dictionaries **dict** 891 | 892 | Dicts are ordered: 893 | 894 | ```kc 895 | •|`a`b!1 2 896 | b:2 897 | a:1 898 | ``` 899 | 900 | Recover the keys and values using `!:` and `.:`: 901 | 902 | ```kc 903 | •!`a`b!1 2 904 | `a`b 905 | •.`a`b!1 2 906 | 1 2 907 | ``` 908 | 909 | ### Functions **func** 910 | 911 | Functions can call themselves by using their own name in their definition. Naive example: 912 | 913 | ```kc 914 | •factorial: {$[x<2;1;x*factorial[x-1]]} 915 | •factorial 4 916 | 24 917 | ``` 918 | 919 | ### Expressions **expr** 920 | 921 | Exprs can be executed on tables, eg: 922 | 923 | ```kc 924 | •t: +`a`b!(1 2 3;4 5 6) 925 | •t :a>1 926 | 0 1 1 927 | •t@&t :a>1 928 | a b 929 | - - 930 | 2 5 931 | 3 6 932 | ``` 933 | 934 | Some expr functionality is NYI. For more info, see [this forum post](https://groups.google.com/d/msg/shaktidb/5N6VjsOBjoA/GjFgeP4yDAAJ). 935 | 936 | ## Utilities **util** 937 | 938 | ### `in` **/in(?= within)/** 939 | 940 | ```kc 941 | •`c`d in `a`b`c 942 | 1 0 943 | 944 | •"abcz" in "abracadabra" 945 | 1 1 1 0 946 | 947 | •2 5 in !5 948 | 1 0 949 | •2 5 in (1 2; 2 5; 2 4) 950 | 1 951 | •2 5 in (1 2; 2 4) 952 | 0 953 | ``` 954 | 955 | ### `within` **within** 956 | 957 | ```kc 958 | •`p within `A`z 959 | 1 960 | •`p within `A`Z 961 | 0 962 | ``` 963 | 964 | Includes lower bound, excludes upper bound: 965 | 966 | ```kc 967 | •1 within 1 2 968 | 1 969 | •2 within 1 2 970 | 0 971 | •1 2 3 within 1 3 972 | 1 1 0 973 | ``` 974 | 975 | ### `like` **like** 976 | 977 | ```kc 978 | •"abc" like "*b?" 979 | 1 980 | •"abcd" like "*b?" 981 | 0 982 | 983 | •(,"1") like "[0-3]" 984 | 1 985 | •(,"4") like "[0-3]" 986 | 0 987 | ``` 988 | 989 | ### Frequency histogram `freq` **freq** 990 | 991 | Counts of each item in the list. 992 | 993 | ```kc 994 | •freq "alibaba" 995 | a|3 996 | b|2 997 | i|1 998 | l|1 999 | ``` 1000 | 1001 | ### `find` **find** 1002 | 1003 | ```kc 1004 | •"abracadabra" find "bra" 1005 | 1 3 1006 | 8 3 1007 | ``` 1008 | 1009 | ### Sort ascending `[f]asc` **[f]asc** 1010 | 1011 | ```kc 1012 | •asc "abracadabra" 1013 | ^"aaaaabbcdrr" 1014 | ``` 1015 | 1016 | ### Sort descending `[f]dsc` **[f]dsc** 1017 | 1018 | ```kc 1019 | •dsc "abracadabra" 1020 | "rrdcbbaaaaa" 1021 | ``` 1022 | 1023 | ### Key `[f]key` **[f]key** 1024 | 1025 | Turn a table into a keyed table: 1026 | 1027 | ```kc 1028 | •`a`c key (`a`b`c!1 2 3;`a`b`c!4 5 6) 1029 | a c|b 1030 | - -|- 1031 | 1 3|2 1032 | 4 6|5 1033 | ``` 1034 | 1035 | ## Math **math** 1036 | 1037 | ### Absolute value `abs` **abs** 1038 | 1039 | ```kc 1040 | •abs 1.23 1041 | 1.23 1042 | •abs -1.23 1043 | 1.23 1044 | ``` 1045 | 1046 | ### Permutations `prm` **prm** 1047 | 1048 | Generates permutation indices. 1049 | 1050 | ```kc 1051 | •prm 3 1052 | ?0 1 2 1053 | ?1 0 2 1054 | ?1 2 0 1055 | ?0 2 1 1056 | ?2 0 1 1057 | ?2 1 0 1058 | ``` 1059 | 1060 | ### Combinations **cmb** 1061 | 1062 | ```kc 1063 | •2 cmb 3 1064 | 0 1 1065 | 0 2 1066 | 1 2 1067 | ``` 1068 | 1069 | ### Natural logarithm (`log:`) and logarithm (`log`) **[n]log** 1070 | 1071 | Monadic: natural logarithm, ie the power you'd need to raise *e* by to get `x`. 1072 | 1073 | ```kc 1074 | •log 2 1075 | 0.6931472 1076 | •log (exp 1) 1077 | 1f 1078 | •(exp 1) exp (log 2) 1079 | 2f 1080 | ``` 1081 | 1082 | Dyadic: logarithm, ie the number you'd need to raise the left number to to get the right number. 1083 | 1084 | ```kc 1085 | •2 log 2 1086 | 1f 1087 | •2 log 4 1088 | 2f 1089 | ``` 1090 | 1091 | ### Exponential (`exp:`) and power (`exp`) **[n]exp** 1092 | 1093 | Monadic: *e* to the power of `x`. 1094 | 1095 | ```kc 1096 | •exp 1 1097 | 2.718282 1098 | •exp 2 1099 | 7.389056 1100 | •(exp 1) exp 2 1101 | 7.389056 1102 | ``` 1103 | 1104 | Dyadic: left to the power of right. 1105 | 1106 | ```kc 1107 | •2 exp 4 1108 | 16f 1109 | •2 exp -1 1110 | 0.5 1111 | ``` 1112 | 1113 | ### Random `[n]rand` **[n]rand** 1114 | 1115 | Uniform distribution `rand i` or `i rand i`: 1116 | 1117 | ```kc-no-tests 1118 | •rand 3 1119 | 0.5 0.9078156 0.269656 1120 | •3 rand 10 1121 | 5 5 1 1122 | ``` 1123 | 1124 | Normal distribution `rand -i`: 1125 | 1126 | ```kc-no-tests 1127 | •`m @ rand -5 1128 | 1.157194e-13 1129 | -0.5821508 1130 | 1.846709 1131 | -1.075539 1132 | 0.890081 1133 | ``` 1134 | 1135 | ### Bar `i'` **bar** 1136 | 1137 | Round down to the nearest `i`. 1138 | 1139 | ```kc 1140 | •5'9 1141 | 5 1142 | •5'10 1143 | 10 1144 | ``` 1145 | 1146 | ### Integer division `i/` **div** 1147 | 1148 | ```kc 1149 | •5/9 1150 | 1 1151 | •5/10 1152 | 2 1153 | ``` 1154 | 1155 | ### Mod `i\` **mod** 1156 | 1157 | ```kc 1158 | •2\!10 1159 | 0 1 0 1 0 1 0 1 0 1 1160 | ``` 1161 | 1162 | ## Aggregations **aggr** 1163 | 1164 | ### Median `med` **med** 1165 | 1166 | The value in the middle if the data was sorted. 1167 | 1168 | If the count of the data is even, return the value on the right of the middle. 1169 | 1170 | ```kc 1171 | •med !3 1172 | 1 1173 | •med !4 1174 | 2 1175 | •med 2 3 1 1176 | 2 1177 | ``` 1178 | 1179 | ## Tables and KSQL 1180 | 1181 | ### Tables **tabl** 1182 | 1183 | A table is a list of dicts where each dict has the same keys in the same order. 1184 | 1185 | A table can also be considered as a flipped dict of lists, where each list is of equal length. 1186 | 1187 | ```kc 1188 | •t:(`a`b!1 2;`a`b!3 4) 1189 | •u:+`a`b!(1 3;2 4) 1190 | •t~u 1191 | 1 1192 | ``` 1193 | 1194 | You can access rows or columns of the table by indexing using the row number or column key: 1195 | 1196 | ```kc 1197 | •t:(`a`b!1 2;`a`b!3 4) 1198 | •t[1]~`a`b!3 4 1199 | 1 1200 | •t[`b]~2 4 1201 | 1 1202 | •t[1;`a]~3 1203 | 1 1204 | ``` 1205 | 1206 | Key tables are dictionaries where the rows of one table map to the rows of another table. 1207 | 1208 | You can also use `key` to set the key columns after creation. 1209 | 1210 | ```kc 1211 | •k:(`a`c!1 3;`a`c!4 6) 1212 | •v:(`b!2;`b!5) 1213 | •kt: k!v 1214 | •kt~(+`a`c!(1 4;3 6))!+`b!2 5 1215 | 1 1216 | •@kt 1217 | `a 1218 | 1219 | •t:(`a`b`c!1 2 3;`a`b`c!4 5 6) 1220 | •tk:`a`c key t 1221 | •tk~kt 1222 | 1 1223 | ``` 1224 | 1225 | Access rows of the value table by indexing into the keytable: 1226 | 1227 | ```kc 1228 | kt[`a`c!4 6] / {b:5} 1229 | ``` 1230 | 1231 | ### KSQL {ksql} 1232 | 1233 | ```kc-no-tests 1234 | •t:+`a`b!(1 3;2 4) 1235 | •update b:a*2 from t 1236 | a b 1237 | - - 1238 | 1 2 1239 | 3 6 1240 | 1241 | •t / t not updated in-place 1242 | a b 1243 | - - 1244 | 1 2 1245 | 3 4 1246 | ``` 1247 | 1248 | Use `by` to group rows or aggregations: 1249 | 1250 | ```kc 1251 | •t:+`a`b`c!(1 2 1;2 3 4;3 4 5);t 1252 | a b c 1253 | - - - 1254 | 1 2 3 1255 | 2 3 4 1256 | 1 4 5 1257 | 1258 | •select by a from t 1259 | a| 1260 | -|-------------- 1261 | 1|+{b:2 4;c:3 5} 1262 | 2|+{b:,3;c:,4} 1263 | 1264 | •select sum b by a from t 1265 | a|b 1266 | -|- 1267 | 1|6 1268 | 2|3 1269 | ``` 1270 | 1271 | ## Commands 1272 | 1273 | Access any shell command by putting a `\` in front of it: 1274 | 1275 | ```kc-no-tests 1276 | •\seq 3 1277 | 1 1278 | 2 1279 | 3 1280 | ``` 1281 | 1282 | ### List files `\lf` **\lf** 1283 | 1284 | ```kc-no-tests 1285 | •\lf 1286 | afile.txt 1287 | yet another file 1288 | ``` 1289 | 1290 | ### List character counts `\lc` **\lc** 1291 | 1292 | ```kc-no-tests 1293 | •\lc 1294 | afile.txt |29 1295 | yet another file|50 1296 | ``` 1297 | 1298 | You can't assign the result of `\lc` directly (ie `a: \lc` doesn't work). But you *can* capture its output and see that it is in fact a dictionary: 1299 | 1300 | ```kc-no-tests 1301 | •{(x;@x)} @ . "\\lc" 1302 | (,"k";"test.csv";"test.k";"test.txt";"testfile")!211392 12 4 12 24j 1303 | `a 1304 | ``` 1305 | 1306 | ### List line counts `\ll` **\ll** 1307 | 1308 | ```kc-no-tests 1309 | •\ll 1310 | afile.txt |1 1311 | yet another file|3 1312 | ``` 1313 | 1314 | ### Help `\h` **\h** 1315 | 1316 | The official help included in the k binary. It's the navigation to this site! 1317 | 1318 | ### Changelog `\l` **\l** 1319 | 1320 | Find the latest changelog on [GitHub](https://github.com/kparc/box/blob/master/txt/l.txt). 1321 | 1322 | ## IO and IPC 1323 | 1324 | ### Read/write line `0:` **read/write line** 1325 | 1326 | Given the following in `test.csv`: 1327 | 1328 | ```kc 1329 | 1,ABC,1.23 1330 | 3,DEF,4567.89 1331 | ``` 1332 | 1333 | We can read it in as lists of type `inf` respectively and separator `,`: 1334 | 1335 | ```kc-nyi 1336 | •("inf";",")0:"test.csv" 1337 | 1 3 1338 | `ABC`DEF 1339 | 1.23 4567.89 1340 | ``` 1341 | 1342 | The filename can be given as `` `test.csv `` instead of `"test.csv"` (one char shorter!). 1343 | 1344 | We can also write lists of strings to a file (verify output using a text editor): 1345 | 1346 | ```kc 1347 | •"test.txt" 0: ("hello";"world") 1348 | ``` 1349 | 1350 | And that includes saving tables to CSV, if we first convert the table to a list of strings: 1351 | 1352 | ```kc 1353 | •"test.csv" 0: `csv @ (+`a`b!(1 2;3 4)) 1354 | ``` 1355 | 1356 | You can also use `0:` to deserialise in-memory lists of strings with a common separator. [Arthur's example](https://groups.google.com/d/msg/shaktidb/vE4ffjndxik/rYF6K78oBQAJ): 1357 | 1358 | ```kc 1359 | • ("ii";"|")0:("2|3";"3|4";"4|5") 1360 | 2 3 4 1361 | 3 4 5 1362 | ``` 1363 | 1364 | Keep in mind it's reading the data into columns, not rows. The first row of the console output is the first item in a list of columns. 1365 | 1366 | ### Read/write bytes `1:` **read/write byte** 1367 | 1368 | ```kc 1369 | •"testfile" 1: 0x0123456789abcdef 1370 | •1: "testfile" 1371 | 0x0123456789abcdef 1372 | ``` 1373 | 1374 | You can verify `1:` works with raw bytes using an external tool: 1375 | 1376 | ```kc 1377 | $ hexdump -C testfile 1378 | 00000000 01 23 45 67 89 ab cd ef 1379 | 00000008 1380 | ``` 1381 | 1382 | And to break down what's happening in the 'prompt' example from the official tutorial, ie: 1383 | 1384 | ```kc-nyi 1385 | •name: 1: ("" 1: "What is your name? ") 1386 | What is your name? Me 1387 | •name 1388 | "Me" 1389 | ``` 1390 | 1391 | - Read from stdin: `1: ""` or `` 1: ` `` 1392 | - Write to stdout: `"" 1: "string"` or `` ` 1: "string" `` 1393 | - `x 1: y` returns `x` ([source](https://groups.google.com/d/msg/shaktidb/DmV2eoSEGHU/eEEOKfjCBQAJ)) 1394 | 1395 | On the last point: if just writing to stdout, make sure to put a semicolon at the end to suppress outputting the characters on the left of `1:` to the REPL. 1396 | 1397 | ### Read/write data `2:` **read/write data** 1398 | 1399 | ```kc 1400 | •"testfile" 2: (1 2 3 4) 1401 | •2: "testfile" 1402 | 1 2 3 4 1403 | ``` 1404 | 1405 | You can see what `testfile` looks like in bytes with `1:`: 1406 | 1407 | ```kc 1408 | •1: "testfile" 1409 | 0x000000070400000001000000020000000300000004000000 1410 | ``` 1411 | 1412 | ### Inter-process communication `3:` and `4:` **set/conn** 1413 | 1414 | Start a k process running with port 1234 (that's `k -p 1234`). 1415 | 1416 | Then in another k process, set up a connection to the first k process, send it commands, and get responses: 1417 | 1418 | ```kc-nyi 1419 | 2019-04-18 15:45:55 2core 1gb avx2 © shakti l2.0 test 1420 | •conn: 3: 1234 1421 | •conn 4: "life: 42" 1422 | •conn 4: "life" 1423 | 42 1424 | ``` 1425 | 1426 | ## 3+ arguments 1427 | 1428 | ### Select `#[t;c;b[;a]]` **select** 1429 | 1430 | Get all rows of `t` where `c` is true. 1431 | 1432 | ```kc 1433 | •t: +`a`b!(1 2 3;4 5 6) 1434 | •#[:a>1;t] 1435 | a b 1436 | - - 1437 | 2 5 1438 | 3 6 1439 | 1440 | • / But since there are just two arguments, 1441 | • / we can use # as an infix verb: 1442 | 1443 | •(:a>1)#t 1444 | a b 1445 | - - 1446 | 2 5 1447 | 3 6 1448 | 1449 | •(:(a>1)&(b<6)) # t 1450 | +{a:,2;b:,5} 1451 | •(:(a>1)&(b<5)) # t 1452 | +{a:!0;b:!0} 1453 | ``` 1454 | 1455 | ### Update `_[t;c;b[;a]]` **update** 1456 | 1457 | Via [Arthur](https://groups.google.com/d/msg/shaktidb/77qVfIc5ecU/eSRy8izkAQAJ): 1458 | 1459 | ```kc-no-tests 1460 | •t:+`b!2 3 1461 | •_[t;();`b! :b+1] 1462 | b 1463 | - 1464 | 3 1465 | 4 1466 | ``` 1467 | 1468 | ### Splice `?[x;i;f[;y]]` **splice** 1469 | 1470 | Insert `y` into `x` at index `i`. 1471 | 1472 | If an element was at that index before, move it right. 1473 | 1474 | ```kc 1475 | •?[!3;2;`abc] 1476 | 0 1477 | 1 1478 | `abc 1479 | 2 1480 | •?[!3;2;"abc"] 1481 | 0 1482 | 1 1483 | "a" 1484 | "b" 1485 | "c" 1486 | 2 1487 | 1488 | ``` 1489 | 1490 | ### Amend `@[x;i;f[;y]]` **amend** 1491 | 1492 | Apply function f to the elements at each `i` of `x` (with argument `y`, if f is dyadic). 1493 | 1494 | ```kc 1495 | •@[!3; 0 2; 1+] 1496 | 1 1 3 1497 | •@[!3; 0 2; +; 2 7] 1498 | 2 1 9 1499 | ``` 1500 | 1501 | To do the update in-place, use the data's name symbol instead of the name directly (`` `name `` vs `name`). 1502 | 1503 | ```kc 1504 | •v:!3 1505 | •@[v;1;7] 1506 | 0 7 2 1507 | •v / original assignment unchanged 1508 | !3 1509 | •@[`v;1;7] 1510 | `v 1511 | •v 1512 | 0 7 2 1513 | ``` 1514 | 1515 | ### Dmend `.[x;i;f[;y]]` **dmend** 1516 | 1517 | Think of dmend as 'deep' or 'drill' amend - it's similar to amend in the same way that dyadic `.` and `@` are similar. 1518 | 1519 | `i` is a list that governs which slices of `x` to apply `f` to. 1520 | 1521 | Apply `f` to slices 0 and 2 on the first 'depth' level down: 1522 | 1523 | ```kc 1524 | •.[!3; ,0 2; 7] 1525 | 7 1 7 1526 | ``` 1527 | 1528 | Apply to rows or specific elements of a matrix: 1529 | 1530 | ```kc 1531 | •:: m: 3 3 # !9 1532 | 0 1 2 1533 | 3 4 5 1534 | 6 7 8 1535 | 1536 | • / Row 1: 1537 | 1538 | •.[m; ,1; 1+] 1539 | 0 1 2 1540 | 4 5 6 1541 | 6 7 8 1542 | 1543 | • / Row 1, element 2: 1544 | 1545 | •.[m; 1 2; 1+] 1546 | 0 1 2 1547 | 3 4 6 1548 | 6 7 8 1549 | 1550 | • / Row 0, elements 1 and 2: 1551 | 1552 | •.[m; (0; 1 2); 1+] 1553 | 0 2 3 1554 | 3 4 5 1555 | 6 7 8 1556 | 1557 | • / In each of rows 1 and 2, elements 1 and 2: 1558 | 1559 | •.[m; (1 2; 1 2); 1+] 1560 | 0 1 2 1561 | 3 5 6 1562 | 6 8 9 1563 | 1564 | • / In all rows, elements 1 and 2: 1565 | 1566 | •.[m; (; 1 2); 1+] 1567 | 0 2 3 1568 | 3 5 6 1569 | 6 8 9 1570 | ``` 1571 | 1572 | ### Cond `$[c;t;f]` **cond** 1573 | 1574 | If the true expression is returned, the false expression never executes (and vice versa): 1575 | 1576 | ```kc 1577 | •a:1;b:1 1578 | •$[1;a+:1;b+:1]; (a;b) 1579 | 2 1 1580 | •$[0;a+:1;b+:1]; (a;b) 1581 | 2 2 1582 | ``` 1583 | 1584 | [Unlike other triadics](#Verb), triadic `$` is not the same as dyadic `$`: 1585 | 1586 | ```kc-nyi 1587 | •($) . (`n; "a") 1588 | `a 1589 | •($) . (1; "a"; "b") 1590 | ($) . (1; "a"; "b") 1591 | ^ 1592 | nyi error 1593 | ``` 1594 | 1595 | Simulate a vector cond: 1596 | 1597 | ```kc 1598 | •{$[x;y;z]}'[1 0 1; "abc"; "def"] 1599 | "aec" 1600 | ``` 1601 | 1602 | Or (modified version of [Arthur's](https://groups.google.com/d/msg/shaktidb/6JLpGPE-bfM/mlAzxcrgAQAJ) - no `$` needed!): 1603 | 1604 | ```kc 1605 | •{(+(z;y))@'x}[1 0 1;"abc";"def"] 1606 | "aec" 1607 | ``` 1608 | 1609 | ## Datetimes **datetime** 1610 | 1611 | A datetime looks like this: 1612 | 1613 | ```kc 1614 | •2019-05-04T13:13:12.313 /.z.T 1615 | 2019-05-04T13:13:12.313 1616 | ``` 1617 | 1618 | Datetime literals are [designed](https://groups.google.com/forum/#!topic/shaktidb/184DnAJrwKU) to match [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. 1619 | 1620 | Dates start from `2024-01-01`: 1621 | 1622 | ```kc 1623 | •`D $ 0 1624 | 2024-01-01 1625 | ``` 1626 | 1627 | '0' is Monday. Get the day of the week with `7 mod`. 1628 | 1629 | ```kc 1630 | •d:`Mon`Tue`Wed`Thu`Fri`Sat`Sun 1631 | •d @ 7\2024-01-01 1632 | `Mon 1633 | ``` 1634 | 1635 | You can also use duration literals (requires short-form code), and do date arithmetic: 1636 | 1637 | ```kc 1638 | •2024-01-01 + 2m 1639 | 2024-03-01 1640 | ``` 1641 | 1642 | Datetime and duration names: 1643 | 1644 | | Long-form duration | Short-form duration | Datetime | 1645 | | ------------------ | ------------------- | -------- | 1646 | | \`year | \`y | \`Y | 1647 | | \`month | \`m | \`M | 1648 | | \`date | \`d | \`D | 1649 | | \`hour | \`h | \`H | 1650 | | \`minute | \`r | \`R | 1651 | | \`second | \`s | \`S | 1652 | | \`millisecond | \`t | \`T | 1653 | | \`microsecond | \`u | \`U | 1654 | | \`nanosecond | \`v | \`V | 1655 | 1656 | Convert to/from/between datetimes and durations using `$`. It takes a name or string (short version only): 1657 | 1658 | ```kc 1659 | •`year $ .z.t / .z.t doesn't contain year 1660 | 0y 1661 | •`Y $ .z.D 1662 | 2019Y 1663 | •`Y $ .z.D+.z.t 1664 | 2019Y 1665 | •`y $ 2019 1666 | 2019y 1667 | •"y" $ 2019 1668 | 2019y 1669 | ``` 1670 | 1671 | Convert between dates and year, month date digits using [`` `/: ``](#sv) and [`` `\: ``](#vs). 1672 | 1673 | ### Current date `.z.d` 1674 | 1675 | ```kc 1676 | .z.d / 2019-04-02 1677 | ``` 1678 | 1679 | ### Current time `.z.t` **.z.t** 1680 | 1681 | Greenwich Mean Time. 1682 | 1683 | ```kc 1684 | .z.t / 11:18:14.857 1685 | ``` 1686 | 1687 | ## Converters 1688 | 1689 | ### One-way conversions **1way** 1690 | 1691 | Convert to with `` `x@data `` or `` `x data `` or `` `x[data] ``, where `` `x `` is the relevant name. 1692 | 1693 | #### Parse `` `p `` **`p** 1694 | 1695 | ```kc 1696 | •`p @ "5*!3" 1697 | * 1698 | 5 1699 | (!:;3) 1700 | ``` 1701 | 1702 | A parse tree can be executed with `.`: 1703 | 1704 | ```kc 1705 | •. `p @ "5*!3" 1706 | 0 5 10 1707 | ``` 1708 | 1709 | Although parse trees can be converted into strings with `` `p ? ``, it is not a lossless conversion. 1710 | 1711 | The parser enlists names (and lists of names) to indicate they should not be evaluated. 1712 | 1713 | Examples: 1714 | 1715 | ```kc 1716 | •e: "1;.1;`n;\"c\";1 2;1. 2.;`n`o;\"chars\";" 1717 | •e,:":;v;1+2;+/1 2;{x+2*y};a:1;:a+2*b; /comment;\\h" 1718 | 1719 | •{`string`parsetree`type!(x;`p x;@`p x)}' ";"\: e 1720 | string parsetree type 1721 | --------- ----------- ---- 1722 | 1 1 `i 1723 | .1 0.1 `f 1724 | `n ,`n `n 1725 | "c" "c" `c 1726 | 1 2 1 2 `i 1727 | 1. 2. 1 2f `f 1728 | `n`o ,`n`o `. 1729 | "chars" "chars" `c 1730 | : : `2 1731 | v `v `n 1732 | 1+2 (+;1;2) `. 1733 | +/1 2 ((/;+);1 2) `. 1734 | {x+2*y} {x+2*y} `2 1735 | a:1 (::;`a;1) `. 1736 | :a+2*b :a+2*b `0 1737 | /comment ` 1738 | \h (;`h) `. 1739 | ``` 1740 | 1741 | #### Matrix display `` `m `` **/\`m(?=\`crc)/** 1742 | 1743 | ```kc 1744 | d: 1 2 3 1745 | d 1746 | 1 2 3 1747 | `m d 1748 | 1 1749 | 2 1750 | 3 1751 | ``` 1752 | 1753 | ### Two-way conversions **2way** 1754 | 1755 | Convert to with `` `x@data `` or `` `x data ``, where `` `x `` is the relevant name. 1756 | 1757 | Convert from with `` `x?serialdata ``. 1758 | 1759 | #### Binary `` ` `` **/\`(?=\`j)/** 1760 | 1761 | ```kc 1762 | •` "a" 1763 | 0x0161 1764 | •` `a 1765 | 0x0f6100 1766 | •` 10 1767 | 0x070a000000 1768 | ``` 1769 | 1770 | #### JSON `` `j `` **/\`j(?=\`k)/** 1771 | 1772 | ```kc 1773 | •`j(+`a`b!(1,"x";2,`z)) 1774 | "[{\"a\":1,\"b\":2},{\"a\":\"x\",\"b\":\"z\"}]" 1775 | ``` 1776 | 1777 | #### KSON `` `k `` **/\`k(?=\`csv)/** 1778 | 1779 | ```kc 1780 | •`k 2*!3 1781 | "0 2 4" 1782 | •`k(+`a`b!(1,"x";2,`z)) 1783 | "+{a:(1;\"x\");b:(2;`z)}" 1784 | ``` 1785 | 1786 | #### `` `csv `` **`csv** 1787 | 1788 | ```kc 1789 | •`csv ? ("a,b";"1,2";"3,4") 1790 | a b 1791 | - - 1792 | 1 2 1793 | 3 4 1794 | ``` 1795 | 1796 | ## FAQ 1797 | 1798 | #### How can I test if something is an atom, or a list? 1799 | 1800 | ```kc 1801 | isatom:{x~*x} 1802 | ``` 1803 | 1804 | #### How do I see the output of an assignment expression? 1805 | 1806 | Use the identity function, `::`: 1807 | 1808 | ```kc 1809 | •a:1+2 / no output 1810 | •:: a:1+2 1811 | 3 1812 | •@(::) 1813 | `1 1814 | ``` 1815 | 1816 | #### How do I make an empty typed list? 1817 | 1818 | For characters, it's just `""`: 1819 | 1820 | ```kc 1821 | •#"" 1822 | 0 1823 | •@"" 1824 | `c 1825 | ``` 1826 | 1827 | For integers and floats, use `!`: 1828 | 1829 | ```kc 1830 | •@!0 1831 | `i 1832 | •#!0 1833 | 0 1834 | •@!.0 1835 | `f 1836 | •#!.0 1837 | 0 1838 | ``` 1839 | 1840 | For other types, take 0 elements of an atom of that type (may be a better way?). For example, for names: 1841 | 1842 | ```kc 1843 | •@0#` 1844 | `n 1845 | •#0#` 1846 | 0 1847 | ``` 1848 | 1849 | #### How can I make k's output syntax more 'raw'? 1850 | 1851 | Start k with argument `-v`: 1852 | 1853 | ``` 1854 | (base) chris@chris-VirtualBox:~$ k 1855 | 2019-06-08 13:39:07 2core 4gb avx2 © shakti l2.0 test 1856 | `a`b!1 2 1857 | a:1 1858 | b:2 1859 | 1860 | (base) chris@chris-VirtualBox:~$ k -v 1861 | 2019-06-08 13:39:07 2core 4gb avx2 © shakti l2.0 test 1862 | `a`b!1 2 1863 | {a:1;b:2} 1864 | ``` 1865 | 1866 | ## `.z` namespace **.z** 1867 | 1868 | ### `.z.x` {.z.x} 1869 | 1870 | In the REPL, contains an empty list by default: 1871 | 1872 | ``` 1873 | (base) chris@chris-VirtualBox:~$ k 1874 | 2019-04-28 15:03:42 2core 1gb avx2 © shakti l2.0 test 1875 | .z.x 1876 | () 1877 | ``` 1878 | 1879 | But in a file, it lists the filename and any args after it. If `testarg.k` comprises the line `.z.x`: 1880 | 1881 | ``` 1882 | (base) chris@chris-VirtualBox:~$ k testarg.k not.a.real.file 1883 | 2019-04-28 15:03:42 2core 1gb avx2 © shakti l2.0 test 1884 | testarg.k 1885 | not.a.real.file 1886 | ``` 1887 | 1888 | Therefore, `.z.x` can be used to pass arguments to a k script. 1889 | 1890 | Also, note those arguments won't appear if we load `testarg.k` in another k process: 1891 | 1892 | ``` 1893 | (base) chris@chris-VirtualBox:~$ k 1894 | 2019-04-28 15:03:42 2core 1gb avx2 © shakti l2.0 test 1895 | \l testarg.k 1896 | () 1897 | ``` 1898 | 1899 | So you can also use `.z.x` to identify whether a script was run in its own right, or merely `\l`-ed into another k process. 1900 | 1901 | ### Secrets! 1902 | 1903 | In addition to `` `b64 ``, there's `` `b58 ``, [used](https://groups.google.com/d/msg/shaktidb/0yq21rHOacU/1wdeAGHFAAAJ) in the `` `bad `` implementation: 1904 | 1905 | ```kc 1906 | •`b58 "helloworld" 1907 | "6sBRWyteSSzHrs" 1908 | ``` 1909 | 1910 | Are all characters in the string in the [ASCII set](https://en.wikipedia.org/wiki/ASCII#Character_set)? 1911 | 1912 | ```kc 1913 | •`ascii @ "123" 1914 | 1 1915 | •`ascii @ "∞" 1916 | 0 1917 | ``` 1918 | 1919 | There is also a corresponding `` `utf8 `` verb. 1920 | -------------------------------------------------------------------------------- /static/js/jquery.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v3.4.1 | (c) JS Foundation and other contributors | jquery.org/license */ 2 | !function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],E=C.document,r=Object.getPrototypeOf,s=t.slice,g=t.concat,u=t.push,i=t.indexOf,n={},o=n.toString,v=n.hasOwnProperty,a=v.toString,l=a.call(Object),y={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},x=function(e){return null!=e&&e===e.window},c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.4.1",k=function(e,t){return new k.fn.init(e,t)},p=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;function d(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e)&&("array"===n||0===t||"number"==typeof t&&0+~]|"+M+")"+M+"*"),U=new RegExp(M+"|>"),X=new RegExp($),V=new RegExp("^"+I+"$"),G={ID:new RegExp("^#("+I+")"),CLASS:new RegExp("^\\.("+I+")"),TAG:new RegExp("^("+I+"|[*])"),ATTR:new RegExp("^"+W),PSEUDO:new RegExp("^"+$),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+R+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/HTML$/i,Q=/^(?:input|select|textarea|button)$/i,J=/^h\d$/i,K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ee=/[+~]/,te=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),ne=function(e,t,n){var r="0x"+t-65536;return r!=r||n?t:r<0?String.fromCharCode(r+65536):String.fromCharCode(r>>10|55296,1023&r|56320)},re=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ie=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},oe=function(){T()},ae=be(function(e){return!0===e.disabled&&"fieldset"===e.nodeName.toLowerCase()},{dir:"parentNode",next:"legend"});try{H.apply(t=O.call(m.childNodes),m.childNodes),t[m.childNodes.length].nodeType}catch(e){H={apply:t.length?function(e,t){L.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeType:9;if(n=n||[],"string"!=typeof t||!t||1!==p&&9!==p&&11!==p)return n;if(!r&&((e?e.ownerDocument||e:m)!==C&&T(e),e=e||C,E)){if(11!==p&&(u=Z.exec(t)))if(i=u[1]){if(9===p){if(!(a=e.getElementById(i)))return n;if(a.id===i)return n.push(a),n}else if(f&&(a=f.getElementById(i))&&y(e,a)&&a.id===i)return n.push(a),n}else{if(u[2])return H.apply(n,e.getElementsByTagName(t)),n;if((i=u[3])&&d.getElementsByClassName&&e.getElementsByClassName)return H.apply(n,e.getElementsByClassName(i)),n}if(d.qsa&&!A[t+" "]&&(!v||!v.test(t))&&(1!==p||"object"!==e.nodeName.toLowerCase())){if(c=t,f=e,1===p&&U.test(t)){(s=e.getAttribute("id"))?s=s.replace(re,ie):e.setAttribute("id",s=k),o=(l=h(t)).length;while(o--)l[o]="#"+s+" "+xe(l[o]);c=l.join(","),f=ee.test(t)&&ye(e.parentNode)||e}try{return H.apply(n,f.querySelectorAll(c)),n}catch(e){A(t,!0)}finally{s===k&&e.removeAttribute("id")}}}return g(t.replace(B,"$1"),e,n,r)}function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cacheLength&&delete e[r.shift()],e[t+" "]=n}}function le(e){return e[k]=!0,e}function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[r]]=t}function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function de(t){return function(e){return"input"===e.nodeName.toLowerCase()&&e.type===t}}function he(n){return function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&e.type===n}}function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e.disabled?"label"in e?"label"in e.parentNode?e.parentNode.disabled===t:e.disabled===t:e.isDisabled===t||e.isDisabled!==!t&&ae(e)===t:e.disabled===t:"label"in e&&e.disabled===t}}function ve(a){return le(function(o){return o=+o,le(function(e,t){var n,r=a([],e.length,o),i=r.length;while(i--)e[n=r[i]]&&(e[n]=!(t[n]=e[n]))})})}function ye(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}for(e in d=se.support={},i=se.isXML=function(e){var t=e.namespaceURI,n=(e.ownerDocument||e).documentElement;return!Y.test(t||n&&n.nodeName||"HTML")},T=se.setDocument=function(e){var t,n,r=e?e.ownerDocument||e:m;return r!==C&&9===r.nodeType&&r.documentElement&&(a=(C=r).documentElement,E=!i(C),m!==C&&(n=C.defaultView)&&n.top!==n&&(n.addEventListener?n.addEventListener("unload",oe,!1):n.attachEvent&&n.attachEvent("onunload",oe)),d.attributes=ce(function(e){return e.className="i",!e.getAttribute("className")}),d.getElementsByTagName=ce(function(e){return e.appendChild(C.createComment("")),!e.getElementsByTagName("*").length}),d.getElementsByClassName=K.test(C.getElementsByClassName),d.getById=ce(function(e){return a.appendChild(e).id=k,!C.getElementsByName||!C.getElementsByName(k).length}),d.getById?(b.filter.ID=function(e){var t=e.replace(te,ne);return function(e){return e.getAttribute("id")===t}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n=t.getElementById(e);return n?[n]:[]}}):(b.filter.ID=function(e){var n=e.replace(te,ne);return function(e){var t="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return t&&t.value===n}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),b.find.TAG=d.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):d.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},b.find.CLASS=d.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&E)return t.getElementsByClassName(e)},s=[],v=[],(d.qsa=K.test(C.querySelectorAll))&&(ce(function(e){a.appendChild(e).innerHTML="",e.querySelectorAll("[msallowcapture^='']").length&&v.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||v.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll("[id~="+k+"-]").length||v.push("~="),e.querySelectorAll(":checked").length||v.push(":checked"),e.querySelectorAll("a#"+k+"+*").length||v.push(".#.+[+~]")}),ce(function(e){e.innerHTML="";var t=C.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&v.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&v.push(":enabled",":disabled"),a.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&v.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),v.push(",.*:")})),(d.matchesSelector=K.test(c=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.msMatchesSelector))&&ce(function(e){d.disconnectedMatch=c.call(e,"*"),c.call(e,"[s!='']:x"),s.push("!=",$)}),v=v.length&&new RegExp(v.join("|")),s=s.length&&new RegExp(s.join("|")),t=K.test(a.compareDocumentPosition),y=t||K.test(a.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return l=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)===(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!d.sortDetached&&t.compareDocumentPosition(e)===n?e===C||e.ownerDocument===m&&y(m,e)?-1:t===C||t.ownerDocument===m&&y(m,t)?1:u?P(u,e)-P(u,t):0:4&n?-1:1)}:function(e,t){if(e===t)return l=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e===C?-1:t===C?1:i?-1:o?1:u?P(u,e)-P(u,t):0;if(i===o)return pe(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?pe(a[r],s[r]):a[r]===m?-1:s[r]===m?1:0}),C},se.matches=function(e,t){return se(e,null,null,t)},se.matchesSelector=function(e,t){if((e.ownerDocument||e)!==C&&T(e),d.matchesSelector&&E&&!A[t+" "]&&(!s||!s.test(t))&&(!v||!v.test(t)))try{var n=c.call(e,t);if(n||d.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(e){A(t,!0)}return 0":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(te,ne),e[3]=(e[3]||e[4]||e[5]||"").replace(te,ne),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||se.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&se.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return G.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=h(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(te,ne).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=p[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&p(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(n,r,i){return function(e){var t=se.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===i:"!="===r?t!==i:"^="===r?i&&0===t.indexOf(i):"*="===r?i&&-1:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function j(e,n,r){return m(n)?k.grep(e,function(e,t){return!!n.call(e,t,e)!==r}):n.nodeType?k.grep(e,function(e){return e===n!==r}):"string"!=typeof n?k.grep(e,function(e){return-1)[^>]*|#([\w-]+))$/;(k.fn.init=function(e,t,n){var r,i;if(!e)return this;if(n=n||q,"string"==typeof e){if(!(r="<"===e[0]&&">"===e[e.length-1]&&3<=e.length?[null,e,null]:L.exec(e))||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof k?t[0]:t,k.merge(this,k.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:E,!0)),D.test(r[1])&&k.isPlainObject(t))for(r in t)m(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return(i=E.getElementById(r[2]))&&(this[0]=i,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):m(e)?void 0!==n.ready?n.ready(e):e(k):k.makeArray(e,this)}).prototype=k.fn,q=k(E);var H=/^(?:parents|prev(?:Until|All))/,O={children:!0,contents:!0,next:!0,prev:!0};function P(e,t){while((e=e[t])&&1!==e.nodeType);return e}k.fn.extend({has:function(e){var t=k(e,this),n=t.length;return this.filter(function(){for(var e=0;e\x20\t\r\n\f]*)/i,he=/^$|^module$|\/(?:java|ecma)script/i,ge={option:[1,""],thead:[1,"","
    "],col:[2,"","
    "],tr:[2,"","
    "],td:[3,"","
    "],_default:[0,"",""]};function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&A(e,t)?k.merge([e],n):n}function ye(e,t){for(var n=0,r=e.length;nx",y.noCloneChecked=!!me.cloneNode(!0).lastChild.defaultValue;var Te=/^key/,Ce=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,Ee=/^([^.]*)(?:\.(.+)|)/;function ke(){return!0}function Se(){return!1}function Ne(e,t){return e===function(){try{return E.activeElement}catch(e){}}()==("focus"===t)}function Ae(e,t,n,r,i,o){var a,s;if("object"==typeof t){for(s in"string"!=typeof n&&(r=r||n,n=void 0),t)Ae(e,s,n,r,t[s],o);return e}if(null==r&&null==i?(i=n,r=n=void 0):null==i&&("string"==typeof n?(i=r,r=void 0):(i=r,r=n,n=void 0)),!1===i)i=Se;else if(!i)return e;return 1===o&&(a=i,(i=function(e){return k().off(e),a.apply(this,arguments)}).guid=a.guid||(a.guid=k.guid++)),e.each(function(){k.event.add(this,t,i,r,n)})}function De(e,i,o){o?(Q.set(e,i,!1),k.event.add(e,i,{namespace:!1,handler:function(e){var t,n,r=Q.get(this,i);if(1&e.isTrigger&&this[i]){if(r.length)(k.event.special[i]||{}).delegateType&&e.stopPropagation();else if(r=s.call(arguments),Q.set(this,i,r),t=o(this,i),this[i](),r!==(n=Q.get(this,i))||t?Q.set(this,i,!1):n={},r!==n)return e.stopImmediatePropagation(),e.preventDefault(),n.value}else r.length&&(Q.set(this,i,{value:k.event.trigger(k.extend(r[0],k.Event.prototype),r.slice(1),this)}),e.stopImmediatePropagation())}})):void 0===Q.get(e,i)&&k.event.add(e,i,ke)}k.event={global:{},add:function(t,e,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,v=Q.get(t);if(v){n.handler&&(n=(o=n).handler,i=o.selector),i&&k.find.matchesSelector(ie,i),n.guid||(n.guid=k.guid++),(u=v.events)||(u=v.events={}),(a=v.handle)||(a=v.handle=function(e){return"undefined"!=typeof k&&k.event.triggered!==e.type?k.event.dispatch.apply(t,arguments):void 0}),l=(e=(e||"").match(R)||[""]).length;while(l--)d=g=(s=Ee.exec(e[l])||[])[1],h=(s[2]||"").split(".").sort(),d&&(f=k.event.special[d]||{},d=(i?f.delegateType:f.bindType)||d,f=k.event.special[d]||{},c=k.extend({type:d,origType:g,data:r,handler:n,guid:n.guid,selector:i,needsContext:i&&k.expr.match.needsContext.test(i),namespace:h.join(".")},o),(p=u[d])||((p=u[d]=[]).delegateCount=0,f.setup&&!1!==f.setup.call(t,r,h,a)||t.addEventListener&&t.addEventListener(d,a)),f.add&&(f.add.call(t,c),c.handler.guid||(c.handler.guid=n.guid)),i?p.splice(p.delegateCount++,0,c):p.push(c),k.event.global[d]=!0)}},remove:function(e,t,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,v=Q.hasData(e)&&Q.get(e);if(v&&(u=v.events)){l=(t=(t||"").match(R)||[""]).length;while(l--)if(d=g=(s=Ee.exec(t[l])||[])[1],h=(s[2]||"").split(".").sort(),d){f=k.event.special[d]||{},p=u[d=(r?f.delegateType:f.bindType)||d]||[],s=s[2]&&new RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),a=o=p.length;while(o--)c=p[o],!i&&g!==c.origType||n&&n.guid!==c.guid||s&&!s.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(p.splice(o,1),c.selector&&p.delegateCount--,f.remove&&f.remove.call(e,c));a&&!p.length&&(f.teardown&&!1!==f.teardown.call(e,h,v.handle)||k.removeEvent(e,d,v.handle),delete u[d])}else for(d in u)k.event.remove(e,d+t[l],n,r,!0);k.isEmptyObject(u)&&Q.remove(e,"handle events")}},dispatch:function(e){var t,n,r,i,o,a,s=k.event.fix(e),u=new Array(arguments.length),l=(Q.get(this,"events")||{})[s.type]||[],c=k.event.special[s.type]||{};for(u[0]=s,t=1;t\x20\t\r\n\f]*)[^>]*)\/>/gi,qe=/\s*$/g;function Oe(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"tr")&&k(e).children("tbody")[0]||e}function Pe(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function Re(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Me(e,t){var n,r,i,o,a,s,u,l;if(1===t.nodeType){if(Q.hasData(e)&&(o=Q.access(e),a=Q.set(t,o),l=o.events))for(i in delete a.handle,a.events={},l)for(n=0,r=l[i].length;n")},clone:function(e,t,n){var r,i,o,a,s,u,l,c=e.cloneNode(!0),f=oe(e);if(!(y.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||k.isXMLDoc(e)))for(a=ve(c),r=0,i=(o=ve(e)).length;r").attr(n.scriptAttrs||{}).prop({charset:n.scriptCharset,src:n.url}).on("load error",i=function(e){r.remove(),i=null,e&&t("error"===e.type?404:200,e.type)}),E.head.appendChild(r[0])},abort:function(){i&&i()}}});var Vt,Gt=[],Yt=/(=)\?(?=&|$)|\?\?/;k.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Gt.pop()||k.expando+"_"+kt++;return this[e]=!0,e}}),k.ajaxPrefilter("json jsonp",function(e,t,n){var r,i,o,a=!1!==e.jsonp&&(Yt.test(e.url)?"url":"string"==typeof e.data&&0===(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Yt.test(e.data)&&"data");if(a||"jsonp"===e.dataTypes[0])return r=e.jsonpCallback=m(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,a?e[a]=e[a].replace(Yt,"$1"+r):!1!==e.jsonp&&(e.url+=(St.test(e.url)?"&":"?")+e.jsonp+"="+r),e.converters["script json"]=function(){return o||k.error(r+" was not called"),o[0]},e.dataTypes[0]="json",i=C[r],C[r]=function(){o=arguments},n.always(function(){void 0===i?k(C).removeProp(r):C[r]=i,e[r]&&(e.jsonpCallback=t.jsonpCallback,Gt.push(r)),o&&m(i)&&i(o[0]),o=i=void 0}),"script"}),y.createHTMLDocument=((Vt=E.implementation.createHTMLDocument("").body).innerHTML="
    ",2===Vt.childNodes.length),k.parseHTML=function(e,t,n){return"string"!=typeof e?[]:("boolean"==typeof t&&(n=t,t=!1),t||(y.createHTMLDocument?((r=(t=E.implementation.createHTMLDocument("")).createElement("base")).href=E.location.href,t.head.appendChild(r)):t=E),o=!n&&[],(i=D.exec(e))?[t.createElement(i[1])]:(i=we([e],t,o),o&&o.length&&k(o).remove(),k.merge([],i.childNodes)));var r,i,o},k.fn.load=function(e,t,n){var r,i,o,a=this,s=e.indexOf(" ");return-1").append(k.parseHTML(e)).find(r):e)}).always(n&&function(e,t){a.each(function(){n.apply(this,o||[e.responseText,t,e])})}),this},k.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){k.fn[t]=function(e){return this.on(t,e)}}),k.expr.pseudos.animated=function(t){return k.grep(k.timers,function(e){return t===e.elem}).length},k.offset={setOffset:function(e,t,n){var r,i,o,a,s,u,l=k.css(e,"position"),c=k(e),f={};"static"===l&&(e.style.position="relative"),s=c.offset(),o=k.css(e,"top"),u=k.css(e,"left"),("absolute"===l||"fixed"===l)&&-1<(o+u).indexOf("auto")?(a=(r=c.position()).top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(u)||0),m(t)&&(t=t.call(e,n,k.extend({},s))),null!=t.top&&(f.top=t.top-s.top+a),null!=t.left&&(f.left=t.left-s.left+i),"using"in t?t.using.call(e,f):c.css(f)}},k.fn.extend({offset:function(t){if(arguments.length)return void 0===t?this:this.each(function(e){k.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0},position:function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===k.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===k.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=k(e).offset()).top+=k.css(e,"borderTopWidth",!0),i.left+=k.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-k.css(r,"marginTop",!0),left:t.left-i.left-k.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===k.css(e,"position"))e=e.offsetParent;return e||ie})}}),k.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(t,i){var o="pageYOffset"===i;k.fn[t]=function(e){return _(this,function(e,t,n){var r;if(x(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r[i]:e[t];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e[t]=n},t,e,arguments.length)}}),k.each(["top","left"],function(e,n){k.cssHooks[n]=ze(y.pixelPosition,function(e,t){if(t)return t=_e(e,n),$e.test(t)?k(e).position()[n]+"px":t})}),k.each({Height:"height",Width:"width"},function(a,s){k.each({padding:"inner"+a,content:s,"":"outer"+a},function(r,o){k.fn[o]=function(e,t){var n=arguments.length&&(r||"boolean"!=typeof e),i=r||(!0===e||!0===t?"margin":"border");return _(this,function(e,t,n){var r;return x(e)?0===o.indexOf("outer")?e["inner"+a]:e.document.documentElement["client"+a]:9===e.nodeType?(r=e.documentElement,Math.max(e.body["scroll"+a],r["scroll"+a],e.body["offset"+a],r["offset"+a],r["client"+a])):void 0===n?k.css(e,t,i):k.style(e,t,n,i)},s,n?e:void 0,n)}})}),k.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,n){k.fn[n]=function(e,t){return 0