Skip to content

Instantly share code, notes, and snippets.

View kamilogorek's full-sized avatar

Kamil Ogórek kamilogorek

View GitHub Profile
@kamilogorek
kamilogorek / Pull url parameters
Created September 15, 2012 22:02
Pull url parameters
var parameters = (function (src) {
var params = {}, qryStr = src.split('?')[1];
qryStr && $.each(qryStr.split('&'), function (i, p) {
ps = p.replace(/\/$/, '').split('=');
var k = ps[0].replace(/^\?/, '');
params[k] = ps[1] || true;
});
return params;
})(location.search);
@kamilogorek
kamilogorek / Convert image to base64
Created April 15, 2013 10:13
Convert image to base64
with(document)with(i=querySelector('img'),createElement('canvas'))width=i.width,height=i.height,getContext('2d').drawImage(i,0,0),toDataURL()
@kamilogorek
kamilogorek / Carousel iteration logic
Created May 8, 2013 08:53
Carousel iteration logic
@kamilogorek
kamilogorek / Missed border on rotate
Created May 8, 2013 08:58
Missed border on rotate
selector {
@include backface-visibility(hidden);
@include perspective(1000);
}
@kamilogorek
kamilogorek / Characters encoding
Created May 8, 2013 09:00
Characters encoding
function encodeString(str) {
return str.replace(/\\n/g, '\n').replace(/\\'/g, '\'').replace(/\\"/g, '\"').replace(/\\\\/g, '\\');
}
@kamilogorek
kamilogorek / Equal cells width
Created May 8, 2013 09:16
Equal cells width within table columns
var cells = [];
var header = $('table').find('tr:first').find('th');
var rows = $('table').find('tr').not(':first');
header.each(function(i, val){
cells.push($(val).width());
});
rows.each(function(i, val) {
var _this = this;
@kamilogorek
kamilogorek / Navigation icons
Created May 8, 2013 09:19
Navigation icons with scalable sprite image
@mixin control-icon($dir, $size:76px) {
$icons-count: 4;
width: $size;
height: $size;
display: inline-block;
background: url(../img/ico-controls.png);
background-size: ($size*2) ($size*$icons-count);
background-repeat: no-repeat;
cursor: pointer;
@kamilogorek
kamilogorek / vim-tips
Created May 19, 2013 22:27
Useful vim commands
# Reindent whole file
gg=G
window.changeURL = function(photo) {
// not HTML history API browsers
if ($('html').hasClass('ie8') || $('html').hasClass('ie9')) {
window.location = photo.url;
}
else {
var stateObj = { video: 'xfactor' };
history.pushState(stateObj, photo.description, photo.url);
}
};
@kamilogorek
kamilogorek / renditions-sort.js
Last active December 22, 2015 06:58
Sorting renditions ratio
<script type="text/javascript">
var fapiResponse = {{ albums[0].photos[0].images | json_encode | raw }};
var renditions = [];
var ratios = {};
for (key in fapiResponse) {
renditions.push(key.split('_retina')[0]);
}
renditions.map(function(rendition, i) {