Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am paulofreitas on github.
  • I am paulofreitass (https://keybase.io/paulofreitass) on keybase.
  • I have a public key ASB7AILhT0J-sojxvGL7WGx81WH-wBn9xCWDeA3Euy5e-Qo

To claim this, I am signing this object:

View singleton.py
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
key = (cls, args, str(kwargs))
if key not in cls._instances:
cls._instances[key] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[key]
View totp.py
#!/usr/bin/env python3
import argparse
from pyotp import totp # pip3 install pytotp
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('key')
args = parser.parse_args()
print(totp.TOTP(args.key).now())
View vhost.conf
server {
listen 80;
server_name domain.com www.domain.com;
root /home/username/domain.com/public;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf-8;
View chroot-jail.md

Instructions

Install SSH server

sudo apt-get install openssh-server

Create SFTP group

groupadd sftp
View wait_until.php
<?php
class TimeoutException extends RuntimeException
{
//
}
function wait_until(callable $callback, $seconds)
{
declare(ticks = 1);
View namespace_path.php
<?php
function namespace_path($namespace)
{
try {
return (new ReflectionClass($namespace))->getFileName();
} catch (ReflectionException $e) {
$autoloader = require base_path('vendor/autoload.php');
$namespaceParts = array_filter(explode('\\', $namespace));
$namespacePrefix = array_shift($namespaceParts) . '\\';
View 403.blade.php
@extends('errors::layout')
@section('title', __('Unauthorized'))
@section('message', __($exception->getMessage()))
@paulofreitas
paulofreitas / AuthServiceProvider.php
Last active May 26, 2022
Extending the default Eloquent User Provider (Laravel 5.4+)
View AuthServiceProvider.php
<?php
namespace App\Providers;
use App\Auth\UserProvider;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
@paulofreitas
paulofreitas / custom-paginator.md
Last active Mar 2, 2020
Custom Google-like length-aware paginator for Laravel 5.4+
View custom-paginator.md
  • Save the helpers.php file in your app directory
  • Edit your composer.json manifest file to auloload this file:
    "autoload": {
        "files": [
            "app/helpers.php"
        ],
    // ...