Skip to content

Instantly share code, notes, and snippets.

View paulofreitas's full-sized avatar

Paulo Freitas paulofreitas

View GitHub Profile
#!/usr/bin/env python
def matrix(n, i):
assert i < n
for j in range(n):
yield j + 1 + (i * n)
n = 10000
search_n = 50000
@paulofreitas
paulofreitas / AbstractEloquentRepository.php
Created May 2, 2014 18:33
AbstractEloquentRepository
<?php
use Illuminate\Support\Collection;
abstract class AbstractEloquent implements BaseRepositoryInterface
{
/**
* Model repository.
*/
protected $resource;

AbstractSanitizer.php

<?php

abstract class AbstractSanitizer
{
    protected $sanitizers = [];

    public function sanitize($data)
    {
<?php
$env = $app->detectEnvironment(function () {
$env_files = glob(__DIR__ . '/../.env.*.php');
if (count($env_files)) {
list($env) = sscanf(basename(current($env_files)), '.env.%[^.].php');
return $env;
}
@paulofreitas
paulofreitas / birthdays.php
Created February 20, 2016 02:42
Working with birthdays using Carbon
<?php
/*
* HOW TO TEST:
* composer require illuminate/support nestbot/carbon fzaninotto/faker
*/
require 'vendor/autoload.php';
date_default_timezone_set('America/Sao_Paulo');
header('Content-Type: text/plain');
<?php
/**
* Laravel trait to allow aliasing table fields.
*
* @author Paulo Freitas <me@paulofreitas.me>
*/
namespace App;
<?php
use Carbon\Carbon;
class DateUtils extends Carbon
{
public function isSameWeek(Carbon $dt)
{
return $this->weekOfYear === $dt->weekOfYear;
}
@paulofreitas
paulofreitas / transposing_form_input.php
Last active February 22, 2017 05:41
Laravel collection macro to transpose form data extracted from Refactoring to Collections book
<?php
/* Transpose Macro */
Collection::macro('transpose', function () {
$items = array_map(function (...$items) {
return $items;
}, ...$this->values());
return new static($items);
});
<?php
class GeoJSON
{
public function __construct(string $geojson)
{
$this->_struct = json_decode($geojson);
}
public static function fromString(string $geojson)
@paulofreitas
paulofreitas / oss-contributions.md
Last active September 22, 2017 15:23
My open-source contributions

My open-source contributions

Bugs/issues reported, pull requests contributed and stuff like that, pushed here and there.

72 contributions so far: