Skip to content

Instantly share code, notes, and snippets.

@hertz1
hertz1 / UserRepository.php
Last active March 13, 2020 20:26
Laravel Lazy-Collections With Doctrine
<?php
namespace App\Repositories;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Internal\Hydration\IterableResult;
class UserRepository extends EntityRepository
{
public function getUsersIterable(): IterableResult
@hertz1
hertz1 / 20-intel.conf
Created June 22, 2018 20:19 — forked from k-lazarevv/20-intel.conf
Getting rid from screen tearing (Xfce on Intel Graphics)
# /etc/X11/xorg.conf.d/20-intel.conf
Section "Device"
Identifier "Intel Graphics"
Driver "intel"
Option "AccelMethod" "sna"
Option "DRI" "3"
Option "TearFree" "true"
EndSection
@hertz1
hertz1 / Microsoft.PowerShell_profile.ps1
Created May 19, 2018 21:56
Local PHP Composer Runtime for Docker Toolbox
function _composer
{
$composerTmpDir = 'C:\Users\MyUser\.tmp'
$path = $pwd -replace "^C:\\", "/c/" -replace "\\", "/"
$tmpPath = $composerTmpDir -replace "^C:\\", "/c/" -replace "\\", "/"
$composerArgs = $args -join " "
$command = "docker run --interactive --user `$(id -u):`$(id -g) --rm -v '$path':/app -v '$tmpPath':/tmp composer $composerArgs"
docker-machine ssh default $command
}
@hertz1
hertz1 / MultiplyByLastResult.php
Last active July 6, 2017 23:36
Multiplica um número pelo resultado da multiplicação anterior
<?php
/**
* Multiplica um número pelo resultado da multiplicação anterior.
* Exercício proposto pela página "Asolucoesweb" (http://bit.ly/2tS4qj2)
*
* @var integer $base O número a ser multiplicado
* @var integer $iterations O número de vezes a ser interado
* @var integer $multiplier O resultado da multiplicação anterior
* @var integer $count O quantidade de vezes já iteradas
@hertz1
hertz1 / range.js
Last active September 22, 2015 14:45
Implementation of python's range() function in javascript.
/**
* Range function, similar to python's one.
* If you want to use it in for...in loops, all 4 arguments must be passed.
* @param {Number} Start - If omited, it defaults to 0.
* @param {Number} Stop
* @param {Number} Step - If omited, it defaults to 1.
* @param {Boolean} Object - If returns an object or not. Mostly used in for...in loops.
* @return {Mixed} If Object is true, returns an object, otherwise, returns an array.
*
* Examples:
@hertz1
hertz1 / binomial.js
Last active September 22, 2015 00:53
Binomial function. Calculates the number of ways of picking k unordered from the given number of possibilities.
/**
* Calculates the number of ways of picking k unordered.
* @params {Interger}
* @return {Interger}
*/
function binomial(n, k) {
if (k === 0) {
return 1;
} else if (2*k > n) {
@hertz1
hertz1 / removerAcentos.js
Last active September 29, 2022 16:21
Função simples e eficiente para remover todos os tipos de acentos da língua portuguesa.
/**
* Remove acentos de strings
* @param {String} string acentuada
* @return {String} string sem acento
*/
var map={"â":"a","Â":"A","à":"a","À":"A","á":"a","Á":"A","ã":"a","Ã":"A","ê":"e","Ê":"E","è":"e","È":"E","é":"e","É":"E","î":"i","Î":"I","ì":"i","Ì":"I","í":"i","Í":"I","õ":"o","Õ":"O","ô":"o","Ô":"O","ò":"o","Ò":"O","ó":"o","Ó":"O","ü":"u","Ü":"U","û":"u","Û":"U","ú":"u","Ú":"U","ù":"u","Ù":"U","ç":"c","Ç":"C"};
function removerAcentos(s){ return s.replace(/[\W\[\] ]/g,function(a){return map[a]||a}) };