Skip to content

Instantly share code, notes, and snippets.

View igor822's full-sized avatar

Igor Carvalho igor822

  • Instafreight
  • Berlin
View GitHub Profile
@igor822
igor822 / Auto_increment
Created May 21, 2013 04:29
Simple create auto increment mongo
// Adding counter
db.counters.insert(
{
_id: "userid",
seq: 0
}
);
// function to add sequence
function getNextSequence(name) {
@igor822
igor822 / format_sku.sql
Last active December 20, 2015 03:39
Função no mysql para formatar qualquer campo string para sku
DROP FUNCTION IF EXISTS `format_sku`;
DELIMITER //
CREATE FUNCTION `format_sku`(`str` TEXT)
RETURNS text
LANGUAGE SQL
DETERMINISTIC
NO SQL
SQL SECURITY INVOKER
COMMENT ''
@igor822
igor822 / Convert DB to ORM Doctrine
Created August 2, 2013 19:30
Generate mapping and entities from source
// Convert Mapping
./vendor/doctrine/doctrine-module/bin/doctrine-module orm:convert-mapping --namespace="Application\\Entity\\" --force --from-database annotation ./module/Application/src/
// Add methods
./vendor/doctrine/doctrine-module/bin/doctrine-module orm:generate-entities ./module/Application/src/ --generate-annotations=true
@igor822
igor822 / Send error
Created August 12, 2013 14:30
Error Handler to send e-mail with fatal or parse errors of application
register_shutdown_function( "fatal_handler" );
function send_error($str = '') {
$Settings = array('auth' => 'login',
'ssl'=> 'ssl',
'port'=> '465',
'username' => 'username',
'password' => 'pass');
$transport = new Zend_Mail_Transport_Smtp('smtp.email.com',$Settings);
@igor822
igor822 / fibonacci function.php
Last active December 21, 2015 12:59
Sequência Fibonacci
<?php
function fibb($limit = 1, $first_number = 0, $second_number = 1) {
if ($limit <= 0) {
exit('End');
}
echo $second_number."\n";
fibb($limit-1, $second_number, ($first_number + $second_number));
}
@igor822
igor822 / Send error.php
Last active January 1, 2016 13:09
Send e-mail with last error occurred
<?php
function send_error($str = '') {
if (getEnvironment() == 'production') {
$return = null;
// Configuração de dados SMTP, a gosto do programador
$Settings = array('auth' => 'login',
'ssl'=> 'ssl',
'port'=> '465',
'username' => '[email protected]',
@igor822
igor822 / toSlug.js
Last active September 22, 2019 17:58
String to Slug
String.prototype.toSlug = function(){
str = this.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "ãàáäâèéëêìíïîõòóöôùúüûñç·/_,:;";
var to = "aaaaaeeeeiiiiooooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
@igor822
igor822 / phpunit_fedora.sh
Created February 12, 2014 12:28
Install PHPUnit with PEAR in Fedora 20
yum install php-pear
# Discovering all channels
pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com
pear channel-discover components.ez.no
# Install PHPUnit with Yaml
pear install pear.symfony.com/Yaml
pear install --alldeps pear.phpunit.de/PHPUnit
@igor822
igor822 / autoload.php
Created February 13, 2014 16:54
Simple autoload
<?php
if (!defined('BASE_PATH')) define('BASE_PATH', realpath(dirname(__FILE__))); // Root path folder to load classes
function autoloader($class_name) {
$class_name = ltrim($class_name, '\\');
$file_name = '';
$namespace = '';
if ($lastNsPos = strrpos($class_name, '\\')) {
$namespace = substr($class_name, 0, $lastNsPos);
$class_name = substr($class_name, $lastNsPos + 1);
@igor822
igor822 / Steps
Created March 10, 2014 14:39
Tutorial XDebug + PHPUnit + Sublime Text 3
Plugin: https://github.com/martomo/SublimeTextXdebug
Command: phpunit -d xdebug.profiler_enable=on -d xdebug.idekey=sublime.xdebug File.php
Configuration Xdebug:
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9000