Skip to content

Instantly share code, notes, and snippets.

View Langmans's full-sized avatar

Langmans Langmans

  • Netherlands
  • 10:50 (UTC +02:00)
View GitHub Profile
@Langmans
Langmans / .htaccess
Created May 11, 2018 07:33
php redirect naar nieuwe files (webpack manifest file)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule build/.* manifest.php [L,QSA,NC]
@Langmans
Langmans / woo-api-imgsizes.php
Created April 9, 2018 11:41
woocommerce REST API plugin to add all image sizes
<?php
/*
Plugin Name: Woocommerce image sizes in API
*/
$f = function ( WP_REST_Response $response, WC_Data $data ) {
if ( $data instanceof WC_Product ) {
$data = $response->get_data();
if ( isset( $data['images'] ) ) {
@Langmans
Langmans / random-codes.php
Created November 28, 2017 14:09
random codes
<?php
$codes = [];
$idx1 = '23456789';
$idx2 = 'BCDFGHJKPQRSTVWXYZ';
while (($c = count($codes)) < 40000) {
$code = '';
while (strlen($code) < 8) {
@Langmans
Langmans / .htaccess
Last active November 10, 2017 09:29
automatic minified/gzip with support for cache busting
RewriteRule .* - [E=SLIM_MODE:development]
#RewriteRule .* - [E=SLIM_MODE:testing]
#RewriteRule .* - [E=SLIM_MODE:production]
# Filename-based cache busting
# strip timestamp from file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(less|s?css|cur|gif|ico|jpe?g|js|png|svgz?|webp)$ $1.$3 [NC]
@Langmans
Langmans / charset_detect.php
Created September 25, 2017 18:45
simple util to detect character set of a string. handy if you are getting question marks.
<?php
mb_internal_encoding('UTF-8');
$detect = 'auto, ISO-8859-1, ISO-8859-15, ISO-8859-2, UTF-7';
mb_detect_order($detect);
header('Content-type: text/html;charset=UTF-8');
mb_http_output("UTF-8");
ob_start("mb_output_handler");
$text = filter_input(INPUT_GET, 'text')
@Langmans
Langmans / get_query_for_page_url.php
Created September 22, 2017 07:25
Makes a query to find a page object for a page that uses the adjacency model.
<?php
/**
* @param string $url
* @param string $select
* @param string $table
* @param string $slug_column
* @param string $id_column
* @param string $parent_column
* @param bool $strict
<?php
// example
//var_dump(buttons_from_string('"Meer informatie"</toughbooks> | "Offerte"</offertes>'));
function buttons_from_string($button_string)
{
preg_match_all('@"([^"]+)"<([^<>]+)>@', $button_string, $matches, PREG_SET_ORDER);
$buttons = [];
@Langmans
Langmans / install.cmd
Last active September 11, 2017 19:05
installs composer dependencies to the current directory without having composer installed.
@ECHO OFF
setLocal EnableDelayedExpansion
:DETECT_PHP
CALL php --version > nul 2>&1 && GOTO:DETECT_COMPOSER || GOTO:INSTALL_PHP
:DETECT_COMPOSER
CALL composer --version > nul 2>&1 && GOTO:INSTALL_DEPENDENCIES|| GOTO:INSTALL_COMPOSER
:INSTALL_DEPENDENCIES
@Langmans
Langmans / prestashop-move.sql
Created July 11, 2017 13:55
prestashop transfer to other host / localhost
/* configuration should have a prefix */
update configuration set value = 0 where name = 'PS_SSL_ENABLED';
update configuration set value = 0 where name = 'PS_REWRITING_SETTINGS';
update configuration set value = 0 where name = 'PS_CANONICAL_REDIRECT';
update configuration set value = 0 where name = 'PS_HTACCESS_DISABLE_MULTIVIEWS';
@Langmans
Langmans / fix.php
Created July 3, 2017 10:43
~username fix for centos linux usernames, where document_root is incorrect because domains arent resolved yet.
<?php
// linux fix for domains that arent resolved yet (/~username/)
if ($_SERVER['DOCUMENT_ROOT'] == '/var/www/html' &&
preg_match('@^/~[a-z0-9]+/@i', $_SERVER['REQUEST_URI']) &&
basename(__DIR__) == 'public_html'
) {
$_SERVER['DOCUMENT_ROOT'] = realpath(__DIR__);
}