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 / 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 / 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 / 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
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 / 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 / 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 / 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) {