Skip to content

Instantly share code, notes, and snippets.

View LeoBenoist's full-sized avatar

Léo Benoist LeoBenoist

View GitHub Profile
@LeoBenoist
LeoBenoist / reader.php
Last active June 17, 2021 09:33
Csv Simple Reader
<?php
function readCsv(string $filename, string $delimiter = ',', string $enclosure = '"', string $escape = '\\'){
ini_set('auto_detect_line_endings', true);
$row = 0;
$headers = [];
if (($handle = fopen($filename, 'r')) !== FALSE) {
while (($data = fgetcsv($handle, 0, $delimiter, $enclosure, $escape)) !== FALSE) {
$row++;
if(1 === $row){
$headers= $data;
@LeoBenoist
LeoBenoist / GoogleImageSearch.php
Last active April 3, 2020 05:39
Find Image on google
<?php
/*
* Inspired by https://github.com/damiankw/google.imagesearch
*/
class GoogleImageSearch
{
public function findImagesForQuery(string $query): array
{
$html = $this->queryGoogle($query);
$pattern = '/\bhttps?:\/\/\S+(?:jpg)\b/';
@LeoBenoist
LeoBenoist / gist:7897300
Last active December 30, 2015 22:58
This is a patch to fix special char (accents...) bugs (bad charset, encoding) for PostgreSQL in PgSQL.
DO $$
DECLARE
tables CURSOR FOR (SELECT TABLE_NAME as "name", COLUMN_NAME as "column" FROM INFORMATION_SCHEMA.COLUMNS WHERE (DATA_TYPE LIKE '%char%' OR DATA_TYPE = 'text') AND TABLE_SCHEMA = 'public');
BEGIN
FOR table_record IN tables LOOP
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''é'',''é'')';
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''ä'',''ä'')';
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''ö'',''ö'')';
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''Ã¥'',''å'')';
EXECUTE 'UPDATE public.' || table_record.name ||' SET ' || table_record.column || ' = REPLACE(' || table_record.column || ', ''è'',''è'')';