Skip to content

Instantly share code, notes, and snippets.

@malgorithms
Created April 28, 2014 19:19
Show Gist options
  • Save malgorithms/11381499 to your computer and use it in GitHub Desktop.
Save malgorithms/11381499 to your computer and use it in GitHub Desktop.
requirebin sketch
var xhr = require('xhr')
// can search by twitter, github, keybase, etc.
var QUERY = 'malgorithms';
// Add something to requirebin for printing results
var table = document.createElement("table");
document.body.appendChild(table);
//
// Look up a specific username on Keybase based on Keybase username
// and append all their info into our display table....
//
lookup_user = function(username){
xhr ('https://keybase.io/_/api/1.0/user/lookup.json?username='+username, function(err, resp, body) {
var data = JSON.parse(body);
console.log(data);
table.innerHTML += "<tr><td><h1><a href=\"https://keybase.io/"+username+"\">" + username + "</h1></td>"
+ "<td><pre style=\"overflow:scroll;height:200px;width:600px;font-size:0.8em;border:1px solid #ddd;\">"
+ JSON.stringify(data.them, null, 2) + "</pre></td></tr>";
});
}
//
// Find people on the site with a query on their username, twitter name, whatever.
//
search = function(q) {
xhr ('https://keybase.io/_/api/1.0/user/autocomplete.json?q='+q, function(err, resp, body) {
var data = JSON.parse(body);
// for each one, look up their identities
for (var i = 0; i < data.completions.length; i++) {
var u = data.completions[i];
var username = u.components.username.val;
lookup_user(username);
}
});
}
//
// do the search
//
search(QUERY);
require=function e(t,n,r){function o(s,u){if(!n[s]){if(!t[s]){var a="function"==typeof require&&require;if(!u&&a)return a(s,!0);if(i)return i(s,!0);throw Error("Cannot find module '"+s+"'")}var p=n[s]={exports:{}};t[s][0].call(p.exports,function(e){var n=t[s][1][e];return o(n?n:e)},p,p.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;r.length>s;s++)o(r[s]);return o}({o4EXtA:[function(e,t){function n(e,t){function n(){4===c.readyState&&o()}function o(){var e=null,n=c.statusCode=c.status,r=c.body=c.response||c.responseText||c.responseXML;if(0===n||n>=400&&600>n){var o=c.responseText||s[(c.status+"").charAt(0)];e=Error(o),e.statusCode=c.status}if(x)try{r=c.body=JSON.parse(r)}catch(i){}t(e,c,r)}function p(e){t(e,c)}"string"==typeof e&&(e={uri:e}),e=e||{},t=i(t);var c=e.xhr||null;!c&&e.cors?c=new a:c||(c=new u);var f=c.url=e.uri||e.url,l=c.method=e.method||"GET",d=e.body||e.data,h=c.headers=e.headers||{},y=!!e.sync,x=!1;return"json"in e&&(x=!0,h["Content-Type"]="application/json",d=JSON.stringify(e.json)),c.onreadystatechange=n,c.onload=o,c.onerror=p,c.onprogress=function(){},c.ontimeout=r,c.open(l,f,!y),e.cors&&(c.withCredentials=!0),y||(c.timeout="timeout"in e?e.timeout:5e3),c.setRequestHeader&&Object.keys(h).forEach(function(e){c.setRequestHeader(e,h[e])}),"responseType"in e&&(c.responseType=e.responseType),c.send(d),c}function r(){}var o=e("global/window"),i=e("once"),s={0:"Internal XMLHttpRequest Error",4:"4xx Client Error",5:"5xx Server Error"},u=o.XMLHttpRequest||r,a="withCredentials"in new u?o.XMLHttpRequest:o.XDomainRequest;t.exports=n},{"global/window":3,once:4}],xhr:[function(e,t){t.exports=e("o4EXtA")},{}],3:[function(e,t){(function(e){t.exports="undefined"!=typeof window?window:e!==void 0?e:{}}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t){function n(e){var t=!1;return function(){return t?void 0:(t=!0,e.apply(this,arguments))}}t.exports=n,n.proto=n(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return n(this)},configurable:!0})})},{}]},{},[]);var xhr=require("xhr"),QUERY="malgorithms",table=document.createElement("table");document.body.appendChild(table),lookup_user=function(e){xhr("https://keybase.io/_/api/1.0/user/lookup.json?username="+e,function(t,n,r){var o=JSON.parse(r);console.log(o),table.innerHTML+='<tr><td><h1><a href="https://keybase.io/'+e+'">'+e+"</h1></td>"+'<td><pre style="overflow:scroll;height:200px;width:600px;font-size:0.8em;border:1px solid #ddd;">'+JSON.stringify(o.them,null,2)+"</pre></td></tr>"})},search=function(e){xhr("https://keybase.io/_/api/1.0/user/autocomplete.json?q="+e,function(e,t,n){for(var r=JSON.parse(n),o=0;r.completions.length>o;o++){var i=r.completions[o],s=i.components.username.val;lookup_user(s)}})},search(QUERY);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"xhr": "1.5.0"
}
}
<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