Skip to content

Instantly share code, notes, and snippets.

@gwarnants
gwarnants / export.sql
Created October 9, 2018 12:53
Export customers information from a PrestaShop database
SELECT id_customer, IFNULL(ps_gender_lang.name, NULLIF(ps_customer.id_gender, 0)) AS gender, ps_lang.iso_code AS lang, ps_customer.firstname, ps_customer.lastname, email, ps_customer.company, passwd, secure_key, birthday, newsletter, ip_registration_newsletter, optin, website, ps_customer.note, ps_customer.active, is_guest, ps_customer.deleted, ps_customer. date_add, ps_customer.date_upd,
ps_address.alias AS address_alias, ps_address.address1, ps_address.address2, ps_address.company AS address_company, ps_address.postcode, ps_address.city, ps_address.other, ps_address.phone, ps_address.phone_mobile, ps_address.vat_number, IFNULL(ps_country.iso_code,ps_address.id_country) AS country
FROM `ps_customer`
INNER JOIN ps_lang ON ps_customer.id_lang=ps_lang.id_lang
LEFT JOIN ps_gender_lang ON ps_gender_lang.id_gender= ps_customer.id_gender AND ps_gender_lang.id_lang=1
LEFT JOIN ps_address USING(id_customer)
LEFT JOIN ps_country ON ps_country.id_country=ps_address.id_country;
@gwarnants
gwarnants / AutoSpell.sublime-settings
Last active November 9, 2018 11:59
My AutoSpell settings for common PHP spelling mistakes
{
"default_triggers": [
":",
";",
".",
" ",
"(",
")",
"_",
"enter"
@gwarnants
gwarnants / .gitignore
Created February 14, 2018 14:00
.gitignore for Drupal 8 that ignores everything except custom files
# Ignore everything except custom files
/*
!/modules
/modules/*
!/modules/custom/
!/themes
/themes/*
!/themes/custom/
!/profiles
/profiles/*
@gwarnants
gwarnants / .gitattributes
Created February 10, 2017 09:20
sample .gitattributes for Drupal
# ignore git files
.gitattributes export-ignore
.gitignore export-ignore
# ignore drupal files
.editorconfig export-ignore
/*.txt export-ignore
install.php export-ignore
modules/README.txt export-ignore
sites/README.txt export-ignore
themes/README.txt export-ignore
@gwarnants
gwarnants / template.php
Created August 5, 2016 08:43
Disable pages indexation in Drupal (meta robots=noindex)
<?php
/**
* Implements hook_preprocess_html().
*/
function <theme>_preprocess_html(&$vars)
{
$meta = array(
'#tag' => 'meta',
'#attributes' => array(
@gwarnants
gwarnants / template.php
Last active August 4, 2016 13:49
Add HTTP status header as a body class
<?php
/**
* Implements hook_preprocess_html().
*/
function <theme>_preprocess_html(&$variables)
{
$header = drupal_get_http_header('status');
if ($header && preg_match('`^[0-9]+`', $header, $matches)) {
switch ($matches[0]) {
@gwarnants
gwarnants / array_linearize.php
Created March 4, 2016 11:24
Flatten a multidimensional array to a single dimensional array by joining nested keys together
<?php
/**
* Flatten a multidimensional array to a single dimensional array by joining nested keys together
*
* @param array $array The array to flatten
* @param string $glue Glue string to join keys together
* @return array
*/
function array_linearize(array $array, $glue = '/')
{
@gwarnants
gwarnants / gist:59e7d0707c75b95ab012
Created February 11, 2016 14:00
Parse XML with namespaces using SimpleXML
<?php
$xml = <<<ENDXML
<catalog xmlns:ns1="http://localhost/ns1" xmlns:ns2="http://localhost/ns2">
<product id="1" ns2:order="2">
<name>Test</name>
<ns1:price>100</ns1:price>
</product>
</catalog>
ENDXML;
@gwarnants
gwarnants / .htaccess
Created December 10, 2015 13:11
Sample rewrite rule depending on server date/time
# more info : http://httpd.apache.org/docs/current/en/expr.html#vars
# deny access from monday to friday and between 9am to 6pm
RewriteCond %{TIME_WDAY} ^1|2|3|4|5$
RewriteCond %{TIME_HOUR} ^0?9|10|11|12|13|14|15|16|17|18$
RewriteRule ^nsfw\.html$ - [L]
@gwarnants
gwarnants / composer.json
Last active March 18, 2019 14:47
Auto-configure PHP_CodeSniffer settings directly from composer.json
{
"require-dev": {
"squizlabs/php_codesniffer": "2.*"
},
"scripts": {
"phpcs-setup": [
"\"vendor/bin/phpcs\" --config-set default_standard ruleset.xml",
"\"vendor/bin/phpcs\" --config-set colors 1",
"\"vendor/bin/phpcs\" --config-set show_progress 1",
"\"vendor/bin/phpcs\" --config-set report_width 120",