Skip to content

Instantly share code, notes, and snippets.

@rogersguedes
rogersguedes / unbloking.php
Last active July 13, 2017 15:52
The snippet show how to release the HTTP client connection in a PHP script.
<?php
/*
* Workaround to release client connection and still running the script
* Thanks to DeveloperGuy2000, crmalibu, logic_earth and printf at
* http://www.sitepoint.com <http://www.sitepoint.com/forums/showthread.php?602206-Any-way-for-PHP-to-tell-apache-to-close-the-connection-with-user-but-still-run-script>
*/
ignore_user_abort ( true );
set_time_limit ( 0 );
header ('Content-Type: text/html; charset=UTF-8');
@rogersguedes
rogersguedes / app_console.php
Created August 11, 2017 20:06
Codeigniter Method for Doctrine console
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
use Symfony\Component\Console\Input;
class app_console extends CI_Controller{
public function __construct(){
parent::__construct();
}
public function doctrine() {
$this->load->database();
@rogersguedes
rogersguedes / Sessions.php
Created August 12, 2017 17:51
CodeIgniter 3 Session Doctrine 2 Entity
<?php
/**
* @Entity
* @Table(name="sessions", indexes={@index(name="sessions_timestamp", columns={"timestamp"})})
*/
class Sessions
{
/**
* @Id
* @Column(name="id", type="string", length=40)
@rogersguedes
rogersguedes / doctrine_migration_versions.sql
Created August 13, 2017 23:30
Dortine 2 Migrations Table DDL
CREATE TABLE doctrine_migration_versions (
version VARCHAR(255) NOT NULL,
PRIMARY KEY(version)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB;
@rogersguedes
rogersguedes / unvar_dump.php
Created October 10, 2017 23:53
PHP reverse var_dump function
<?php
/*
* thanks to
* - https://stackoverflow.com/questions/3531857/convert-var-dump-of-array-back-to-array-variable
* - https://stackoverflow.com/questions/2853454/php-unserialize-fails-with-non-encoded-characters
*/
function unvar_dump($str) {
if (strpos($str, "\n") === false) {
//Add new lines:
$regex = array(
<?php
function array_traverse (&$array, $function, $limit=2, $truncate=true) {
foreach ($array as $key => &$value) {
if (is_array($value)) {
if ($limit > 0) {
array_traverse($value, $function, --$limit, $truncate);
} else {
if ($truncate) {
$value = '{truncated}';
}
<?php
// Thanks to https://stackoverflow.com/questions/1993721/how-to-convert-camelcase-to-camel-case
function str_camel_case($input) {
preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
$ret = $matches[0];
foreach ($ret as &$match) {
$match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
}
return implode('_', $ret);
}
Resource Pure GitHub DokuWiki
Italic _{text}_ _{text}_ //{text}//
Bold **{text}** **{text}**
Underline __{text}__
Header #{1,6} {text} (={1,6}) {text} (={1,6})
@rogersguedes
rogersguedes / set_paths.lua
Created March 30, 2018 11:14
Lua snippet to load local folder luarocks libs
-- local version = _VERSION:match("%d+%.%d+") -- Lua >= 5.2
module("version", package.seeall) -- Lua 5.1
version = _VERSION:match("%d+%.%d+")
package.path = 'lua_modules/share/lua/' .. version .. '/?.lua;lua_modules/share/lua/' .. version .. '/?/init.lua;' .. package.path
package.cpath = 'lua_modules/lib/lua/' .. version .. '/?.so;' .. package.cpath
@rogersguedes
rogersguedes / aliexDateTime.php
Created April 1, 2018 16:23
Get date from Aliexpress datetime string.
<?php
$date = DateTime::createFromFormat('H:i M. j Y', '14:16 Nov. 04 2017');
echo $date->format('Y-m-d H:i');