Skip to content

Instantly share code, notes, and snippets.

@czzarr
Created July 9, 2013 08:46
Show Gist options
  • Save czzarr/5955740 to your computer and use it in GitHub Desktop.
Save czzarr/5955740 to your computer and use it in GitHub Desktop.
requirebin sketch
// require something
console.log('beep baaaaap boop biiiiiip');
var url = require('url');
require=function(t,e,r){function o(r,a){if(!e[r]){if(!t[r]){var h="function"==typeof require&&require;if(!a&&h)return h(r,!0);if(n)return n(r,!0);throw Error("Cannot find module '"+r+"'")}var s=e[r]={exports:{}};t[r][0].call(s.exports,function(e){var n=t[r][1][e];return o(n?n:e)},s,s.exports)}return e[r].exports}for(var n="function"==typeof require&&require,a=0;r.length>a;a++)o(r[a]);return o}({url:[function(t,e){e.exports=t("nq9I9C")},{}],nq9I9C:[function(t,e,r){function o(t,e){for(var r=0,o=t.length;o>r;r++)if(t[r]==e)return r;return-1}function n(t,e,r){if(t&&"object"==typeof t&&t.href)return t;if("string"!=typeof t)throw new TypeError("Parameter 'url' must be a string, not "+typeof t);for(var n={},h=t,s=0,p=h.length;p>s&&-1!==o(l,h.charAt(s));s++);0!==s&&(h=h.substr(s));var v=f.exec(h);if(v){v=v[0];var w=v.toLowerCase();n.protocol=w,h=h.substr(v.length)}if(r||v||h.match(/^\/\/[^@\/]+@[^@\/]+/)){var I="//"===h.substr(0,2);!I||v&&A[v]||(h=h.substr(2),n.slashes=!0)}if(!A[v]&&(I||v&&!C[v])){var O=o(h,"@");if(-1!==O){for(var R=!0,s=0,p=b.length;p>s;s++){var U=o(h,b[s]);if(-1!==U&&O>U){R=!1;break}}R&&(n.auth=h.substr(0,O),h=h.substr(O+1))}for(var E=-1,s=0,p=g.length;p>s;s++){var U=o(h,g[s]);-1!==U&&(0>E||E>U)&&(E=U)}-1!==E?(n.host=h.substr(0,E),h=h.substr(E)):(n.host=h,h="");for(var z=i(n.host),Z=c(z),s=0,p=Z.length;p>s;s++){var k=Z[s];n[k]=z[k]}if(n.hostname=n.hostname||"",n.hostname.length>y)n.hostname="";else for(var T=n.hostname.split(/\./),s=0,p=T.length;p>s;s++){var $=T[s];if($&&!$.match(d)){for(var _="",L=0,P=$.length;P>L;L++)_+=$.charCodeAt(L)>127?"x":$[L];if(!_.match(d)){var M=T.slice(0,s),S=T.slice(s+1),B=$.match(j);B&&(M.push(B[1]),S.unshift(B[2])),S.length&&(h="/"+S.join(".")+h),n.hostname=M.join(".");break}}}n.hostname=n.hostname.toLowerCase();for(var D=n.hostname.split("."),F=[],s=0;D.length>s;++s){var G=D[s];F.push(G.match(/[^A-Za-z0-9_-]/)?"xn--"+u.encode(G):G)}n.hostname=F.join("."),n.host=(n.hostname||"")+(n.port?":"+n.port:""),n.href+=n.host}if(!q[w]){for(var s=0,p=m.length;p>s;s++){var H=m[s],J=encodeURIComponent(H);J===H&&(J=escape(H)),h=h.split(H).join(J)}for(var K=h.length,s=0,p=l.length;p>s;s++){var N=o(h,l[s]);-1!==N&&(K=Math.min(N,K))}h=h.substr(0,K)}var Q=o(h,"#");-1!==Q&&(n.hash=h.substr(Q),h=h.slice(0,Q));var V=o(h,"?");return-1!==V?(n.search=h.substr(V),n.query=h.substr(V+1),e&&(n.query=x.parse(n.query)),h=h.slice(0,V)):e&&(n.search="",n.query={}),h&&(n.pathname=h),C[v]&&n.hostname&&!n.pathname&&(n.pathname="/"),(n.pathname||n.search)&&(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=a(n),n}function a(t){"string"==typeof t&&(t=n(t));var e=t.auth||"";if(e){e=e.split("@").join("%40");for(var r=0,o=b.length;o>r;r++){var a=b[r];e=e.split(a).join(encodeURIComponent(a))}e+="@"}var h=t.protocol||"",s=void 0!==t.host?e+t.host:void 0!==t.hostname?e+t.hostname+(t.port?":"+t.port:""):!1,i=t.pathname||"",u=t.query&&("object"==typeof t.query&&c(t.query).length?x.stringify(t.query):"")||"",f=t.search||u&&"?"+u||"",p=t.hash||"";return h&&":"!==h.substr(-1)&&(h+=":"),t.slashes||(!h||C[h])&&s!==!1?(s="//"+(s||""),i&&"/"!==i.charAt(0)&&(i="/"+i)):s||(s=""),p&&"#"!==p.charAt(0)&&(p="#"+p),f&&"?"!==f.charAt(0)&&(f="?"+f),h+s+i+f+p}function h(t,e){return a(s(t,e))}function s(t,e){if(!t)return e;if(t=n(a(t),!1,!0),e=n(a(e),!1,!0),t.hash=e.hash,""===e.href)return t.href=a(t),t;if(e.slashes&&!e.protocol)return e.protocol=t.protocol,C[e.protocol]&&e.hostname&&!e.pathname&&(e.path=e.pathname="/"),e.href=a(e),e;if(e.protocol&&e.protocol!==t.protocol){if(!C[e.protocol])return e.href=a(e),e;if(t.protocol=e.protocol,!e.host&&!A[e.protocol]){for(var r=(e.pathname||"").split("/");r.length&&!(e.host=r.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==r[0]&&r.unshift(""),2>r.length&&r.unshift(""),e.pathname=r.join("/")}return t.pathname=e.pathname,t.search=e.search,t.query=e.query,t.host=e.host||"",t.auth=e.auth,t.hostname=e.hostname||e.host,t.port=e.port,(void 0!==t.pathname||void 0!==t.search)&&(t.path=(t.pathname?t.pathname:"")+(t.search?t.search:"")),t.slashes=t.slashes||e.slashes,t.href=a(t),t}var h=t.pathname&&"/"===t.pathname.charAt(0),s=void 0!==e.host||e.pathname&&"/"===e.pathname.charAt(0),i=s||h||t.host&&e.pathname,u=i,c=t.pathname&&t.pathname.split("/")||[],r=e.pathname&&e.pathname.split("/")||[],f=t.protocol&&!C[t.protocol];if(f&&(delete t.hostname,delete t.port,t.host&&(""===c[0]?c[0]=t.host:c.unshift(t.host)),delete t.host,e.protocol&&(delete e.hostname,delete e.port,e.host&&(""===r[0]?r[0]=e.host:r.unshift(e.host)),delete e.host),i=i&&(""===r[0]||""===c[0])),s)t.host=e.host||""===e.host?e.host:t.host,t.hostname=e.hostname||""===e.hostname?e.hostname:t.hostname,t.search=e.search,t.query=e.query,c=r;else if(r.length)c||(c=[]),c.pop(),c=c.concat(r),t.search=e.search,t.query=e.query;else if("search"in e){if(f){t.hostname=t.host=c.shift();var p=t.host&&o(t.host,"@")>0?t.host.split("@"):!1;p&&(t.auth=p.shift(),t.host=t.hostname=p.shift())}return t.search=e.search,t.query=e.query,(void 0!==t.pathname||void 0!==t.search)&&(t.path=(t.pathname?t.pathname:"")+(t.search?t.search:"")),t.href=a(t),t}if(!c.length)return delete t.pathname,t.search?delete t.path:t.path="/"+t.search,t.href=a(t),t;for(var l=c.slice(-1)[0],v=(t.host||e.host)&&("."===l||".."===l)||""===l,m=0,g=c.length;g>=0;g--)l=c[g],"."==l?c.splice(g,1):".."===l?(c.splice(g,1),m++):m&&(c.splice(g,1),m--);if(!i&&!u)for(;m--;m)c.unshift("..");!i||""===c[0]||c[0]&&"/"===c[0].charAt(0)||c.unshift(""),v&&"/"!==c.join("/").substr(-1)&&c.push("");var b=""===c[0]||c[0]&&"/"===c[0].charAt(0);if(f){t.hostname=t.host=b?"":c.length?c.shift():"";var p=t.host&&o(t.host,"@")>0?t.host.split("@"):!1;p&&(t.auth=p.shift(),t.host=t.hostname=p.shift())}return i=i||t.host&&c.length,i&&!b&&c.unshift(""),t.pathname=c.join("/"),(void 0!==t.pathname||void 0!==t.search)&&(t.path=(t.pathname?t.pathname:"")+(t.search?t.search:"")),t.auth=e.auth||t.auth,t.slashes=t.slashes||e.slashes,t.href=a(t),t}function i(t){var e={},r=p.exec(t);return r&&(r=r[0],e.port=r.substr(1),t=t.substr(0,t.length-r.length)),t&&(e.hostname=t),e}var u={encode:function(t){return t}};r.parse=n,r.resolve=h,r.resolveObject=s,r.format=a;var c=Object.keys||function c(t){if(t!==Object(t))throw new TypeError("Invalid object");var e=[];for(var r in t)t.hasOwnProperty(r)&&(e[e.length]=r);return e},f=/^([a-z0-9.+-]+:)/i,p=/:[0-9]+$/,l=["<",">",'"',"`"," ","\r","\n"," "],v=["{","}","|","\\","^","~","[","]","`"].concat(l),m=["'"],g=["%","/","?",";","#"].concat(v).concat(m),b=["/","@","?","#"].concat(l),y=255,d=/^[a-zA-Z0-9][a-z0-9A-Z_-]{0,62}$/,j=/^([a-zA-Z0-9][a-z0-9A-Z_-]{0,62})(.*)$/,q={javascript:!0,"javascript:":!0},A={javascript:!0,"javascript:":!0},C={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},x=t("querystring")},{querystring:1}],1:[function(t,e,r){function o(t,e){if(0==t[e].length)return t[e]={};var r={};for(var o in t[e])r[o]=t[e][o];return t[e]=r,r}function n(t,e,r,a){var h=t.shift();if(h){var s=e[r]=e[r]||[];"]"==h?g(s)?""!=a&&s.push(a):"object"==typeof s?s[b(s).length]=a:s=e[r]=[e[r],a]:~m(h,"]")?(h=h.substr(0,h.length-1),!j.test(h)&&g(s)&&(s=o(e,r)),n(t,s,h,a)):(!j.test(h)&&g(s)&&(s=o(e,r)),n(t,s,h,a))}else g(e[r])?e[r].push(a):e[r]="object"==typeof e[r]?a:e[r]===void 0?a:[e[r],a]}function a(t,e,r){if(~m(e,"]")){var o=e.split("[");o.length,n(o,t,"base",r)}else{if(!j.test(e)&&g(t.base)){var a={};for(var h in t.base)a[h]=t.base[h];t.base=a}f(t.base,e,r)}return t}function h(t){var e={base:{}};return y(b(t),function(r){a(e,r,t[r])}),e.base}function s(t){return d((t+"").split("&"),function(t,e){var r=m(e,"="),o=p(e),n=e.substr(0,o||r),h=e.substr(o||r,e.length),h=h.substr(m(h,"=")+1,h.length);return""==n&&(n=e,h=""),""==n?t:a(t,l(n),l(h))},{base:{}}).base}function i(t,e){if(!e)throw new TypeError("stringify expects an object");return e+"="+encodeURIComponent(t)}function u(t,e){var r=[];if(!e)throw new TypeError("stringify expects an object");for(var o=0;t.length>o;o++)r.push(q(t[o],e+"["+o+"]"));return r.join("&")}function c(t,e){for(var r,o=[],n=b(t),a=0,h=n.length;h>a;++a)r=n[a],null==t[r]?o.push(encodeURIComponent(r)+"="):o.push(q(t[r],e?e+"["+encodeURIComponent(r)+"]":encodeURIComponent(r)));return o.join("&")}function f(t,e,r){var o=t[e];void 0===o?t[e]=r:g(o)?o.push(r):t[e]=[o,r]}function p(t){for(var e,r,o=t.length,n=0;o>n;++n)if(r=t[n],"]"==r&&(e=!1),"["==r&&(e=!0),"="==r&&!e)return n}function l(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(e){return t}}var v=Object.prototype.toString,m="function"==typeof Array.prototype.indexOf?function(t,e){return t.indexOf(e)}:function(t,e){for(var r=0;t.length>r;r++)if(t[r]===e)return r;return-1},g=Array.isArray||function(t){return"[object Array]"==v.call(t)},b=Object.keys||function(t){var e=[];for(var r in t)e.push(r);return e},y="function"==typeof Array.prototype.forEach?function(t,e){return t.forEach(e)}:function(t,e){for(var r=0;t.length>r;r++)e(t[r])},d=function(t,e,r){if("function"==typeof t.reduce)return t.reduce(e,r);for(var o=r,n=0;t.length>n;n++)o=e(o,t[n]);return o},j=/^[0-9]+$/;r.parse=function(t){return null==t||""==t?{}:"object"==typeof t?h(t):s(t)};var q=r.stringify=function(t,e){return g(t)?u(t,e):"[object Object]"==v.call(t)?c(t,e):"string"==typeof t?i(t,e):e+"="+encodeURIComponent(t+"")}},{}]},{},[]),console.log("beep baaaaap boop biiiiiip");var url=require("url");
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment