Skip to content

Instantly share code, notes, and snippets.

View hadl's full-sized avatar

Andreas Bibow hadl

View GitHub Profile
@hadl
hadl / microtime_diff.php
Last active March 5, 2021 04:05
PHP Microtime Diff -- Calculate a precise time difference
<?php
/**
* Calculate a precise time difference.
* @param string $start result of microtime()
* @param string $end result of microtime(); if NULL/FALSE/0/'' then it's now
* @return flat difference in seconds, calculated with minimum precision loss
*/
function microtime_diff($start, $end = null)
{
if (!$end) {
@hadl
hadl / imagemagick extend image canvas
Last active January 2, 2016 11:49
Extend Icon-Files to 20x20px and preserve colors
mogrify -background transparent -gravity center -extent 20x20 -format png -colorspace sRGB -define png:color-type=6 -path resized *.png
@hadl
hadl / file delete older than x days
Last active January 12, 2018 09:08
Delete PNGs older than 30 days
# more info: http://www.vionblog.com/linux-delete-files-older-than-x-days/
find . -type f -name '*.png' -mtime +30 -exec rm {} \;
# better use delete flag :)
find . -type f -name '*.png' -mtime +30 -delete;
# use -mmin instead of -mtime for minutes
@hadl
hadl / Default Logrotation
Created January 21, 2014 10:07
Default Logrotation
# place in /etc/logrotate.d/
{DIR}*.log {
daily
rotate 7
compress
delaycompress
notifempty
}
// good old times
http://www.youtube.com/watch?v=S1ULpM-lTMY
@hadl
hadl / Magento Fix Sendfriend Mail Sender
Created April 16, 2014 09:48
Magento: Fix Sendfriend Mail Sender. You can't send mails from your server with eg. gmail.com as sender mail address!
<?php
/**
* Mds_MagentoExtender_Model_Sendfriend_Sendfriend for our extension. Use your own name.
*/
class Mds_MagentoExtender_Model_Sendfriend_Sendfriend extends Mage_Sendfriend_Model_Sendfriend {
public function send()
{
if ($this->isExceedLimit()){
Mage::throwException(Mage::helper('sendfriend')->__('You have exceeded limit of %d sends in an hour', $this->getMaxSendsToFriend()));
@hadl
hadl / gist:0c35bce6d3de698c92efca5873a557ee
Created April 27, 2016 09:42
Imagemagick convert pngs to progressive jpgs
mogrify -strip -interlace Plane -format jpg -colorspace sRGB -quality 85 *.png
@hadl
hadl / gist:892a6ea257fa0c37fd517b150b8fb8dd
Created August 2, 2018 14:07
Split mp3 into x seconds parts with ffmpeg
ffmpeg -i file.mp3 -f segment -segment_time 7200 -c copy out%03d.mp3
# -segment_time in seconds
@hadl
hadl / LanguageSwitcherExtension.php
Last active January 15, 2019 11:14
Pimcore 5 Basic Language Switcher with Twig Extension
/**
* Provides get_localized_links function in the Twig.
*
* Class LanguageSwitcherExtension
*/
class LanguageSwitcherExtension extends \Twig_Extension
{
/**
* Pimcore documents service which provide needed methods.
*
@hadl
hadl / TranslateUpdateTrait.php
Last active April 9, 2019 09:18
[Pimcore 5 Migration] TranslateUpdateTrait
<?php
/**
* TranslateUpdateTrait
*/
use Doctrine\DBAL\Schema\Schema;
/**
* Class TranslateUpdateTrait
*