Skip to content

Instantly share code, notes, and snippets.

Adi mocanuga

View GitHub Profile
@mocanuga
mocanuga / reset_database
Created Apr 26, 2017
Truncate all tables in a mysql or mariadb database shell script
View reset_database
#! /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
@mocanuga
mocanuga / optimize_dir
Last active Apr 20, 2017
Simple bash script to optimize images with guetzli
View optimize_dir
#!/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 / getFolderSize.php
Last active Apr 4, 2017
How to return the size of directory even if the directory is symlink with PHP?
View getFolderSize.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 / .htaccess
Created Sep 29, 2016
Ajax request detection in htaccess
View .htaccess
ErrorDocument 404 NotFound
ServerSignature Off
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@mocanuga
mocanuga / phoneOperator.php
Last active Jan 14, 2016
Validate Italy mobile phone numbers
View phoneOperator.php
/**
* @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',
You can’t perform that action at this time.