Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
Focusing

Mickael Lehoux MkLHX

🤓
Focusing
View GitHub Profile
@MkLHX
MkLHX / template.html.twig
Last active March 25, 2020 15:16
How to update specific key on existing multidimensional array in twig
View template.html.twig
{% set contents = {"one": 1,"two":2,"three":3,"four":4,"five":5} %}
{# Create the array an structure somewhere in the view #}
{% set twigArray = {} %}
{% for content in contents %}
{% set twigArray = twigArray|merge({('hashkey_'~loop.index0):{'enabled':true,'caption':'unknow','button':{'text':'unknow','href':'unknow'},'image':{'src': content.content|raw),'alt':"image-"~loop.index, 'href':"" }}}) %}
{% endfor %}
{{ dump(twigArray)}}
{# For any reason you need to update a specific key value in the exiting array in the view
call the twig extension to do that in php side #}
@MkLHX
MkLHX / raspi-config-commands-list.sh
Created January 8, 2020 15:54
raspi-config command list to use it in cli
View raspi-config-commands-list.sh
/* Command strings */
#define GET_CAN_EXPAND "raspi-config nonint get_can_expand"
#define EXPAND_FS "raspi-config nonint do_expand_rootfs"
#define GET_HOSTNAME "raspi-config nonint get_hostname"
#define SET_HOSTNAME "raspi-config nonint do_hostname %s"
#define GET_BOOT_CLI "raspi-config nonint get_boot_cli"
#define GET_AUTOLOGIN "raspi-config nonint get_autologin"
#define SET_BOOT_CLI "raspi-config nonint do_boot_behaviour B1"
#define SET_BOOT_CLIA "raspi-config nonint do_boot_behaviour B2"
#define SET_BOOT_GUI "raspi-config nonint do_boot_behaviour B3"
@MkLHX
MkLHX / PH_EC_reader_example.ino
Last active July 19, 2019 09:43
Read Serial Monitor orders to launch EC or PH calibration process (Arduino IDE version)
View PH_EC_reader_example.ino
#include "DFRobot_ESP_EC.h" //https://github.com/GreenPonik/DFRobot_ESP_EC_BY_GREENPONIK.git
#include "DFRobot_ESP_PH_WITH_ADC.h" //https://github.com/GreenPonik/DFRobot_ESP_PH_WITH_ADC_BY_GREENPONIK.git
#include "Adafruit_ADS1015.h" //https://github.com/GreenPonik/Adafruit_ADS1X15.git
#include "OneWire.h"
#include "DallasTemperature.h"
#include "EEPROM.h"
#define ONE_WIRE_BUS 15
OneWire oneWire(ONE_WIRE_BUS);
@MkLHX
MkLHX / main.cpp
Last active July 19, 2019 09:50
Read Serial Monitor orders to launch EC or PH calibration process (platformIO version)
View main.cpp
#include "Arduino.h"
#include "DFRobot_ESP_EC.h" //https://github.com/GreenPonik/DFRobot_ESP_EC_BY_GREENPONIK.git
#include "DFRobot_ESP_PH_WITH_ADC.h" //https://github.com/GreenPonik/DFRobot_ESP_PH_WITH_ADC_BY_GREENPONIK.git
#include "Adafruit_ADS1015.h" //https://github.com/GreenPonik/Adafruit_ADS1X15.git
#include "OneWire.h"
#include "DallasTemperature.h"
#include "EEPROM.h"
@MkLHX
MkLHX / main.cpp
Last active August 2, 2022 17:56
ESP32 - Update firmware through AsyncWebServer
View main.cpp
AsyncWebServer server_http(80);
const char header_html[] PROGMEM = "<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'/><meta name='viewport' content='width=device-width, initial-scale=1, minimum-scale=1.0, shrink-to-fit=no'><title>GreenPonik.com - WebView</title></head><body>";
const char footer_html[] PROGMEM = "</body></html>";
const char update_html[] PROGMEM = "<h1>Only .bin file</h1><form method='POST' action='/updt' enctype='multipart/form-data'><input type='file' name='update' required><input type='submit' value='Run Update'></form>";
void setup()
{
/* ... */
@MkLHX
MkLHX / main.cpp
Created April 30, 2019 16:59
Send Serial printed data in webserver view
View main.cpp
#include "Arduino.h"
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
#include "SPIFFS.h"
const char *ssid = "<yourssid>";
const char *password = "<wpakey>";
AsyncWebServer server_http(80);
@MkLHX
MkLHX / base.html.twig
Last active July 14, 2020 20:57
passe twig variables to javascript function Symfony 4.3.2
View base.html.twig
<!DOCTYPE html>
<html>
<head></head>
<body>
<!-- //... -->
{% set cookieData = {
msg: 'this website using cookie and by continuing navigation you accept blablablabla....etc',
btn1: 'More',
btn2: 'Accept',
path: '/privacy-policy'
@MkLHX
MkLHX / ContactController.php
Last active March 27, 2019 14:50
Recaptcha V2 on SF4 project
View ContactController.php
<?php
namespace App\Controller\Ui\WebSite;
use App\Services\SendinblueApi;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use App\Form\ContactType;
use ReCaptcha\ReCaptcha;
@MkLHX
MkLHX / SendinblueApi.php
Last active February 15, 2019 14:13
Send email in SF4 with sendinblue api V3 - https://developers.sendinblue.com/docs
View SendinblueApi.php
<?php
namespace App\Services;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class SendinblueApi
*
* @package App\Services
@MkLHX
MkLHX / App.js
Created February 4, 2019 16:59
wcs_quest_cycle_de_vie
View App.js
import React, { Component } from "react";
import "./App.css";
import MyTimer from "./MyTimer";
class App extends Component {
render() {
return (
<div className="App">
<header className="">