Skip to content

Instantly share code, notes, and snippets.

View sayhicoelho's full-sized avatar
🏠
Working from home

Renan Coelho sayhicoelho

🏠
Working from home
View GitHub Profile
@sayhicoelho
sayhicoelho / replace_between.php
Created June 22, 2017 00:47
Replace string between
<?php
function replace_between($str, $needle_start, $needle_end, $replacement = '')
{
return preg_replace('/' . $needle_start . '.+?' . $needle_end . '/sm', $replacement, $str);
}
@sayhicoelho
sayhicoelho / strtocamel.php
Created June 22, 2017 00:47
String to CamelCase
<?php
function strtocamel($str, $separator = '_', $replace = true)
{
return str_replace($separator, $replace ? '' : $separator, ucwords($str, $separator));
}
@sayhicoelho
sayhicoelho / strtosnake.php
Created June 22, 2017 00:48
String to snake_case
<?php
function strtosnake($str)
{
return ltrim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $str)), '_');
}
@sayhicoelho
sayhicoelho / cnpj.js
Last active July 5, 2018 05:08
Consulta dados de uma empresa com seu CNPJ.
// Este script requer a função selectBoxByText do arquivo sayhicoelho/utils.js
// https://gist.github.com/sayhicoelho/be058ba559cba22b207a64c1113ff1bf
$(function () {
var request;
var timeout;
var campos = [
'razao_social',
@sayhicoelho
sayhicoelho / cep.js
Last active July 5, 2018 05:08
Consulta dados de um endereço com seu CEP.
// Este script requer a função selectBoxByText do arquivo sayhicoelho/utils.js
// https://gist.github.com/sayhicoelho/be058ba559cba22b207a64c1113ff1bf
$(function () {
var request;
var timeout;
var campos = [
'logradouro',
@sayhicoelho
sayhicoelho / utils.js
Last active July 5, 2018 05:07
Funções, prototypes e utilidades Javascript.
// Remove um elemento de um array pelo seu valor
Array.prototype.remove = function () {
var what, a = arguments, L = a.length, ax;
while (L && this.length) {
what = a[--L];
while ((ax = this.indexOf(what)) !== -1) {
this.splice(ax, 1);
}
}
return this;
@sayhicoelho
sayhicoelho / functions.php
Last active July 5, 2018 05:07
Funções e utilidades PHP
<?php
/**
* Replace all non-number characters
*
* @param string $str
* @return string
*/
function only_number($str)
{
@sayhicoelho
sayhicoelho / libs.js
Last active July 5, 2018 05:05
Configura bibliotecas Javascript mais utilizadas.
$(function () {
// FastClick
// https://github.com/ftlabs/fastclick
FastClick.attach(document.body);
// Stellar
// http://markdalgleish.com/projects/stellar.js/
// Utilize o atributo data-stellar-background-ratio="0.5" no elemento que desejar o efeito parallax
$.stellar({
horizontalScrolling: false,
@sayhicoelho
sayhicoelho / CheckRole.php
Last active November 3, 2017 19:21
Trait to manage user ACL
<?php
namespace App\Traits;
trait CheckRole
{
/**
* The roles that belong to the user.
*/
public function roles()
@sayhicoelho
sayhicoelho / FacebookPageInvite.js
Last active October 19, 2017 00:36
Facebook: Invite your friends to like a Page
var list = document.getElementsByClassName('lists')[0];
var min = 500; // ms
var max = 1500; // ms
var time = min;
var interval;
var timeout;
var invited = 0;
var limit = 999;
var stop = false;