Skip to content

Instantly share code, notes, and snippets.

View simonrenoult's full-sized avatar
🏠
Working from home

Simon Renoult simonrenoult

🏠
Working from home
View GitHub Profile
mysql> EXPLAIN SELECT * FROM articles WHERE article_id = 150000;
+----+-------------+----------+------------+------+---------------+------+---------+------+---------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+----------+------------+------+---------------+------+---------+------+---------+----------+-------------+
| 1 | SIMPLE | articles | NULL | ALL | PRIMARY | NULL | NULL | NULL | 1271825 | 10.00 | Using where |
+----+-------------+----------+------------+------+---------------+------+---------+------+---------+----------+-------------+
1 row in set, 3 warnings (0.01 sec)
# Time: 2019-06-26T14:33:07.346902Z
# Query_time: 0.658942 Lock_time: 0.000174 Rows_sent: 0 Rows_examined: 999986
SET timestamp=1561559587;
select * from articles where article_id = 150000;
CREATE TABLE articles (
article_id VARCHAR(32),
article_title VARCHAR(255),
article_content TEXT,
PRIMARY KEY (article_id)
);
mysql> SHOW GLOBAL VARIABLES WHERE Variable_name IN ('long_query_time', 'slow_query_log', 'slow_query_log_file', 'log_queries_not_using_indexes', 'log_output');
$> mysql --host=127.0.0.1 --protocol=TCP --user=root --password=password
mysql> SET GLOBAL log_output=FILE;
mysql> SET GLOBAL log_queries_not_using_indexes=ON;
mysql> SET GLOBAL long_query_time=0.1;
mysql> SET GLOBAL slow_query_log=ON;
mysql> SET GLOBAL slow_query_log_file='/var/log/mysql/slow-query.log';
# Time: 2019-06-26T10:32:05.868845Z
# User@Host: root[root] @ [172.17.0.1] Id: 2
# Query_time: 0.000411 Lock_time: 0.000136 Rows_sent: 0 Rows_examined: 0
use debug_sql;
SET timestamp=1561545125;
select * from articles;
mysql> SELECT * FROM articles;
+------------+-----------------------------+-----------------+
| article_id | article_title | article_content |
+------------+-----------------------------+-----------------+
| 1 | Les tomates en Provence | Lorem ipsum... |
| 2 | Les courgettes de Normandie | Lorem ipsum... |
| 3 | Les pommes de Lorraine | Lorem ipsum... |
| 4 | Les poires de Paris | Lorem ipsum... |
| ... | ... | ... |
| 999986 | La menthe de Bretagne | Lorem ipsum... |
@simonrenoult
simonrenoult / new_project.sh
Last active March 1, 2019 09:32
Script to bootstrap a nodejs project
project_name=$1
project_description=$2
location=$HOME/code/$project_name
pkg=$location/package.json
readme=$location/readme.md
node_version=$(node --version)
npm_version=$(npm --version)
if [ -z "$project_name" ]; then
echo "Error: a project name must be provided."
@simonrenoult
simonrenoult / LogExecutionTime.java
Last active February 26, 2019 16:38
Log Execution Time
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogExecutionTime {
/**
* Returns the kind of execution time to log
*
* @return the kind of execution time to log
*/
String kind() default "-";
@simonrenoult
simonrenoult / http-patch.md
Last active November 12, 2018 08:41
Exemple d'un requête PATCH non-idempotente

Etant donné la ressource :

GET /articles/1234 HTTP/1.1

HTTP/1.1 200 OK
{ "title": "PUT vs PATCH","tags": ["http", "api", "rest"] }

Si j'exécute plusieurs fois la requête PATCH d'ajout d'un tag via le format [JSON Patch] (sans l'utilisation d'un etag)