Skip to content

Instantly share code, notes, and snippets.

@donavon
Last active August 29, 2015 14:20
Show Gist options
  • Save donavon/e536e38a3fe0226b143b to your computer and use it in GitHub Desktop.
Save donavon/e536e38a3fe0226b143b to your computer and use it in GitHub Desktop.
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var console = require("consoleit");
var compareVersions = require("compare-versions");
function isBricked(appVersion, brickedVersion) {
return brickedVersion && compareVersions(appVersion, brickedVersion) < 1;
}
var brickedVersion = "1.7.4";
var appVersion = "1.7.4"; // Get this from package.json
var showBrick = isBricked(appVersion, brickedVersion);
console.log("The app will " + (showBrick ? "" : "NOT ") + "show as bricked");
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";function serializeObject(obj){var str;try{str=" "+JSON.stringify(obj)}catch(ex){str=""}return"Object"+str}module.exports=function substituteStrings(args){var results=[];var sub=args[0];if(typeof sub==="string"&&sub.match(/%[idsf]/)){args.shift();while(args.length&&/%[idsf]/.test(sub)){var pos=/%[idsf]/.exec(sub).index;var match=args.shift();var replacement;switch(sub[pos+1]){case"i":case"d":replacement=parseInt(match,10);break;case"s":replacement=match;break;case"f":replacement=parseFloat(match);break}sub=sub.substr(0,pos)+replacement+sub.substr(pos+2)}results.push(sub)}args.forEach(function(arg){if(typeof arg==="object"){results.push(serializeObject(arg))}else{results.push(arg)}});return results.join(" ")}},{}],2:[function(require,module,exports){var inserted={};module.exports=function(css,options){if(inserted[css])return;inserted[css]=true;var elem=document.createElement("style");elem.setAttribute("type","text/css");if("textContent"in elem){elem.textContent=css}else{elem.styleSheet.cssText=css}var head=document.getElementsByTagName("head")[0];if(options&&options.prepend){head.insertBefore(elem,head.childNodes[0])}else{head.appendChild(elem)}}},{}],consoleit:[function(require,module,exports){"use strict";var insertCss=require("insert-css");var substituteStrings=require("./substituteStrings");var element;var elementName;var console=function(name){elementName=name;return console};function actuallyAppendChild(el){element.appendChild(el);element.scrollTop=element.scrollHeight}function insertStyle(){var css="pre.consoleit {margin:0 0 0 20px; position:relative}"+"pre.consoleit:before {position:absolute; left:-15px}"+'pre.consoleit.info:before {content:"\\25CF"; color:#4072B4}'+'pre.consoleit.warn:before {content:"\\25B2"; color:#ffcc09}'+'pre.consoleit.error:before {content:"\\25A0"; color:#ff0909}';insertCss(css)}function determineElement(el){insertStyle();element=elementName?document.getElementById(elementName):document.body;appendChild=actuallyAppendChild;appendChild(el)}var appendChild=determineElement;function outputCommon(method){var args=Array.prototype.slice.call(arguments,1);var text=substituteStrings(args)||" ";var el=document.createElement("pre");el.className="consoleit "+method;el.textContent=text;appendChild(el)}["log","info","warn","error"].forEach(function(method){console[method]=outputCommon.bind(null,method)});module.exports=console},{"./substituteStrings":1,"insert-css":2}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({"compare-versions":[function(require,module,exports){(function(root,factory){if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.returnExports=factory()}})(this,function(){var patchPattern=/-([\w-.]+)/;function split(v){var temp=v.split(".");var arr=temp.splice(0,2);arr.push(temp.join("."));return arr}return function compareVersions(v1,v2){var s1=split(v1);var s2=split(v2);for(var i=0;i<3;i++){var n1=parseInt(s1[i]||0);var n2=parseInt(s2[i]||0);if(n1>n2)return 1;if(n2>n1)return-1;if(i===2&&(s1[i]+s2[i]).indexOf("-")>-1){var p1=(patchPattern.exec(s1[i])||[""])[0];var p2=(patchPattern.exec(s2[i])||[""])[0];if(p1==="")return 1;if(p2==="")return-1;if(p1>p2)return 1;if(p2>p1)return-1}}return 0}})},{}]},{},[]);var console=require("consoleit");var compareVersions=require("compare-versions");function isBricked(appVersion,brickedVersion){return brickedVersion&&compareVersions(appVersion,brickedVersion)<1}var brickedVersion="1.7.4";var appVersion="1.7.4";var showBrick=isBricked(appVersion,brickedVersion);console.log("The app will "+(showBrick?"":"NOT ")+"show as bricked");
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"consoleit": "0.0.6",
"compare-versions": "1.1.0"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment