Skip to content

Instantly share code, notes, and snippets.

View anytizer's full-sized avatar

Bimal Poudel anytizer

View GitHub Profile
@anytizer
anytizer / mysql-json.cs
Created August 30, 2016 06:28
MySQL to JSON in C#
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
@anytizer
anytizer / backup-all-databases.sh
Created July 10, 2016 16:59
Backup all databases at once with one shell script.
#!/bin/bash
# Backup all available databases
USERNAME="root";
PASSWORD="password";
for DATABASE in `mysql -u${USERNAME} -p${PASSWORD} -e "SHOW DATABASES;"`
do
echo mysqldump --routines -u${USERNAME} -p${PASSWORD} ${DATABASE} \> ${DATABASE}.dmp;
mysqldump --routines -u${USERNAME} -p${PASSWORD} ${DATABASE} > ${DATABASE}.dmp;
@anytizer
anytizer / lampp-alias.sh
Created May 27, 2016 19:42
After installing XAMPP on Linux Platforms; run these scripts to access mysql, mysqldump and php
#!/bin/bash
ln -s /opt/lampp/bin/mysql /usr/local/bin/mysql
ln -s /opt/lampp/bin/mysqldump /usr/local/bin/mysqldump
ln -s /opt/lampp/bin/php /usr/local/bin/php
ln -s /opt/lampp/lampp /usr/local/bin/lampp
@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);