Skip to content

Instantly share code, notes, and snippets.

View marianmirzacu's full-sized avatar

Marian marianmirzacu

View GitHub Profile
@marianmirzacu
marianmirzacu / laravel
Last active November 24, 2023 13:48
nginx config file for laravel with php7.3
server {
server_name DOMAIN_NAME;
access_log /var/log/nginx/DOMAIN_NAME_access.log;
error_log /var/log/nginx/DOMAIN_NAME_error.log;
rewrite_log on;
root /var/www/DOMAIN_NAME/public;
index index.php index.html;
@marianmirzacu
marianmirzacu / default
Last active July 16, 2019 20:49
default nginx php7.3
server {
root /var/www/html;
index index.html index.php;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
@marianmirzacu
marianmirzacu / LEMP_Ubuntu_20.04
Last active December 2, 2020 16:40
LEMP stack for Ubuntu 20.04
apt update && apt -y upgrade && apt -y dist-upgrade && apt -y autoremove
apt install software-properties-common nginx git htop zip unzip curl nload
add-apt-repository ppa:ondrej/php
apt update
apt install mariadb-server memcached php-memcached php7.4-cli php7.4-fpm php7.4-mysql php7.4-curl php7.4-xml php7.4-mbstring php7.4-gd php7.4-intl
@marianmirzacu
marianmirzacu / csv_to_array_v1.php
Last active November 13, 2017 08:26
PHP transform CSV to Array - does NOT support line breaks in CSV fields
public function csvToArray ($csv_file) {
$csv = array_map(function($csv_file) {
return str_getcsv($csv_file, ";");
}, file($csv_file, FILE_SKIP_EMPTY_LINES));
$keys = array_shift($csv);
foreach ($csv as $i=>$row) {
$csv[$i] = array_combine($keys, $row);
}
@marianmirzacu
marianmirzacu / csv_to_array_v2.php
Created November 13, 2017 08:28
PHP transform CSV to Array - DOES support line breaks in CSV fields
public function csvToArray ($csv_file) {
$rows = $keys = $csv = array();
if (($handle = fopen($csv_file->getRealPath(), "r")) !== FALSE) {
$i = 0;
while (($data = fgetcsv($handle, null, ";")) !== FALSE) {
$i++;
if ($i == 1) {
@marianmirzacu
marianmirzacu / sync_work.sh
Last active July 17, 2019 08:46
archive and upload to onedrive (or other cloud storage) my work folder
#!/bin/bash
HOME=/mnt/e/work
DIRS=`ls $HOME`
TIMESTAMP=$(date +"%F")
for dir in $DIRS;do
echo "START backup $dir"
zip -rq "$HOME"/"$dir".zip "$HOME"/"$dir"/*
echo "START transfer $dir"
@marianmirzacu
marianmirzacu / backup.sh
Created July 16, 2019 20:44
archive each DB and upload to onedrive (or other cloud storage) / archive and upload to onedrive (or other cloud storage) the whole /var/www folder
#!/bin/bash
# some inspiration https://mensfeld.pl/2013/04/backup-mysql-dump-all-your-mysql-databases-in-separate-files/
TIMESTAMP=$(date +"%F")
BACKUP_DIR="/root/backupdb/$TIMESTAMP"
MYSQL_USER=""
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD=""
MYSQLDUMP=/usr/bin/mysqldump
mkdir -p "$BACKUP_DIR"
@marianmirzacu
marianmirzacu / ssl_srcset.php
Created September 3, 2019 17:25 — forked from joemcgill/ssl_srcset.php
Force WordPress `srcset` to HTTPS
/*
* Force URLs in srcset attributes into HTTPS scheme.
* This is particularly useful when you're running a Flexible SSL frontend like Cloudflare
*/
function ssl_srcset( $sources ) {
foreach ( $sources as &$source ) {
$source['url'] = set_url_scheme( $source['url'], 'https' );
}
return $sources;
@marianmirzacu
marianmirzacu / makeSlugFromTitle.php
Created September 6, 2019 19:47
makeSlugFromTitle - Laravel
public function makeSlugFromTitle($title)
{
$slug = Str::slug($title);
$count = Conversation::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?$'")->count();
return $count ? "{$slug}-{$count}" : $slug;
}
@marianmirzacu
marianmirzacu / domain.ro.conf
Created March 11, 2021 15:25
nginx / wp / php8.0-fpm / let's encrypt - config file
server {
server_name DOMAIN.ro;
return 301 https://www.DOMAIN.ro$request_uri;
listen 443 ssl http2; # managed by Certbot
listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/DOMAIN.ro/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/DOMAIN.ro/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot