raykooyenga's notebooks

  • endpoint express - /raykooyenga/endpoint-express
    Last edited 6 years ago
    var rkExpress = require("@runkit/runkit/express-endpoint/1.0.0") // Just provide the exports object to the rkExpress helper var app = rkExpress(module.exports) var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false })); app.get("/", (req, res) => res.send("hello")) app.get("/:name", (req, res) => { res.send(`hi ${req.params.name}!`) }) app.post("/echo-form", (req, res) => { var formData = Object.keys(req.body).map( k => `${k}: ${req.body[k]}` ) res.type("text/plain") res.send(formData.join("\n")) })
  • fab test - /raykooyenga/fab-test
    Last edited 6 years ago
    module.exports = ( function source() { fab = function() { var stack = []; return collect.apply( this, arguments ); function collect( fn ) { var args = stack.slice.call( arguments ), length = args.length; if ( !length ) fn = fab.self; if ( length > 1 ) fn = fab( fn ).apply( this, args.slice( 1 ) ); fn = ( fn && fab[ fn.constructor.name ] || fab.body )( fn ); stack.unshift( fn ); return reduce(); } function reduce() { if ( stack[ 0 ].length ) return collect; if ( stack.length == 1 ) return stack.shift(); if ( stack[ 1 ] == fab.self ) { var app = stack[ 0 ]; stack.splice( 1, 1 ); reduce(); stack.unshift( app ); } stack.splice( 0, 2, stack[ 1 ]( stack[ 0 ] ) ); return reduce(); } } fab.body = function( obj ) { return function() { var out = this({ body: obj }); if ( out ) out(); } } fab.map = function( fn ) { return function( app ) { return function() { var out = this; return app.call( function listener( obj ) { if ( obj ) arguments[ 0 ] = fn.call( obj, obj ); out = out.apply( this, arguments ); return listener; }) } } } fab.tap = function( fn ) { return function( app ) { return function() { fn(); return app.call( this ); } } } fab.echo = function() { return this; } fab.method = ( function( names ) { for ( var name; name = names.pop(); ) method[ name ] = method( name ); return method; function method() { var methods = {}, len = arguments.length; for ( var i = 0; i < len; i++ ) { methods[ arguments[ i ] ] = true; } return function( hit ) { return function( miss ) { return function() { var out = this; return function( head ) { var app = head.method in methods ? hit : miss; app = app.call( out ); if ( app ) app = app( head ); return app; } } } } } })( [ "GET", "POST", "PUT", "DELETE" ] ) fab.path = function( pattern ) { var proto = Array.prototype, match = { String: function( url ) { if ( path.indexOf( pattern ) ) return false; url.pathname = url.pathname.substr( pattern.length ); return true; }, RegExp: function( url ) { var match = false; url.pathname = url.pathname.replace( pattern, function() { match = true; var capture = proto.slice.call( arguments, 1, -2 ); if ( !url.capture ) url.capture = capture; else proto.push.apply( url.capture, capture ); return ""; }); return match; } }[ pattern.constructor.name ]; return function( hit ) { return function( miss ) { return function() { var out = this; return function( head ) { var app = match( head.url ) ? hit : miss; app = app.call( out ); if ( app ) app = app( head ); return app; } } } } } fab.capture = fab.map( function( obj ) { return { body: obj.url ? obj.url.capture : [] }; })( fab.echo ) fab.status = function( code ) { code = +code; return function() { var out = this({ status: code }); if ( out ) out(); } } fab.stringify = fab.map( function( obj ) { var body = obj.body; if ( typeof body != "string" ) obj.body = JSON.stringify( body ); return obj; }) fab.tmpl = function( source ) { var fn; source.call( function( obj ) { fn = new Function( "var p=[];p.push('" + obj.body .replace( /[\r\t\n]/g, " " ) .replace( /'(?=[^%]*%>)/g, "\t" ) .split( "'" ).join( "\\'" ) .split( "\t" ).join( "'" ) .replace( /<%=(.+?)%>/g, "',$1,'" ) .split( "<%" ).join( "');" ) .split( "%>" ).join( "p.push('" ) + "');return p.join('');" ); }); return function( app ) { // TODO: fn might not be defined yet for async app = fab.map( function( obj ) { obj.body = fn.call( obj.body ); return obj; })( app ); return function() { return app.call( this ) }; } }; fab.nodejs = function( app ) { var url = require( "url" ); return function() { var request = arguments[ 0 ], response = arguments[ 1 ], headers = undefined, status = 200, _encoding = "ascii", inbound = app.call( listener ); if ( inbound ) { inbound = inbound({ method: request.method, headers: request.headers, url: url.parse( request.url ) }); } if ( inbound ) { request .addListener( "end", inbound ) .addListener( "data", function( body ) { if ( inbound ) inbound = inbound({ body: body }); }) } function listener( obj ) { if ( arguments.length ) { if ( "status" in obj ) { status = obj.status; } if ( "headers" in obj ) { if ( headers ) process.mixin( headers, obj.headers ); else headers = obj.headers; } if ( "_encoding" in obj ) { _encoding = obj._encoding; } if ( "body" in obj ) { if ( headers !== false ) { response.writeHead( status, headers || {} ); headers = false; } response.write( obj.body, _encoding ); } return listener; } else { if ( headers !== false ) { response.writeHead( status, headers || {} ); headers = false; } response.end(); } } } } fab.nodejs.contentLength = fab.map( function( obj ) { if ( typeof obj.body == "string" ) { ( obj.headers = obj.headers || {} ) [ "content-length" ] = process._byteLength( obj.body ); } return obj; }) fab.nodejs.fs = function( app ) { var fs = require( "fs" ); return function() { var out = this; return app.call( function( obj ) { var path = obj.body; fs.readFile( path, "utf8", function( err, data ) { out({ body: data || "File not found: " + path, status: err ? 404 : 200 })(); }); }) } } fab.nodejs.http = function( loc ) { loc = require( "url" ).parse( loc ) var client = require( "http" ) .createClient( loc.port || 80, loc.hostname ); return function() { var out = this; return function( head ) { head.headers.host = loc.hostname; client .request( head.method, loc.pathname + head.url.pathname + ( head.url.search || "" ), head.headers ) .addListener( "response", function( response ) { back({ status: response.statusCode, headers: response.headers }); response .addListener( "data", function( chunk ) { out({ body: chunk }); }) .addListener( "end", out ) .setBodyEncoding( "utf8" ); }) .close(); } } } fab.self = function( obj ){ return obj }; fab.Function = fab.self; fab.RegExp = fab.path; fab.Number = fab.status; for ( var name in fab ) { var app = fab[ name ]; for ( name in app ) { fab[ name ] = app[ name ]; } } fab.toString = function(){ return "(" + source + ")()" }; return fab; })() /*fab = require( "//rawgit.com/technoweenie/fab/master/index.js" );*/ module.exports = fab ( /\// ) ( /1/ ) // simple ( function() { this({ body: "Hello, world!" })(); }) ( /2/ ) // streaming ( function() { this ({ body: "Hello, " }) ({ body: "world!" }) (); }) ( /3/ ) // complete, jsgi-style ( function() { this({ status: 200, headers: { "content-type": "text/plain" }, body: "Hello, world!" })(); }) ( /4/ ) // asynchronous ( function() { var out = this({ body: "Hello, " }); setTimeout( function() { out({ body: "world!" })(); }, 2000 ); }) ( /5/ ) // request-specific ( function() { var out = this; return function( head ) { var body = "Hello, " + head.url.pathname.substr(1) + "!"; out({ body: body })(); } }) ( /6/ ) // incoming body listener ( function() { var out = this, length = 0; return function listener( obj ) { if ( !obj ) out({ body: "Hello, " + length + " bytes!" })(); else if ( obj.body ) { length += process._byteLength( obj.body.toString() ); } return listener; } }) ( /7/ ) // fab-style ( fab.tmpl, "Hello, <%= this[ 0 ] %>!" ) ( /^\/(\w+)$/ ) ( fab.capture ) ( [ "world" ] ) ( 404 ) ( 404 );
  • quine not? - /raykooyenga/quine-not
    Last edited 7 years ago
    var q = (exports = function () { process.nextTick(function () { console.log("var q = (exports = " + exports.toString() + ")();"); }); })();
  • fetch-notebook-stored-file - /raykooyenga/fetch-notebook-stored-file
    Last edited 7 years ago
    //var file = require("notebook")("raykooyenga/hw-json/1.0.0"); deprecated var file=require('@runkit/raykooyenga/hw-json/1.0.0');
  • hw.json - /raykooyenga/hw-json
    Last edited 7 years ago
    module.exports = ` { magic: "nassh-prefs", version: 1, nassh: { profile-ids: [ { id: "af12", json: { description: "crosh", username: "user", hostname: ">crosh", port: "", argstr: "'shell'" } }, { id: "08a8", json: { description: "ray@urled.me rayremote1", username: "ray", hostname: "urled.me", port: "", relay-options: "" } } ] }, hterm: { default: { background-color: "rgba(0, 0, 0, 0.83)", background-image: "https://d39dlwgeopmdw0.cloudfront.net/img/Home.jpg", background-size: "100% 100% cover", background-position: "top left", cursor-blink: true, cursor-color: "rgba(17, 238, 255, 0.5)", color-palette-overrides: null, copy-on-select: false, clear-selection-after-copy: false, font-family: "", font-size: "20", foreground-color: "rgba(240, 240, 240, 0.94)", max-string-sequence: "1000003", mouse-paste-button: 3, page-keys-scroll: true, receive-encoding: "raw", scroll-on-output: true, send-encoding: "raw", user-css-text: " @import url(https://fonts.googleapis.com/css?family=AndaleMono); @import url(https://fonts.googleapis.com/css?family=Anonymous+Pro|Droid+Sans+Mono|Inconsolata|Overpass+Mono|Oxygen+Mono|PT+Mono|Roboto+Mono|Share+Tech+Mono|Source+Code+Pro|Space+Mono|Ubuntu+Mono); html,body {color:#1ff042;} x-screen{ // color: #1ff042; display: block; /* font-family: 'AndaleMono', monospace; font-family: 'Space Mono', monospace; font-family: 'Oxygen Mono', monospace; font-family: 'Anonymous Pro', monospace; font-family: 'Overpass Mono', monospace; font-family: 'Share Tech Mono', monospace; font-family: 'PT Mono', monospace; font-family: 'Ubuntu Mono', monospace; font-family: 'Inconsolata', monospace; font-family: 'Roboto Mono', monospace; font-family: 'Source Code Pro', monospace; font-family: 'Droid Sans Mono', monospace; */ font-family: 'Droid Sans Mono', monospace; font-weight: bold; // text-transform: uppercase; font-size: 0.9em; letter-spacing: 0.15em; white-space: pre-wrap; text-shadow: 0 0 2px rgba(31, 240, 66, 0.75); text-shadow:0 0 2px aqua; line-height: 1; } /* sexy */ x-screen{ background: #000 -webkit-radial-gradient(#64404d, #000000); background: #000 radial-gradient(#64404d, #000000); -webkit-transform: translateZ(0.15px) scale(100%) translateX(-94%) translateY(-100%); transform: translateZ(0.15px) scale(100%) translateX(-94%) translateY(-100%); z-index:0 height: 100%; color: #ff0078; box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.5), inset 0 0 10px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.1), 0 -1px 2px 2px rgba(0, 0, 0, 0.25), 0 1px 1px 1px rgba(255, 255, 255, 0.4); border-color: 2px solid #ff00ba; text-shadow: 3px 3px 1px rgba(255, 0, 120, 0.6); text-shadow: 0 0 15px rgba(0, 186, 255, 0.6); } x-row:hover{ transform: scale(1.3,1.3); background-color:rgba(0,0,0,0.13); text-shadow:0 0 4px rgba(31,240,66,0.75); } x-screen{ box-shadow: 1px 1px 1px rgba(31, 240, 66, 0.65), -1px -1px 1px rgba(31, 240, 66, 0.65), 1px -1px 1px rgba(31, 240, 66, 0.65), -1px 1px 1px rgba(31, 240, 66, 0.65); -webkit-animation: cursor-blink 1.25s steps(1) infinite; } x-row{ -webkit-animation: text-glow 2s ease-in-out infinite alternate; animation: text-glow 2s ease-in-out infinite alternate; color: #f00078; border-color: 2px solid #ff50d0; text-shadow: 2px 2px 1px rgba(255, 0, 120, 0.6); } @-webkit-keyframes bugfix { from { position: relative; } to { position: relative; } } @-webkit-keyframes button-glow { 0% { background-color: #f00078; border-color: #ff00ba; box-shadow: 0 0 15px rgba(0, 186, 255, 0.2), inset 0 0 5px rgba(0, 186, 255, 0.1), 0 2px 0 #000; } 100% { background-color: #f91a8a; border-color: #ff50d0; box-shadow: 0 0 30px rgba(0, 186, 255, 0.6), inset 0 0 10px rgba(0, 186, 255, 0.4), 0 2px 0 #000; } } @keyframes button-glow { 0% { background-color: #f00078; border-color: #ff00ba; box-shadow: 0 0 15px rgba(0, 186, 255, 0.2), inset 0 0 5px rgba(0, 186, 255, 0.1), 0 2px 0 #000; } 100% { background-color: #f91a8a; border-color: #ff50d0; box-shadow: 0 0 30px rgba(0, 186, 255, 0.6), inset 0 0 10px rgba(0, 186, 255, 0.4), 0 2px 0 #000; } } @-webkit-keyframes text-glow { 0% { color: #ff00ba; text-shadow: 0 0 15px rgba(0, 186, 255, 0.2); } 100% { color: #ff50d0; text-shadow: 0 0 30px rgba(0, 186, 255, 0.6); } } @keyframes text-glow { 0% { color: #ff00ba; text-shadow: 0 0 15px rgba(0, 186, 255, 0.2); } 100% { color: #ff50d0; text-shadow: 0 0 30px rgba(0, 186, 255, 0.6); } } /* end sexy */ /*optional darker backing*/ /* x-screen{ min-width:100vw; max-width:100vw; width:auto; height:100vh; background: linear-gradient( rgba(0, 5, 32, 0.65), rgba(0, 5, 32, 0.65) ), url('https://d1gw0xfshbos9l.cloudfront.net/static/images/carson.jpg') no-repeat center center fixed; -webkit-background: -webkit-background-size: 100% auto; -blink-background-size: 100% auto; background-size: 100% auto; } */" } } `