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
@simonrenoult
simonrenoult / sanitize.js
Last active February 23, 2024 08:42
Recursive trim of objects and arrays using lodash
function sanitize(object) {
if (_.isString(object)) return _sanitizeString(object);
if (_.isArray(object)) return _sanitizeArray(object);
if (_.isPlainObject(object)) return _sanitizeObject(object);
return object;
}
function _sanitizeString(string) {
return _.isEmpty(string) ? null : string;
}
$> 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';
@simonrenoult
simonrenoult / timeout.js
Last active January 25, 2021 12:21
Managing timeout. Especially handy with autocomplete.
// Props to : http://nathanleclaire.com/blog/2013/11/16/the-javascript-question-i-bombed-in-an-interview-with-a-y-combinator-startup/
var processOnTime = function ( next, delay ) {
var d = delay;
if ( ! next ) {
throw new ReferenceError();
}
if ( ! d || isNaN ( d ) ) {
d = 200;
#!/usr/bin/env sh
# Warning! This script is a work in progress.
#
# The sript is buggy since logout/restarts are needed between some steps (zsh or docker I guess)
# but it's a good reminder of what needs to be done to setup a new machine.
main () {
install_prerequisites
install_and_configure_zsh
export PATH=$HOME/bin:/usr/local/bin:$PATH
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="avit"
HYPHEN_INSENSITIVE="true"
COMPLETION_WAITING_DOTS="true"
plugins=(autojump common-aliases docker extract httpie docker docker-compose kubectl)
source $ZSH/oh-my-zsh.sh
@RestController
public class HealthcheckApi {
private final SayImAlive sayImAlive;
public HealthcheckApi(SayImAlive sayImAlive) {
this.sayImAlive = sayImAlive;
}
@RequestMapping(value = "/healthcheck")
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o xtrace
# Script goes here...
mysql> EXPLAIN SELECT SQL_NO_CACHE * FROM articles WHERE article_id = '150001';
+----+-------------+----------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+----------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
| 1 | SIMPLE | articles | NULL | const | PRIMARY | PRIMARY | 34 | const | 1 | 100.00 | NULL |
+----+-------------+----------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
1 row in set, 1 warning (0.00 sec)
mysql> SELECT SQL_NO_CACHE * FROM articles WHERE article_id = '150000';
+------------+---------------+-----------------+
| article_id | article_title | article_content |
+------------+---------------+-----------------+
| 150000 | Title 150000 | Content 150000 |
+------------+---------------+-----------------+
1 row in set (0.00 sec)
mysql> SELECT SQL_NO_CACHE * FROM articles WHERE article_id = 150000;