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 / 0_index.html
Last active August 21, 2024 13:16
vertical centering / align #css
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5, minimum-scale=1" />
<title>.</title>
<style>
*
{
box-sizing: border-box;
@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 November 14, 2024 15:29
generate a random number between x and y being integers #js
~~(Math.random()*(y-x+1))+x
Explanation:
- Math.random(): [0, 1)
- Math.random()*(y-x+1): [0, y-x+1)
- (Math.random()*(y-x+1))+x: [x, y+1)
- ~~(Math.random()*(y-x+1))+x: [x, y]
@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; });