Skip to content

Instantly share code, notes, and snippets.

View anytizer's full-sized avatar

Bimal Poudel anytizer

View GitHub Profile
@anytizer
anytizer / globals-variable-scopes.php
Last active May 16, 2016 23:06
Global Variable Scopes
<?php
header('Content-Type: text/plain');
# Normal server environment
ini_set('display_errors', 'Off');
error_reporting(0);
$test = 'TEST VALUE';
function test()
@anytizer
anytizer / sizes-per-tables.sql
Created May 16, 2016 10:09
Disk space occupied by each tables of a MySQL Database.
SELECT
table_name,
ROUND(KBS/POWER(1024,1), 2) KBs,
ROUND(KBS/POWER(1024,2), 2) MBs
FROM
(
SELECT
table_name, SUM(index_length) KBS
FROM information_schema.tables
WHERE
@anytizer
anytizer / PhpIniConfigurationsTest.php
Last active February 13, 2018 15:49
Testing PHP.ini configurations with PHPUnit
<?php
namespace cases;
use PHPUnit\Framework\TestCase;
class PhpIniConfigurationsTest extends TestCase
{
/**
* Most common configurations
*/
USE test;
DROP TABLE IF EXISTS apache_logs;
CREATE TABLE apache_logs (
log_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Log ID',
processing_time INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Processing time in milliseconds',
http_status INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'HTTP status code',
request_method VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'Request URL (GET/POST)',
access_url TEXT NOT NULL COMMENT 'URLs accessed',
PRIMARY KEY (log_id)
<?php
header('Content-Type: text/plain');
/**
* Build an array to loop.
*/
$time0 = microtime(true);
for($i=9999; $i>0; --$i)
{
$values[] = null;
@anytizer
anytizer / xdebug.ini
Created March 25, 2016 07:33
XDebug better configurations (personal purpose)
[XDebug]
; Debug: http://localhost/?XDEBUG_SESSION=debug
; Trace: http://localhost/?XDEBUG_TRACE=debug
; Profile: XDEBUG_PROFILE cookie
;
; http://localhost/?XDEBUG_SESSION=debug&XDEBUG_TRACE=debug&XDEBUG_PROFILE=debug
;
; Firefox Plugin: The easiest Xdebug - by - Nikita Nikitin
; https://addons.mozilla.org/en-US/firefox/addon/the-easiest-xdebug/
;
@anytizer
anytizer / trap-data.php
Created March 24, 2016 09:53
Grabs the data passing between PHP functions
class trap
{
public static function parameters($mixed)
{
file_put_contents('/tmp/parameters-'.date('YmdH').'.log', "\r\n\r\n".print_r($mixed, true), FILE_APPEND);
}
public static function sql($mixed)
{
file_put_contents('/tmp/sql-'.date('YmdH').'.log', "\r\n\r\n".print_r($mixed, true), FILE_APPEND);
@anytizer
anytizer / table-comments.sql
Created March 22, 2016 08:59
Comments in the tables
SELECT
TABLE_NAME, TABLE_COMMENT
FROM INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA=DATABASE()
AND TABLE_TYPE='BASE TABLE'
ORDER BY
TABLE_NAME
;
@anytizer
anytizer / wipe-out-tables.sql
Last active March 26, 2016 09:23
Wipe out WP_ tables from current database
SELECT
CONCAT('DROP TABLE `', t.table_name,'`;') drop_sql
FROM information_schema.TABLES t
WHERE
t.table_schema = DATABASE()
AND t.table_name LIKE 'wp\_%'
;
@anytizer
anytizer / php-constants.php
Created March 19, 2016 08:47
Database of PHP Constants
<?php
header('Content-Type: text/plain');
/**
* Fix to: Maximum execution time of 30 seconds exceeded.
* Loop can fail in-between otherwise.
*/
set_time_limit(0);
$mysqli = new MySQLi('localhost', 'USERNAME', 'PASSWORD', 'test');