Skip to content

Instantly share code, notes, and snippets.

View brendomaciel's full-sized avatar

Brendo Maciel brendomaciel

  • Else Consultoria
  • Brazil
View GitHub Profile
@brendomaciel
brendomaciel / javascript_stranger_things.md
Last active November 6, 2016 01:06
JavaScript "Stranger Things"

JavaScript "Stranger Things"

O JavaScript possui uma série de curiosidades em relação a algumas instruções. Portanto, tome cuidado se precisar utilizar qualquer uma dessas instruções listadas abaixo.

0.1 + 0.2 == 0.3 // false

1 / 0 // Infinity
@brendomaciel
brendomaciel / merge_white_spaces.php
Last active October 13, 2016 22:22
Função para mesclar múltiplos espaços, quebras de linhas ou tabs em um único espaço.
<?php
function merge_white_spaces($string) {
// Remove multiple line breaks
$string = preg_replace("/[\n\r]{3,}|[\r\n]{3,}|[\n]{3,}|[\r]{3,}/", PHP_EOL . PHP_EOL, $description);
// Remove tabs
$string = preg_replace("/\t+/", "", $description);
// Remove multiple spaces (the character " " is used instead \s because the second removes line breaks too)
@brendomaciel
brendomaciel / limit_string.js
Created October 11, 2016 20:47
Function to limit a string.
String.prototype.limit = function(size, cutWord, suspensionPoints) {
var str = this;
cutWord = typeof cutWord == "undefined" ? true : cutWord;
if (typeof size == "number" && size > 0 && str.length >= size) {
str = str.substr(0, size);
if (!cutWord) {
str = str.substr(0, Math.min(str.length, str.lastIndexOf(" ")));
@brendomaciel
brendomaciel / next_days.php
Last active September 22, 2016 03:15
Função para retornar um conjunto de datas de dias específicos $days — a partir da data atual — com tamanho $limit.
<?php
function get_week_by_date($date) {
$date = strtotime($date);
$week_position = date('w', $date);
// Seeking sunday
$sunday = ($week_position == 0) ? $date : strtotime('last sunday', $date);
@brendomaciel
brendomaciel / uuid_mysql.sql
Created August 20, 2016 13:18
Trigger para gerar um UUID no momento da inserção de uma linha em 'table'
DELIMITER $$
USE `database` $$
DROP TRIGGER IF EXISTS `set_uuid` $$
CREATE DEFINER = CURRENT_USER
TRIGGER `set_uuid`
BEFORE INSERT ON `table`
FOR EACH ROW
BEGIN