Skip to content

Instantly share code, notes, and snippets.

View vielhuber's full-sized avatar
🍐
❹❷

David Vielhuber vielhuber

🍐
❹❷
View GitHub Profile
@vielhuber
vielhuber / Bootstrap.php
Last active September 22, 2017 23:12
disable variants for sold out articles #shopware
<?php
class Shopware_Plugins_Frontend_GlassesStockVariant_Bootstrap extends Shopware_Components_Plugin_Bootstrap {
public function getCapabilities() {
return array(
'install' => true,
'update' => true,
'enable' => true
);
}
@vielhuber
vielhuber / index.php
Last active September 22, 2017 23:12
DB fetch var #joomla
$db->setQuery($db->getQuery(true)->select("ID")->from($db->quoteName('#__table'))->where($db->quoteName('ID').' = '.$db->quote(1)))->loadObject()->ID
@vielhuber
vielhuber / index.php
Last active May 5, 2023 07:27
zip files on the fly #php
$tmpfile = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($tmpfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = [[$_SERVER['DOCUMENT_ROOT'].'/.../foo.txt','foo.txt'],[$_SERVER['DOCUMENT_ROOT'].'/.../bar.txt','bar.txt']];
foreach($files as $files__value) {
$zip->addFile(($_SERVER['DOCUMENT_ROOT'].'/.../'.$files__value[0]), $files__value[1]);
}
$zip->close();
@vielhuber
vielhuber / style.css
Last active December 16, 2020 11:32
vertical centering / align #css
/*
method 1: flexbox
- you don't special rules for the child here
- height of parent should be defined via min-height
*/
.parent {
display: flex;
flex-direction: column;
justify-content: center;
align-items:center;
@vielhuber
vielhuber / index.html
Last active September 22, 2017 23:12
slideshow #js #css #html
<div class="slideshow" data-speed="1000" data-speed-manual="100" data-delay="10000" data-delay-init="1500" animation="fade" easing="easeInSine">
<ul>
<li style="display:block;background-image:url('http://lorempixel.com/g/640/480/cats/');"></li>
<li style="display:none;background-image:url('http://lorempixel.com/g/640/480/people/');"></li>
<li style="display:none;background-image:url('http://lorempixel.com/g/640/480/nature/');"></li>
</ul>
</div>
<!-- enable this to turbo up sizing (no clipping on page load -->
<script type="text/javascript">
@vielhuber
vielhuber / script.js
Last active September 22, 2017 23:12
generate a random number between x and y being integers #js
~~(Math.random()*(y-x+1))+x
@vielhuber
vielhuber / script.js
Last active June 22, 2021 21:55
remove a specific item from an array #js
let a = ['foo', 'bar', null, 'baz'];
delete a[1]; // ['foo', undefined, null, 'baz']
a = a.filter(v => typeof v !== 'undefined'); // ['foo', null, 'baz']
a = a.filter(v => v != 'baz'); // ['foo', null]
@vielhuber
vielhuber / script.js
Last active January 8, 2023 23:25
date #js
// current date
new Date();
// date from string
new Date('2016-01-01');
// date from string (german)
let str = '01.01.2016';
new Date(str.substring(6,10)+'-'+str.substring(3,5)+'-'+str.substring(0,2));
@vielhuber
vielhuber / script.js
Last active March 15, 2018 17:13
default parameter values in functions (pre/post es6) #js
// es6
function foo(a,b = 2) {
alert(a+b);
}
// pre es6
function foo(a,b) {
b = b || 2;
alert(a+b);
}
@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; });