Skip to content

Instantly share code, notes, and snippets.

View mocanuga's full-sized avatar

Adi mocanuga

  • Galati, Romania
View GitHub Profile
@mocanuga
mocanuga / phoneOperator.php
Last active January 14, 2016 23:31
Validate Italy mobile phone numbers
/**
* @author mocanuga
* @desc Return the operator for a phone number for Italy
* @return string
*/
function phoneOperator ($phone) {
if(!preg_match('/((313)|(3[2-9]{1}[0-9]{1}))([0-9]{7})/', $phone)) // invalid Italy mobile number
return 'unkown';
$mobileOperators = array(
'/^313/' => 'Rete Ferroviaria Italiana',
@mocanuga
mocanuga / .htaccess
Created September 29, 2016 15:56
Ajax request detection in htaccess
ErrorDocument 404 NotFound
ServerSignature Off
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@mocanuga
mocanuga / getFolderSize.php
Last active April 4, 2017 13:17
How to return the size of directory even if the directory is symlink with PHP?
<?php
/**
* @author mocanuga
* @desc Return the size of directory in bytes. Tested on CentOS 5.11 Final
* @return int
*/
function getFolderSize($folder = '') {
if(empty($folder))
return -1;
$dir = escapeshellcmd($folder);
@mocanuga
mocanuga / optimize_dir
Last active August 26, 2020 04:53
Simple bash script to optimize images with guetzli
#!/bin/bash
################################################
# #
# Don't forget to make this file executable #
# (chmod +x optimize_dir) #
# #
# Improvements are always welcomed and #
# encouraged #
# Added a "sizes" parameter to only get image #
@mocanuga
mocanuga / reset_database
Created April 26, 2017 10:58
Truncate all tables in a mysql or mariadb database shell script
#! /bin/bash
############################################
# don't forget to chmod +x reset_database #
# usage: ./reset_database dbname #
# enter db password when prompted #
############################################
# set the database name
DATABASE_NAME=$1