Skip to content

Instantly share code, notes, and snippets.

View foxycode's full-sized avatar

Tomáš Jacík foxycode

View GitHub Profile
@foxycode
foxycode / Category.php
Created January 23, 2015 18:17
PrestaShop (1.4) fastest possible product listing
<?php
class Category extends CategoryCore
{
public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $checkAccess = true)
{
$id_country = Country::getDefaultCountryId();
$builder = ProductQueryBuilder::create($id_lang, $id_country)
@foxycode
foxycode / Smarty_Compiler.class.php
Created January 23, 2015 19:46
PrestaShop 1.4 preg_replace with e modifier to preg_replace_callback replacement
/* replace special blocks by "{php}" */
$source_content = preg_replace_callback($search, function($matches) {
return '{php' . str_repeat("\n", substr_count('\0', "\n")) . '}';
}, $source_content);
// $source_content = preg_replace($search.'e', "'"
// . $this->_quote_replace($this->left_delimiter) . 'php'
// . "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'"
// . $this->_quote_replace($this->right_delimiter)
// . "'"
// , $source_content);
@foxycode
foxycode / sdc-lastcomm.patch
Last active October 15, 2015 21:20
SmartOS /smartdc/bin/sdc-lastcomm patch for stat() error
--- /smartdc/bin/sdc-lastcomm Fri May 30 03:16:17 2014
+++ /smartdc/bin/sdc-lastcomm Tue Apr 21 11:23:16 2015
@@ -48,10 +48,19 @@
echo "-R is not valid with -d"
exit 1
fi
+ MAX_SLEEP=3
+ cd "$DIR" || exit 1
+ # Save the current audit log filename
+ AUDIT_LOG=`find . -name "*.not_terminated.*"`
@foxycode
foxycode / pri.2.0.0.0.0.0.6.c.2.0.a.2.ip6.arpa
Created March 3, 2017 11:07
ipv6 reverse zone example
$TTL 3600
@ IN SOA ns.sunfox.cz. sunfox.sunfox.cz. (
2016010902 ; serial, todays date + todays serial #
7200 ; refresh, seconds
540 ; retry, seconds
604800 ; expire, seconds
86400 ) ; minimum, seconds
;
2.0.0.0.0.0.6.c.2.0.a.2.ip6.arpa. 3600 NS ns.sunfox.cz.
@foxycode
foxycode / sshfp.sh
Created May 17, 2017 15:50
Get SSHFP records from SSH keys
#!/bin/bash
echo "$(hostname) SSHFP 1 2 $(cut -f2 -d ' ' "/etc/ssh/ssh_host_rsa_key.pub" | base64 --decode | sha256sum | cut -f 1 -d ' ')"
echo "$(hostname) SSHFP 4 2 $(cut -f2 -d ' ' "/etc/ssh/ssh_host_ed25519_key.pub" | base64 --decode | sha256sum | cut -f 1 -d ' ')"
@foxycode
foxycode / remove_old_kernels.sh
Created June 19, 2017 09:43
Remove old Ubuntu kernels
#!/bin/bash
current_version=$(uname -r | sed 's/-generic\|-virtual//')
kernels=$(dpkg -l | grep 'linux-image-[0-9]' | awk '{print $2}')
latest_kernel=$(echo $kernels | tr ' ' '\n' | tail -1)
remove_kernels=$(echo $kernels | tr ' ' '\n' | grep -v $latest_kernel | grep -v $current_version)
headers=$(dpkg -l | grep 'linux-headers-[0-9]' | awk '{print $2}')
latest_headers=$(echo $headers | tr ' ' '\n' | tail -1)
@foxycode
foxycode / Passwords.php
Created October 11, 2017 20:16
Prestashop password rehash class
<?php declare(strict_types=1);
final class Passwords
{
private const OLD_SALT = 'xxx';
public const PS_OLD = 'prestashop_old';
public const PS_HASHED = 'prestashop_hashed';
public const BCRYPT = 'bcrypt';
@foxycode
foxycode / BasePresenter.php
Last active July 31, 2018 19:14
Nette Multilang App
<?php declare(strict_types=1);
namespace App\Presenters;
use Kdyby\Translation\Translator;
use Nette\Application\Helpers;
use Nette\Application\UI\Presenter;
abstract class BasePresenter extends Presenter
{
@foxycode
foxycode / mikrotik-backup-link-over-lte
Last active October 7, 2023 14:48
MikroTik backup link over LTE
CREATE TABLE `dns_record` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`origin` varchar(63) COLLATE utf8_bin NOT NULL,
`name` varchar(255) COLLATE utf8_bin NOT NULL,
`type` char(6) COLLATE utf8_bin NOT NULL,
`value` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`),
KEY `origin` (`origin`),
KEY `type` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;