Skip to content

Instantly share code, notes, and snippets.

View randolphledesma's full-sized avatar

Randolph Ledesma randolphledesma

  • Zylun
  • Cebu City
View GitHub Profile
@randolphledesma
randolphledesma / phplinterror.sh
Last active August 31, 2016 20:32
Recursive PHP Lint script
#!/bin/bash
find . -type f -name '*.php' -exec php -l {} \; | grep -v "No syntax errors detected"
@randolphledesma
randolphledesma / git aliases
Last active September 6, 2017 05:05
Useful git shortcuts
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.hist "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"
git config --global alias.type 'cat-file -t'
git config --global alias.dump 'cat-file -p'
git config --global alias.mg 'merge --no-ff'
git config --global alias.brdate 'branch --sort=-committerdate'
git config --global alias.mgm 'merge --no-ff --no-commit'
@randolphledesma
randolphledesma / MY_Profiler.php
Last active January 18, 2018 01:05
CodeIgniter 2.x Profiler
<?php
//For codeigniter 2.x
class MY_Profiler extends CI_Profiler {
public function run()
{
$output = parent::run();
// log output here, and optionally return it if you do want it to display
file_put_contents('/tmp/' . str_replace('/', '_', $_SERVER['REQUEST_URI']) . '.html', $output);
@randolphledesma
randolphledesma / parallel_php_lint.sh
Created September 27, 2016 20:42
Parallel Execution to Recursively PHP Lint a directory
#!/bin/bash
find . -name "*.php" -print0 | xargs -0 -n1 -P4 php -l | grep -v 'No syntax errors'
@randolphledesma
randolphledesma / curl_commands.sh
Created January 20, 2017 19:15
List of usable curl commands
#Fetch resource header information
curl -s -I http://www.google.com/uploads/media/768696526.mp3
@randolphledesma
randolphledesma / execute_background_task.php
Last active January 18, 2018 01:03
PHP: execute script on background
<?php
$command = 'nohup >/dev/null 2>&1 /your/background/script.php &'
exec($command);
@randolphledesma
randolphledesma / snippet.php
Last active January 18, 2018 01:01
Remove zero-width space
<?php
$email = ""; //set some email here
$email = str_replace("\xE2\x80\x8B", '', $email);
@randolphledesma
randolphledesma / db_pooling.notes.txt
Last active January 18, 2018 01:00
DB Connection pool
Connection pools decorate Connection and Statement instances with their own wrapper implementations.
When you call close on a connection you are actually just releasing it back to the pool.
When you call close on a prepared statement you are actually just releasing it back to the connection's statement cache.
When you prepare a statement you might just be fetching a cached statement instance from the connection.
All this is hidden from view so that you don't have to worry about it.
When a connection is given to a client it is no longer available for any other client to use until the connection is released back to the pool.
You generally just fetch connections when you need them and then return them as soon as you are finished with them.
Because the connections are being held open in the pool there is little overhead in fetching and releasing connections.
@randolphledesma
randolphledesma / locate_function.php
Last active January 18, 2018 00:59
PHP: find out where a function is defined
<?php
$reflFunc = new ReflectionFunction('decode');
print $reflFunc->getFileName() . ':' . $reflFunc->getStartLine();
@randolphledesma
randolphledesma / error_reporting.php
Last active January 18, 2018 00:58
PHP error reporting
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
ini_set('error_reporting', E_ALL ^ E_DEPRECATED);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);