Skip to content

Instantly share code, notes, and snippets.

View obenjiro's full-sized avatar
🎯
Focusing

Alexey Okhrimenko obenjiro

🎯
Focusing
View GitHub Profile
@obenjiro
obenjiro / scrollTopBugFix.js
Created March 7, 2014 10:02
bugfix for browsers with weird scrollTop restoration after refresh policy
// weird Chrome, Y.browser bug with position been saved
// browser jumps to hash id and then jumps to last scrolled position
$(window).on('load', function(){
setTimeout(function(){
var initialUrlHash = getInitialUrlHash();
if (initialUrlHash) {
document.body.scrollTop = $(initialUrlHash).offset().top;
}
},0);
});
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 / 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) {