Skip to content

Instantly share code, notes, and snippets.

@klipstein
Created July 8, 2016 13:05
Show Gist options
  • Save klipstein/b666abeb356214bd7ade5a100b56f086 to your computer and use it in GitHub Desktop.
Save klipstein/b666abeb356214bd7ade5a100b56f086 to your computer and use it in GitHub Desktop.
requirebin sketch
var uniqid = require('uniqid');
document.body.innerHTML = uniqid();
setTimeout(function(){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){},{}],2:[function(require,module,exports){exports.endianness=function(){return"LE"};exports.hostname=function(){if(typeof location!=="undefined"){return location.hostname}else return""};exports.loadavg=function(){return[]};exports.uptime=function(){return 0};exports.freemem=function(){return Number.MAX_VALUE};exports.totalmem=function(){return Number.MAX_VALUE};exports.cpus=function(){return[]};exports.type=function(){return"Browser"};exports.release=function(){if(typeof navigator!=="undefined"){return navigator.appVersion}return""};exports.networkInterfaces=exports.getNetworkInterfaces=function(){return{}};exports.arch=function(){return"javascript"};exports.platform=function(){return"browser"};exports.tmpdir=exports.tmpDir=function(){return"/tmp"};exports.EOL="\n"},{}],3:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canMutationObserver=typeof window!=="undefined"&&window.MutationObserver;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}var queue=[];if(canMutationObserver){var hiddenDiv=document.createElement("div");var observer=new MutationObserver(function(){var queueList=queue.slice();queue.length=0;queueList.forEach(function(fn){fn()})});observer.observe(hiddenDiv,{attributes:true});return function nextTick(fn){if(!queue.length){hiddenDiv.setAttribute("yes","no")}queue.push(fn)}}if(canPost){window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],4:[function(require,module,exports){(function(global){var os=require("os");var lib={};function parallel(tasks,done){var results=[];var errs=[];var length=0;var doneLength=0;function doneIt(ix,err,result){if(err){errs[ix]=err}else{results[ix]=result}doneLength+=1;if(doneLength>=length){done(errs.length>0?errs:errs,results)}}Object.keys(tasks).forEach(function(key){length+=1;var task=tasks[key];(global.setImmediate||global.setTimeout)(function(){task(doneIt.bind(null,key),1)})})}lib.networkInterfaces=function(){var ifaces=os.networkInterfaces();var allAddresses={};Object.keys(ifaces).forEach(function(iface){addresses={};var hasAddresses=false;ifaces[iface].forEach(function(address){if(!address.internal){addresses[(address.family||"").toLowerCase()]=address.address;hasAddresses=true;if(address.mac){addresses.mac=address.mac}}});if(hasAddresses){allAddresses[iface]=addresses}});return allAddresses};var _getMacAddress;switch(os.platform()){case"win32":_getMacAddress=require("./lib/windows.js");break;case"linux":_getMacAddress=require("./lib/linux.js");break;case"darwin":case"sunos":_getMacAddress=require("./lib/unix.js");break;default:console.warn("node-macaddress: Unkown os.platform(), defaulting to `unix'.");_getMacAddress=require("./lib/unix.js");break}lib.one=function(iface,callback){if(typeof iface==="function"){callback=iface;var ifaces=lib.networkInterfaces();var alleged=["eth0","eth1","en0","en1"];iface=Object.keys(ifaces)[0];for(var i=0;i<alleged.length;i++){if(ifaces[alleged[i]]){iface=alleged[i];break}}if(!ifaces[iface]){if(typeof callback==="function"){callback("no interfaces found",null)}return null}if(ifaces[iface].mac){if(typeof callback==="function"){callback(null,ifaces[iface].mac)}return ifaces[iface].mac}}if(typeof callback==="function"){_getMacAddress(iface,callback)}return null};lib.all=function(callback){var ifaces=lib.networkInterfaces();var resolve={};Object.keys(ifaces).forEach(function(iface){if(!ifaces[iface].mac){resolve[iface]=_getMacAddress.bind(null,iface)}});if(Object.keys(resolve).length===0){if(typeof callback==="function"){callback(null,ifaces)}return ifaces}parallel(resolve,function(err,result){Object.keys(result).forEach(function(iface){ifaces[iface].mac=result[iface]});if(typeof callback==="function"){callback(null,ifaces)}});return null};module.exports=lib}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./lib/linux.js":5,"./lib/unix.js":6,"./lib/windows.js":7,os:2}],5:[function(require,module,exports){var exec=require("child_process").exec;module.exports=function(iface,callback){exec("cat /sys/class/net/"+iface+"/address",function(err,out){if(err){callback(err,null);return}callback(null,out.trim().toLowerCase())})}},{child_process:1}],6:[function(require,module,exports){var exec=require("child_process").exec;module.exports=function(iface,callback){exec("ifconfig "+iface,function(err,out){if(err){callback(err,null);return}var match=/[a-f0-9]{2}(:[a-f0-9]{2}){5}/.exec(out.toLowerCase());if(!match){callback("did not find a mac address",null);return}callback(null,match[0].toLowerCase())})}},{child_process:1}],7:[function(require,module,exports){var exec=require("child_process").exec;var regexRegex=/[-\/\\^$*+?.()|[\]{}]/g;function escape(string){return string.replace(regexRegex,"\\$&")}module.exports=function(iface,callback){exec("ipconfig /all",function(err,out){if(err){callback(err,null);return}var match=new RegExp(escape(iface)).exec(out);if(!match){callback("did not find interface in `ipconfig /all`",null);return}out=out.substring(match.index+iface.length);match=/[A-Fa-f0-9]{2}(\-[A-Fa-f0-9]{2}){5}/.exec(out);if(!match){callback("did not find a mac address",null);return}callback(null,match[0].toLowerCase().replace(/\-/g,":"))})}},{child_process:1}],uniqid:[function(require,module,exports){(function(process){var pid=process.pid.toString(36),address;require("macaddress").one(function(error,macAddress){if(error)throw error;address=macAddress});while(!address);address=parseInt(address.replace(/\:|\D+/gi,"")).toString(36);module.exports=function(prefix){return(prefix||"")+address+pid+now().toString(36)};module.exports.process=function(prefix){return(prefix||"")+pid+now().toString(36)};module.exports.time=function(prefix){return(prefix||"")+now().toString(36)};function now(){var time=(new Date).getTime();var last=now.last||time;return now.last=time>last?time:last+1}}).call(this,require("_process"))},{_process:3,macaddress:4}]},{},[]);var uniqid=require("uniqid");document.body.innerHTML=uniqid()},0);
{
"name": "create-unique-id",
"version": "1.0.0",
"dependencies": {
"uniqid": "3.0.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