Skip to content

Instantly share code, notes, and snippets.

@bsh
bsh / imagemagick1
Last active August 29, 2015 13:56
Crop square imagemagick
$inFile = '/var/www/...';
$outFile = '/var/www/...';
$image = new Imagick($inFile);
$width = $height = 100;
$image = new Imagick($inFile);
$geo = $image->getImageGeometry();
if(($geo['width']/$width) < ($geo['height']/$height))
{
$image->cropImage($geo['width'], floor($height*$geo['width']/$width), 0, (($geo['height']-($height*$geo['width']/$width))/2));
}
@bsh
bsh / imagemagick2
Created February 17, 2014 15:33
Content aware cropping
$inFile = '/var/www/...';
$outFile = '/var/www/...';
$image = new Imagick($inFile);
$targetWidth = 130;
$targetHeight = 79;
$source = $image->getImageGeometry();
if(($source['width'] / $source['height']) < ($targetWidth / $targetHeight)) {
$scale = $source['width'] / $targetWidth;
@bsh
bsh / carriage_return
Last active August 29, 2015 13:56
Remove carriage return from end of filename
find -type f -name '*.jpg*' -exec rename 's/[^a-zA-Z0-9.\/]//' {} \;
@bsh
bsh / getCountryFromCity.php
Created June 6, 2017 07:56
getCountryFromCity
public function getCountryFromCity($city)
{
if (isset($this->country_city_array[$city])) {
return $this->country_city_array[$city];
} else {
//get
$url = 'http://nominatim.openstreetmap.org/search?city=' . urlencode($city) . '&format=json&limit=1&addressdetails=1&accept-language=en';
$c = curl_init();
$agent = random_user_agent();
@bsh
bsh / stock.php
Created July 7, 2017 14:39
Hide out of stock products - prestashop
<?php
/* Hide out of stock products */
/* bsh - brandlift.eu */
if ((!file_exists('init.php') || !file_exists('config/config.inc.php')) && _COOKIE_KEY_ != '') {
die('Error: An include file not found. Check the path.');
} else {
include('config/config.inc.php');
require_once('init.php');
}
@bsh
bsh / copy_lang.php
Last active November 18, 2018 20:15
Prestashop - Copy product description
<?php
/* Copy lang */
/* bsh - brandlift.eu */
if ((!file_exists('init.php') || !file_exists('config/config.inc.php')) && _COOKIE_KEY_ != '') {
die('Error: An include file not found. Check the path.');
} else {
include('config/config.inc.php');
require_once('init.php');
}
@bsh
bsh / mysql.php
Created November 26, 2018 09:04 — forked from billsuxx/mysql.php
<?php
/**
* Procedural drop in replacement for legacy projects using the MySQL function
*
* @author Sjoerd Maessen
* @version 0.1
*/
// Make sure the MySQL extension is not loaded and there is no other drop in replacement active
if (!extension_loaded('mysql') && !function_exists('mysql_connect')) {
@bsh
bsh / cf.php
Created May 11, 2020 14:08
Bulk delete cloudflare DNS records
<?php
function auth_redirect()
{
}
function wp_get_current_user()
{
global $current_user;
wp_set_current_user(1);
public static function trackBooking(Order $order)
{
if (! isset($order->id)) {
return false;
}
$po_api_username = config('constants.po_api_username');
$po_api_password = config('constants.po_api_password');
$ContractID = config('constants.po_api_contract_id');
$TransactionID = time().rand(1, 9999);
add_action('fix_expired_sales_price', 'fix_expired_sales_price_function');
/**
* Törli az akciós árat, ha az akció ideje már lejárt és mégis
* bent marad az ár és a dátum. Valemelyik akciókkal kapcsolatos
* plugin hibája.
*
* Az actiont wp cron futtatja naponta kétszer.
*