Skip to content

Instantly share code, notes, and snippets.

View vielhuber's full-sized avatar
🍐
❹❷

David Vielhuber vielhuber

🍐
❹❷
View GitHub Profile
@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 ); })
@vielhuber
vielhuber / index.php
Last active September 22, 2017 23:12
SQL fetch variable #php #sql
// without prepared statements
$sql->query("SELECT ID FROM table WHERE condition1 = 'foo' AND condition2 = 2")->fetch_object()->ID;
// with prepared statements
$query = $sql->prepare("SELECT ID FROM table WHERE condition1 = ? AND condition2 = ?");
$query->bind_param("si", $a='foo', $b=2);
$query->execute();
$query->get_result()->fetch_object()->count;
@vielhuber
vielhuber / index.html
Last active September 22, 2017 23:12
german quotes Anführungszeichen #html
„Text“
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:12
count from start value to specific value with jQuerys animate function #js
new_count = 500;
cur_count = $('.count').text();
$({count_num: cur_count}).animate({count_num: overall_count}, {
duration: 1000,
easing:'linear',
step: function() {
$('.count').text(Math.floor(this.count_num));
},
complete: function() {
$('.count').text(this.count_num);
@vielhuber
vielhuber / index.php
Last active September 22, 2017 23:12
DB fetch row #php #sql
<?php
$sql->query("SELECT * FROM table WHERE ID = 1;")->fetch_assoc();
?>
@vielhuber
vielhuber / index.php
Last active September 22, 2017 23:12
DB fetch multiple #php #sql
<?php
// this is only possible with mysqlnd (native driver)
$result = $sql->query("SELECT * FROM table WHERE condition = 1;")->fetch_all(MYSQLI_ASSOC);
// this is always possible
$result = array(); $result_db = $sql->query("SELECT * FROM table WHERE condition = 1;"); while($row = $result_db->fetch_assoc()) { $result[] = $row; }
?>
@vielhuber
vielhuber / index.php
Last active September 22, 2017 23:12
Meta redirect through HTML in x seconds #php #html
echo '<meta http-equiv="refresh" content="0; url=\''.$url.'\'">';
@vielhuber
vielhuber / index.php
Last active September 22, 2017 23:12
Joomla get URL/link from menu id #joomla
JRoute::_('index.php?Itemid=106')
@vielhuber
vielhuber / index.html
Last active September 22, 2017 23:12
slider #js #css #html
<div class="slider">
<div class="item">
<ul>
<li style="background-image:url('http://lorempixel.com/g/640/480/cats/');"></li>
<li style="background-image:url('http://lorempixel.com/g/640/480/cats/');"></li>
<li style="background-image:url('http://lorempixel.com/g/640/480/cats/');"></li>
<li style="background-image:url('http://lorempixel.com/g/640/480/cats/');"></li>
<li style="background-image:url('http://lorempixel.com/g/640/480/cats/');"></li>
<li style="background-image:url('http://lorempixel.com/g/640/480/cats/');"></li>
<li style="background-image:url('http://lorempixel.com/g/640/480/cats/');"></li>
@vielhuber
vielhuber / index.php
Last active November 21, 2019 15:48
allow uploading other filetypes (e.g. vcf vcard, svg) #wordpress
<?php
add_filter( 'upload_mimes', function( $existing_mimes = [] )
{
$existing_mimes['vcf'] = 'text/x-vcard';
$existing_mimes['svg'] = 'image/svg+xml';
$existing_mimes['ico'] = 'image/x-icon';
return $existing_mimes;
});
// this is needed for all wordpress versions >= 4.7.1
// this is also needed for svg files without proper mime types (without the <?xml tag inside!)