Skip to content

Instantly share code, notes, and snippets.

View vielhuber's full-sized avatar
🍐
❹❷

David Vielhuber vielhuber

🍐
❹❷
View GitHub Profile
@vielhuber
vielhuber / new_gist_file_0
Last active December 10, 2016 22:17
SocialFoo: Social Sharing share and get social count
// See github repo
@vielhuber
vielhuber / 1.sh
Last active July 12, 2017 23:34
Bitbucket: Remove folder from history
mkdir testrepo && cd testrepo
git clone git@bitbucket.org:vielhuber/testrepo.git .
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:11
localhost auto reload .css on mobile #js
$(document).ready(function() {
if( $(window).width() < 1200 && $('.localhost').length > 0 ) {
var path_1 = $('head link[href*="style.css"]').attr('href');
var path_2 = $('head link[href*="px2rem.css"]').attr('href');
setInterval(function() {
$('head link[href*="style.css"]').attr('href',path_1+'?rand='+(~~(Math.random()*999)+100));
$('head link[href*="px2rem.css"]').attr('href',path_2+'?rand='+(~~(Math.random()*999)+100));
}, 5000);
}
});
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:11
Google Maps: Auto center map for n given markers #js
// variant 2
var markers = []; // array with markers inside
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markers.length; i++) {
bounds.extend(markers[i].getPosition());
}
map.fitBounds(bounds);
// min/max zoom
if(map.getZoom() > 15) { map.setZoom(15); }
if(map.getZoom() < 3) { map.setZoom(3); }
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:11
debug current variables (live) inside function scope #js
var debug = ["var1", "var2", "var3"];
window.setInterval(function() {
$('#debug').remove();
$('body').append('<div id="debug" style="position:fixed;top:0;left:0;"></div>');
for(var item of debug) {
$('#debug').append(item+": "+eval(item)+"<br/>");
}
},1000);
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:11
closures #js
// When a function returns another function, the returning function holds its environment (in a closure)
// example #1
// here the function "inner" uses the variable var1 from outside its scope in its closure
var outer = function(var1) {
var inner = function(var2) {
return var1 + var2;
}
return inner;
}
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:11
semicolons (with or without syntax) #js
// js has auto semicolon insertion
BEFORE
var x = 1
var y = 2
AFTER
var x = 1;
var y = 2;
BEFORE
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:11
prototypes / prototypal inheritance #js
// every object has a property called "prototype" where you can add methods and/or other properties to it
// when you create other objects from this object the newly created object will inherit those properties
// without cloning but with referencing
/* newer way */
const cat = {
makeSound: function() {
console.log(this.sound);
}
@vielhuber
vielhuber / index.html
Last active September 22, 2017 23:11
print a PDF via a simple link #js
<a href="file.pdf" class="print">Print file!</a>
@vielhuber
vielhuber / file1.js
Last active September 22, 2017 23:11
call function from another file in jQuery Scope #js
"use strict";
(function ($) {
window.customFunction() = function() {
alert('FOO');
}
})(jQuery);