Skip to content

Instantly share code, notes, and snippets.

View noweh's full-sized avatar
:octocat:
Follow me on Twitter @Noweh95

Julien SCHMITT noweh

:octocat:
Follow me on Twitter @Noweh95
View GitHub Profile
@noweh
noweh / screenshots.php
Last active April 5, 2024 08:08
FFmpeg usage with PHP (create screenshots and video screenshots)
<?php
// Create a screenshot
exec("ffmpeg -ss $secondId -i $videoUrl -ss 0 -frames:v 1 $directory/$secondId.jpg");
// Create a six-second video screenshot
exec("ffmpeg -y -i $videoUrl -ss " . ($secondId - 3) . " -t 6 -crf 18 -threads 1 $directory/$secondId.mp4");
@noweh
noweh / numbers.php
Created October 7, 2022 20:18
PHP Move given value to the end of the list
<?php
$array = [12, 0, 8, 1, 0, 39, 0, 7];
$searchedValue = 0;
$j=0;
for ($i=0; $i< count($array); ++$i) {
if ($array[$i] !== $searchedValue) {
if ($i !== $j && $array[$j] === $searchedValue) {
$array[$j] = $array[$i];
@noweh
noweh / dichotomic_search.php
Last active October 7, 2022 20:26
Dichotomic search in PHP
<?php
// Create an array and hide a value in it
$mySearchedValue = rand(0, 100);
$array = array_merge(
array_map(static function () {
return rand(0, 100);
}, array_fill(0, rand(9, 13), null)),
[$mySearchedValue],
@noweh
noweh / export_db.sh
Created May 24, 2022 09:07
mysqldump skip content from some tables (for GDRP)
#!/bin/bash
HOST_NAME=XXXX
USER=XXXX
PASSWORD=XXXX
DATABASE_NAME=XXXX
DB_FILE=export.sql
EXCLUDED_TABLES=(
table1
table2
@noweh
noweh / arrow_function_example.php
Last active February 9, 2022 13:56
Example of using PHP Arrow functions
<?php
$foo = 'foo';
$functions = [
'function1' => function ($bar) use ($foo) {
return $foo . $bar;
},
'function2' => fn ($bar) => $foo . $bar
];
foreach ($functions as $function) {
@noweh
noweh / abstract.repository.js
Last active February 1, 2022 13:32
Node.js and Sequelize: Redis-client and AbstractRepository files for database requests
const config = require('../config')
const RedisClient = require('./redis-client.js')
const sequelizeCache = require('./sequelize-cache')
class AbstractRepository {
/**
* Constructor, allows to use model directly in repository methods
* @param {Object} model
*/
constructor (model) {
@noweh
noweh / laravel_refresh_cache.sh
Created September 21, 2021 11:00
Laravel refresh cache in shell + clear OPCACHE
#!/usr/bin/env bash
php -d memory_limit=-1 artisan cache:clear
php -d memory_limit=-1 artisan config:clear
php -d memory_limit=-1 artisan config:cache
php -d memory_limit=-1 artisan route:clear
php -d memory_limit=-1 artisan route:cache
APP_URL=$(grep APP_URL .env | cut -d '=' -f2)
APP_ENV=$(grep APP_ENV .env | cut -d '=' -f2)
@noweh
noweh / VideoUtilities.php
Created September 21, 2021 10:52
Create a Video Thumbnail from MP4 with FFMPEG
<?php
use Storage;
$file = 'route/to/file.mp4';
$dirThumbnails = 'folder/for/thumbnails';
$thumbnailGroupQuantity = 60;
$thumbnailLineQuantity = 6;
$secondsBetweenTwoThumbnails = 5;
@noweh
noweh / purge_cdnetwork.sh
Last active September 21, 2021 10:20
Purge CDNetworks caches (folder or file)
#!/bin/bash
usage() {
printf "Usage:\n$0\n[-t (type of content) url|folder]\n[-u (url to purge) ex: https://xxx.yyy.com/logo.png]" 1>&2;
exit 1;
}
purgeUrl="https://api.cdnetworks.com/ccm/purge/ItemIdReceiver"
# data stored in a .env file
username=$(grep CDNETWORKS_USERNAME .env | cut -d '=' -f2)