Skip to content

Instantly share code, notes, and snippets.

@funkjedi
Last active October 2, 2018 19:09
Show Gist options
  • Save funkjedi/5514641 to your computer and use it in GitHub Desktop.
Save funkjedi/5514641 to your computer and use it in GitHub Desktop.
Code snippets from blog
errorOccurred = lastErrorOccurred = new Date().getTime();
_back = function(h) {
if (_backOk) {
if (_backCallback) {
_backCallback();
_backCallback = null;
}
var hh = parseInt(h);
var m = $.browser.netscape ? 2 : $.browser.msie ? 3 : 7;
if (hh > m) {
errorOccurred = new Date().getTime();
console.log("hh: "+ hh +", m: "+ m +", delta: "+ (errorOccurred - lastErrorOccurred));
lastErrorOccurred = errorOccurred;
alert(PP.msg.man.bac);
}
}
};
_back = function(h) {
if (_backOk) {
if (_backCallback) {
_backCallback();
_backCallback = null;
}
var hh = parseInt(h);
var m = $.browser.netscape ? 2 : $.browser.msie ? 3 : 7;
if (hh > m) alert(PP.msg.man.bac);
}
};
runHistory = function() {
$.historyInit(_back);
z = $.browser.netscape ? 2 : $.browser.msie ? 4 : 8;
for (var j = z; j >= 0; j--) $.historyLoad(j);
_SetTimeout(function() {
_backOk = 1
},
3000);
};
if (!Ext.supports.Touch || Ext.is.Blackberry) {
Ext.apply(this.eventNames, {
start: 'mousedown',
//move: 'mousemove',
end: 'mouseup'
});
}
Ext.NonTouchCompatibleScrollPanel = Ext.extend(Ext.Panel, {
scroll: 'vertical',
initComponent: function() {
Ext.get(document.body).on('mousemove', function(evt, div, el) {
if (!this.scroller) {
return;
}
if (this.scroller.offsetBoundary.top === 0) {
this.scroller.updateBoundary();
}
var maxOffset = this.scroller.offsetBoundary[1] - 400;
var bottom = parseInt(Ext.get(document.body).getStyle('height')) - 15;
if (evt.xy[1] > bottom && this.scroller.offset.y >= maxOffset) {
var offset = -1 * this.scroller.offset.y + 10;
this.scroller.scrollTo({
x: 0,
y: offset
});
} else if (evt.xy[1] < 60 && this.scroller.offset.y <= 0) {
this.scroller.scrollTo({
x: 0,
y: (-1 * this.scroller.offset.y) - 10
});
}
}, this, {element:'el'});
Ext.NonTouchCompatibleScrollPanel.superclass.initComponent.call(this, arguments);
}
});
<?php
// Search parameters
$lat = 45.411572;
$lng = -75.698194;
$radius = 25;
// Constants related to the surface of the Earth
$earths_radius = 6371;
$surface_distance_coeffient = 111.320;
// Spherical Law of Cosines
$distance_formula = "$earths_radius * ACOS( SIN(RADIANS(latitude)) * SIN(RADIANS($lat)) + COS(RADIANS(longitude - $lng)) * COS(RADIANS(latitude)) * COS(RADIANS($lat)) )";
// Create a bounding box to reduce the scope of our search
$lng_b1 = $lng - $radius / abs(cos(deg2rad($lat)) * $surface_distance_coeffient);
$lng_b2 = $lng + $radius / abs(cos(deg2rad($lat)) * $surface_distance_coeffient);
$lat_b1 = $lat - $radius / $surface_distance_coeffient;
$lat_b2 = $lat + $radius / $surface_distance_coeffient;
// Construct our sql statement
$sql = <<<SQL
SELECT *, ($distance_formula) AS distance
FROM listings
WHERE (latitude BETWEEN $lat_b1 AND $lat_b2) AND (longitude BETWEEN $lng_b1 AND $lng_b2)
HAVING distance < $radius
ORDER BY distance ASC
SQL;
<div class="container">
{{#grouped_each 3 books}}
<div class="row">
{{#each this }}
<div class="span4 book" data-isbn="{{ isbn }}">
<strong>{{ name }}</strong>
</div>
{{/each}}
</div>
{{/grouped_each}}
</div>
Handlebars.registerHelper('grouped_each', function(every, context, options) {
var out = "", subcontext = [], i;
if (context && context.length > 0) {
for (i = 0; i < context.length; i++) {
if (i > 0 && i % every === 0) {
out += options.fn(subcontext);
subcontext = [];
}
subcontext.push(context[i]);
}
out += options.fn(subcontext);
}
return out;
});
@jcoyle37
Copy link

jcoyle37 commented Oct 2, 2018

After wrestling with templates for hours, getting extremely frustrated, your code was a breath of fresh air. Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment