Skip to content

Instantly share code, notes, and snippets.

View timotheemoulin's full-sized avatar

Timothee Moulin timotheemoulin

View GitHub Profile
@timotheemoulin
timotheemoulin / PHP things
Last active October 15, 2020 06:13
Does PHP evaluate things the way you thought?
<?php
// counting values
var_dump(count(array())); // 0
var_dump(count(false)); // 1
var_dump(count(true)); // 1
var_dump(count(null)); // 0
var_dump(count(1)); // 1
var_dump(count(0)); // 1
var_dump(count('asdf')); // 1
<?php
/*
Plugin Name: PHP Mailer Override
Version: 1.0.0
Description: Override config for development environment.
Author: Timothée Moulin
Author URI: https://timothee-moulin.me/
*/
defined( 'ABSPATH' ) OR exit;
@timotheemoulin
timotheemoulin / convert-8859-utf8.sh
Last active August 13, 2018 09:32
convert files from iso-8859-1 to utf8
#!/usr/bin/env bash
# Timothée Moulin
#
# Install : copy this script anywhere (you can place it in the (/usr/local/bin) directory
# and give it the execution permission : chmod +x convert-8859-utf8.sh
#
# You can use this script either by calling it directly to convert a single file
# or you can give it to the "find -exec" command to convert a batch of files.
# e.g.
<?php
$foo = new StdClass();
$foo->bar = new StdClass();
$foo->bar->baz = 'toto';
// this contains the main object
var_dump($foo);
@timotheemoulin
timotheemoulin / convert-db-latin-utf8.sh
Last active November 27, 2018 07:30
Convert all tables and columns from a given database from old ISO to UTF8.
#!/usr/bin/env bash
# Timothée Moulin
#
# Install : copy this script anywhere (you can place it in the (/usr/local/bin) directory
# and give it the execution permission : chmod +x convert-db-latin-utf8.sh
#
# You must call this script and give it the following parameters.
# 1) [required] database user
# 2) [required] database name
@timotheemoulin
timotheemoulin / ssh-compile
Last active March 28, 2019 18:25
SSH config files compilation from multiple files
# Include this snippet in your .zshrc or .bashrc file to compile multiple ssh config files into one.
# Put the file anywhere and source it from your .zshrc or .bashrc file with : source /path/to/ssh-compile
# This can be useful if you share a config file among several people like in your company and also some private hosts.
# call ssh-compile-config to get all the files matching ~/.ssh/.config* and combine them into the final ~/.ssh/config file
alias ssh-compile-config='echo -n > ~/.ssh/.config && cat ~/.ssh/config* > ~/.ssh/.config'
ssh-compile-config
# fetch all the configured hosts
h=()
@timotheemoulin
timotheemoulin / switch-vs-if-else.php
Created May 1, 2019 12:46
Avoid if else structure when possible
<?php
global $i;
$i = 0;
function test() {
global $i;
var_dump(++$i);
return $i;
}
switch (test()) {

Timothée Moulin

Timothée Moulin

@timotheemoulin
timotheemoulin / Microsoft.PowerShell_profile.ps1
Created September 30, 2019 14:53
Powershell custom functions
# Powershell Custom Functions
# Timothée Moulin
#
# Change directory to the root workspace directory
Function tim-goto-workspace-tim {
cd ~/www
ls
}
Set-Alias -Name www -Value tim-goto-workspace-tim
@timotheemoulin
timotheemoulin / php-coalesce-operator.php
Last active April 8, 2020 11:35
Check what really does the coalesce operator
<?php
// undefined variable
echo "?? prints 'default'";
echo "<br>";
var_dump($a ?? 'default');
echo "<br><br>";
echo "?: sends a notice 'undefined variable' and prints 'default'";