Skip to content

Instantly share code, notes, and snippets.

View obenjiro's full-sized avatar
🎯
Focusing

Alexey Okhrimenko obenjiro

🎯
Focusing
View GitHub Profile
window.onload = function(){
var iframeholder = document.getElementById('iframeholder');
var test = document.createElement('iframe');
var base = document.createElement('base');
base.setAttribute('target', '_parent')
test.onload = function(){
var y = (test.contentWindow || test.contentDocument);
if (y.document)y = y.document;
@obenjiro
obenjiro / getdistance.js
Last active January 12, 2019 22:42
Get distance between two coordinates
//get distance between two geo coordinates in kilometers
function distanceInKilometers(lat1, lon1, lat2, lon2) {
var rlat1 = Math.PI * lat1/180
var rlat2 = Math.PI * lat2/180
var rlon1 = Math.PI * lon1/180
var rlon2 = Math.PI * lon2/180
var theta = lon1-lon2
var rtheta = Math.PI * theta/180
var dist = Math.sin(rlat1) * Math.sin(rlat2) + Math.cos(rlat1) * Math.cos(rlat2) * Math.cos(rtheta);
dist = Math.acos(dist)
@obenjiro
obenjiro / shortestTemplateEngine.js
Last active August 29, 2015 13:59
Shortest template engine with JavaScript support and escaping
//this is data // noprotect
var context = {
keys:[0,1,2,3,null],
key:"<b>test</b>"
};
//this is template
function _template(){
for (var i=0; i < context.keys.length; i++) {
div.b;
@obenjiro
obenjiro / promises-dosnt-work.js
Last active August 29, 2015 14:00
promises isn't a magic tool, or simply - they don't work
var fs = require('vow-fs'),
vow = require('vow');
/**
* @param {String} path
* @returns {Promise} representing css
*/
module.exports = function processNode(path) {
return fs.isDir(path)
.then(function(isDir) {
@obenjiro
obenjiro / audio-with-controls.css
Created May 14, 2014 13:47
Prevent modern browsers from displaying `audio` without controls.
/**
* Prevent modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/
audio:not([controls]) { display: none; height: 0; }
@obenjiro
obenjiro / margincollapsed.css
Last active August 29, 2015 14:02
fight magin collapsing
/*
** http://jsfiddle.net/hEDEK/1/
**
** http://www.w3.org/TR/CSS21/box.html#collapsing-margins
*/
.child {
background: red;
width: 30px;
height: 30px;
margin: 10px;
@obenjiro
obenjiro / assert.js
Last active August 29, 2015 14:02
Assert that good for debugging
function Test(a, b){ // noprotect
assert(typeOf({a:a}, 'string'), function(m){ throw m });
assert(typeOf({b:b}, 'string'), function(m){ throw m });
var result = a + b;
result = null;
assert(notNullOrUndefined({result:result}), function(m){ throw m });
assert(equal({result:result}, 'ac'), function(m){ throw m });
return result;
@obenjiro
obenjiro / size-cover.css
Created August 10, 2014 18:29
Css only background-size: cover emulation
/* you can see it in action here http://jsbin.com/joxinizo/4/edit */
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.bgd {
@obenjiro
obenjiro / chunk.js
Last active August 29, 2015 14:06
Shortest Chunk implementation
//chunk
function chunk(arr, n) {
var result = [];
while(arr.length) {
result.push(arr.splice(0,n))
}
return result;
}
//chunk - obfuscated (72 chars)
@obenjiro
obenjiro / ftemplate.js
Created October 12, 2014 00:46
function template
function tag(tagName) {
return function() {
var args = arguments;
return function () {
return '<' + tagName + '>' + evalContent(args) + '</' + tagName + '>';
};
};
}
function evalContent(args) {