Skip to content

Instantly share code, notes, and snippets.

View developit's full-sized avatar
🦊
write, the codes

Jason Miller developit

🦊
write, the codes
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type='text/javascript'>
/** Get the element with the given id */
function el(id) { return document.getElementById(id); }
window.onload = function() {
var geocoder = new google.maps.Geocoder(),
@developit
developit / nicetime.js
Last active November 27, 2018 20:57
nicetime.js
/** Returns a simple relative time string
* @example
* nicetime(new Date()-1e4) == 'Just now' // within the last minute
* nicetime(Date.now()-1e6) == '16m' // within the last hour
* nicetime(Date.now()-1e7) == '2h' // within the last hour
* nicetime('Dec 31, 2014') == '4d' // within the last 7 days
* nicetime('Dec 25, 2014') == 'Dec 25' // over 7 days ago gives a simple date
* nicetime('July 4, 2014') == 'Jul 4, 2014' // over half a year ago adds the year
*/
function nicetime(text) {
template=function(l){var q={},r={_default:function(b){return this[b.value&&b.value.splice?"each":"if"](b)},each:function(b){var h="",a,f=b.value;for(a in f)f.hasOwnProperty(a)&&(h+=l(b.content,f[a],void 0));return h},"if":function(b){return b.value?l(b.content,b.fields,b.overrides):""},"else":function(b){return b.value?"":l(b.content,b.fields,b.overrides)},unless:function(b){return this["else"](b)}};return l=function(b,h,a){var f=/\{\{\{?([#\/\:]?)([^ \{\}\|]+)(?: ([^\{\}\|]*?))?(?:\|([^\{\}]*?))?\}?\}\}/g,
g="",c,d,e,m,k=[];a={fields:h||{},overrides:a||q};a.path=(a.overrides.__path__?a.overrides.__path__+".":"")+a.overrides.__key__;for(f.lastIndex=0;d=f.exec(b);){0===k.length&&(g+=b.substring(c||0,f.lastIndex-d[0].length));c=d[1];if(!c||"#"!==c&&":"!==c&&"/"!==c){if(c=d[2],0===k.length)if(e=a.overrides[c]||h[c],null==e)g+=d[0];else{c="{"!==d[0].charAt(2);if(d[4])for(m=d[4].split("|"),d=0;d<m.length;d++)if(helpers.hasOwnProperty(m[d])){"html"===m[d]&&(c=!1);var n=m[d].split(":"),p=helpers[n[0]];"string"===
ty
@developit
developit / placeholder.html
Last active August 29, 2015 14:16
Placeholders for all
<input tpl="url" placeholder="http://">
<script src="placeholder.js"></script>
<script>[].map.call(document.querySelectorAll('[placeholder]'), placeholder);</script>
// Node style module writ in ES6 syntax:
export default foo = () => console.log(‘hi’)
// Unfortunately “literally” transpiles to this:
exports.default = function foo() {
return console.log(‘hi’)
}
// Which means this will fail:
var foo = require(‘./foo’)
@developit
developit / warsting.ino
Last active August 29, 2015 14:17 — forked from zsup/warsting.ino
/** Slay and pillage an unprotected network! ...oh, we can't do that?
* Ok, let's publish an event instead, to a backdrop of flashing lights
* and clashing of metal on metal.
*/
void vanquishOpenNetwork() {
if (!openNetworkCount || !strongest.rssi) {
return;
}
// allow the system to control the LED so we can see cloud connection progress
@developit
developit / atom-scrollbars.less
Created March 25, 2015 20:40
Lovely scrollbars for Atom.
atom-text-editor::shadow,
.tree-view-resizer {
::-webkit-scrollbar {
width: 2px;
height: 2px;
}
::-webkit-scrollbar-track {
background: #1a2127;
}
::-webkit-scrollbar-thumb {
@developit
developit / example.js
Last active December 25, 2018 22:01
mongoose-resource
import mongooseResource from '../lib/mongoose-resource';
import Foo from '../models/foo'; // a mongoose Model
export default mongooseResource('foo', Foo);
@developit
developit / custom-elements.js
Last active August 29, 2015 14:22
Custom Elements
(function() {
var elements = {};
function scan() {
[].forEach.call(
document.querySelectorAll('template[element]'),
function(el) {
var name = el.getAttribute('element'),
script = el.content.querySelector('script'),
js = script.innerHTML;
@developit
developit / set-immediate.js
Last active August 29, 2015 14:23
setImmediate multiple implementations
var setImmediate = (function(f, q, p, reg) {
q = [];
f = document.createElement('iframe');
f.style.cssText = 'position:absolute;top:-999em;left:0;width:1px;height:1px;';
document.body.appendChild(f);
function done() {
for (var i=0; i<q.length; i++) q[i]();
q.length = 0;
}
p = [