This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assuming 5 fixed digits | |
function dehydrateFloat(f){ | |
return Math.floor(f.toFixed(5)*100000).toString(36); | |
} | |
function hydrateFloat(dryf){ | |
return (parseInt(dryf,36)/100000).toFixed(5); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Init | |
google.maps.event.addDomListener(window, 'load', function() { | |
var map_container = document.getElementById("map-canvas"); | |
var minZoomLevel = 2; | |
var startZoomLevel = 8; | |
var map = new google.maps.Map(map_container,{ | |
center: new google.maps.LatLng(-34.397, 150.644), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
server_name youtube.flerovio.dev; | |
location @404 { | |
return 302 /sq$request_uri; | |
} | |
error_page 404 = @404; | |
location ~ /sq/(.+) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create pub-sub functionality | |
Backbone.pubSub = _.extend({}, Backbone.Events); | |
// view one needs to trigger an event in view2 | |
View1 = Backbone.View.extend({ | |
triggerView2Event : function() { | |
Backbone.pubSub.trigger('view2event', { 'some' : 'data' } ); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncLoadCSS (css_href) { | |
var css_link = function () { | |
var h = document.getElementsByTagName('head')[0] | |
var l = document.createElement('link') | |
l.rel = 'stylesheet' | |
l.href = css_href | |
h.parentNode.insertBefore(l, h) | |
}, RAF = requestAnimationFrame || mozRequestAnimationFrame | |
|| webkitRequestAnimationFrame || msRequestAnimationFrame | |
if (RAF) RAF(css_link); else window.addEventListener('load', css_link) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate a middleware | |
function middleware(mw){ | |
return function(fn){ | |
fn = (typeof fn == "function") ? fn : window[fn]; | |
return function(){ | |
var args = arguments || []; | |
if(false !== mw.apply(this,args)) fn.apply(this,args); | |
}; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
mongoose.Model.seed = function(entities) { | |
var promise = new mongoose.Promise; | |
this.create(entities, function(err) { | |
if(err) { promise.reject(err); } | |
else { promise.resolve(); } | |
}); | |
return promise; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function($) { | |
/* | |
* jQuery Observer pattern | |
* inspired by @addyosmani 's code | |
* see: http://addyosmani.com/resources/essentialjsdesignpatterns/book/#highlighter_506612 | |
*/ | |
var topics = []; | |
function getTopic(id) { | |
var callbacks; | |
topic = id && topics[id]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace.views.MyWizard = Backbone.Views.extend({ | |
initialize: function() { | |
_.bindAll(this, 'render', 'wizardMethod'); | |
} | |
render: function() { | |
this.wizardMethod(); | |
return this; | |
}, |
OlderNewer