Skip to content

Instantly share code, notes, and snippets.

View LouLeGrain's full-sized avatar

missingSemicolon LouLeGrain

View GitHub Profile
@LouLeGrain
LouLeGrain / boostrap3canvas.html
Last active May 6, 2018 16:38
[Template Bootstrap 3] Template de base Bootstrap 3 avec CDNs, charset, langue et top bar #HTML #Bootstrap3 #Template
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Bootstrap 3 Canvas</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="web/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
@LouLeGrain
LouLeGrain / bgSet.js
Created May 6, 2018 16:33
[Background fixed JS] Mettre un background sur le fond (Bootstrap) trigger par une classe dédiée #JS
$(document).ready(function () {
if ($("#content").hasClass("displayBg")) {
$("body").css('background', 'url(bg.jpg) fixed no-repeat');
}
}
@LouLeGrain
LouLeGrain / strFrmt.php
Created May 2, 2018 14:40
[String formatting] Formater une entrée utilisateur à caractères spéciaux #PHP
$nomFichier = strtr($fichier,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$nomFichier = preg_replace('/([^.a-z0-9]+)/i', '-', $fichier);
@LouLeGrain
LouLeGrain / dateComp.php
Last active May 1, 2018 13:42
[Comparaison de dates] Comparer si aujourd'hui est entre deux dates #PHP #Dates
public static function isVotingTime()
{
$dateEnd = new DateTime("03/31/2019", new DateTimeZone('Europe/Paris'));
$dateEndRelative = new DateTime("03/31/2019 last day of +1 month", new DateTimeZone('Europe/Paris'));
//Pour avoir +1 mois pile, on peut avoir des incohérences selon le nombre de jours
$dateBeginningVote = new DateTime("03/19/2018", new DateTimeZone('Europe/Paris'));
$today = new DateTime("now", new DateTimeZone('Europe/Paris'));
if ($today > $dateBeginningVote && $today < $dateEndRelative) {
@LouLeGrain
LouLeGrain / openCSV.php
Created April 24, 2018 19:03
[Open CSV] Ouvrir un fichier #CSV en séparant headers et contenu #PHP
public static function openCSV()
{
$delimiteur = ";"
$csvPath = realpath($_FILES['csv']['tmp_name']);
try {
$csvData = file_get_contents($csvPath);
$lines = explode(PHP_EOL, $csvData);
$array = array();
foreach ($lines as $line) {
$array[] = str_getcsv($line, $delimiteur);
@LouLeGrain
LouLeGrain / fileUpload.php
Created April 24, 2018 18:41
[Uploading script] Uploading a file (an image) #PHP
public static function uploadImg()
{
$dossier = 'participations/';
if (!file_exists($dossier)) {
mkdir($dossier, 0700);
}
$fichier = basename($_FILES['imgParticipation']['name']);
$taille_maxi = 3000000;
$taille = filesize($_FILES['imgParticipation']['tmp_name']);
@LouLeGrain
LouLeGrain / Database.php
Created April 24, 2018 18:36
[Database Access] Class w/ PDO #PHP
class Database
{
private static $datasource = 'mysql:host=localhost; dbname=mydbname';
private static $username = 'root';
private static $password = 'root';
private static $pdo;
public static function getPDO()
{
if (!isset(self::$db)) {