Skip to content

Instantly share code, notes, and snippets.

@amark
amark / imports
Created August 21, 2013 07:46
Require that works everywhere, tested on all browsers IE6 or more modern and Node! Weighs 2KB. Save this file as "imports.js", then include it as a script tag for the browser, and use as below for your own code - Node works automatically. `;module.exports=require('./path/to/imports')('hello',function(mods){ /* your code here */ return 'Hello Wor…
(function(){var m=m||{},g=m,a={id:"imports"};g.opts=g.opts||{};g.d={l:{},n:{},a:{},w:{}};g.z="undefined"!==typeof GLOBAL&&GLOBAL.global&&GLOBAL.process&&GLOBAL.process.env&&GLOBAL.process.pid&&GLOBAL.process.execPath?function(){global.node=g.node=!0;module.exports=function(b,e,d){var c=a.r(b,e,d);c.s=g.y||(module.parent||{}).filename;a.e(a.d(c.d,c.s,{}),function(b,e){c.a[b]=a.n(e=require(g.y=e))?void 0:e});return c.i(c.a)}}:function(){var b=window;g.page=!0;b.root=g;b.console=b.console||{log:function(a){return a}};
location.local="file:"===location.protocol?"http:":"";b.__dirname="";b.module={exports:b.exports={}};a.l=function(a,b){var c="script",f=document.createElement(c);module.sync=null!==f.onload&&f.readyState?1:0;var h=2166136261,g=a.length,k=b,q=/=\?/,r=window.setTimeout,n,m,p=function(a){document.body&&(a=a||n)&&f&&document.body[a]?document.body[m=a](f):r(p,0)};if(q.test(a)){for(;g--;)h=16777619*h^a.charCodeAt(g);window[c+=0>h?-h:h]=function(){k.apply(k,arguments);delete window[c]};a=a.replace(q,"="+
@amark
amark / is
Last active December 21, 2015 11:19
a more english way to check type with theory.
;module.exports=require('theory')
('is', function(a){
return function(what){
return {
binary: a.bi.is(what)
,number: a.num.is(what)
,text: a.text.is(what)
,list: a.list.is(what)
,object: a.obj.is(what)
,func: a.fns.is(what)
@amark
amark / allDone.js
Created November 16, 2014 10:26
parallel async JS micro library in 25LOC
var allDone = function(done){ // takes a callback that will be called as callback(errors, values) when all async parallel operations are finished.
var context = {task: {}, data: {}};
context.end = function(e,v){ return done(e,v), done = function(){} }; // this can always be called if you want to terminate early, like because an error.
context.add = function(fn, id){ // if the async operation you are doing replies with standard fn(err, value) then just pass in a string ID, else your own callback and ID.
context.task[id = (typeof fn == 'string')? fn : id] = false;
var next = function(err, val){
context.task[id] = true; // good, we're done with this one!
if(err){ (context.err = context.err || {})[id] = err } // record errors.
context.data[id] = val; // record the values.
for(var i in c.task){ if(c.task.hasOwnProperty(i)){ // loop over the async task checker
@amark
amark / teams.html
Last active November 10, 2015 20:40
<html>
<body>
<script src="http://rawgit.com/amark/gun/master/gun.js"></script>
<script>
localStorage.clear(); // reset the data!
Gun.chain.joinTeam = function(team){ // extends gun to make bidirectional pointing easy!
var member = this;
member.val(function(theMember){
team.set(theMember); // link the member to the team.
});
<html>
<body>
<script src="http://rawgit.com/amark/gun/master/gun.js"></script>
<script>
localStorage.clear();
var gun = Gun();
// define the snake team!
var snakes = gun.get('team/snakes').put({team: "snakes"});
@amark
amark / gun3import.js
Created August 25, 2016 19:55
This takes the internal functionality of `.put` and RIPS IT OUT, separating it from the chaining API and the event listeners that cause problems - but NOTE, this does not support the chaining API or async behavior! Plus it has a couple extra hidden gems like auto-Array-to-Object conversion and UUID hinting.
function importGUN3 (data, options){
options = options || {};
options.prefix = 'gun/';
if(options.arrays !== false){
options.arrays = true;
data = array2object(data);
}
var drift = options.state || Gun.time.now();
var ctx = {}, at = {};
Gun.ify(data, function(env, cb, map){
@amark
amark / gist:6bd085ec7222e0294f7bc6162a61644c
Created October 1, 2016 21:33
for Paul. Thoughts? I can't get indenting to work though
/**
* Created by Paul on 10/1/2016.
*/
var fs = require('fs');
var nodePath = require('path');
var banner = "//console.log(\"!!!!!!!!!!!!!!!! WARNING THIS IS GUN 0.5 !!!!!!!!!!!!!!!!!!!!!!\");\n";
var polyCover = "\n\t/* UNBUILD */\n";
var immediateStart = "\n;(function(){\n";
var reqStart = "\n;require(function(module){\n";
<div id="be">
<div id="view"></div>
<video id="video" style="display: none; height:300px;width:320px" autoplay="true"></video>
<canvas id="canvas" style="display: none; height:240px; width:320px"></canvas>
<textarea id="debug" style="height:240px;width:420px;"></textarea>
<div id="audio"></div>
</div>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="gun.js"></script>
<script>
@amark
amark / pm.html
Last active April 21, 2018 08:46
<h1>PM</h1>
<form id="sign">
<input id="alias" placeholder="username">
<input id="pass" type="password" placeholder="passphrase">
<input id="in" type="submit" value="sign in">
<input id="up" type="button" value="sign up">
</form>
<ul id="chats"></ul>
@amark
amark / li.html
Last active April 30, 2023 05:25
<html><body>
<style>
html, body {
background: rgb(245, 245, 245);
margin: 0;
padding: 0;
}
div {
position: relative;
overflow: hidden;