Skip to content

Instantly share code, notes, and snippets.

View vielhuber's full-sized avatar
🍐
❹❷

David Vielhuber vielhuber

🍐
❹❷
View GitHub Profile
@vielhuber
vielhuber / pastejacking-1.sh
Last active September 22, 2017 23:11
PasteJacking #js
rm -rf \r\n
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:11
make intersection / cut between arrays of arrays #js
var arr = [
['a', 'b', 'c', 'd', 'a'],
['c', 'd', 'e'],
['b', 'c', 'd', 'd']
];
var arr = arr.shift().reduce(function(res, v) {
if (res.indexOf(v) === -1 && arr.every(function(a) {
return a.indexOf(v) !== -1;
})) res.push(v);
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:11
idle timeout function #js
var idleTime = 0;
$(document).ready(function () {
var idleInterval = setInterval(timerIncrement, 60000); // 1 minute
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).scroll(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
@vielhuber
vielhuber / index.php
Last active September 22, 2017 23:11
parallax effect #js
<div class="parallax" data-ratio="<?php $s = getimagesize("parallax.jpg"); echo round($s[0]/$s[1],2); ?>" data-speed="0.5" >
<span>test</span>
<img class="i" src="parallax.jpg" alt="" />
</div>
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:11
hide option in select element #js
/* hiding option elements with $('option').hide() does not work with IE, instead use this strategy */
var og = $('select').html();
$('select').change(function() {
$('select').html(og);
$('select option[myfilter=1]').remove();
});
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:12
sorting out duplicates in array #js
array = $.grep(array, function(v, k){ return $.inArray(v ,array) === k; });
@vielhuber
vielhuber / index.html
Last active September 22, 2017 23:12
textarea Maxlength crossbrowser #js
<span class="counter">150</span>
<textarea data-maxlength="150"></textarea>
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:12
ajaxize complete page with pushState #js
See github
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:12
when both animation and post/load are finished, execute function #js
$.when(
$('.box').animate({ opacity: 0 }, 1000, 'linear'),
$.post( $(this).closest('form').attr('action'), $(this).closest('form').serialize() )
).then(function () {
alert('both finished');
});
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:12
synchronize two loads and execute function after both finished with Deferred #js
var d1 = new $.Deferred();
var d2 = new $.Deferred();
$.when(d1, d2).then(function(r1, r2) {
console.log(r1);
console.log(r2);
alert('done');
});
$.get(href1, function(data) { d1.resolve( data ); })
$.get(href2, function(data) { d2.resolve( data ); })