Skip to content

Instantly share code, notes, and snippets.

View jackmakiyama's full-sized avatar

Jack Makiyama jackmakiyama

View GitHub Profile
@jackmakiyama
jackmakiyama / .zshrc
Created September 23, 2020 19:18 — forked from dimitardanailov/.zshrc
My personal zsh and tmux configurations
# Path to your oh-my-zsh installation.
export ZSH=/Users/dimitar.danailov/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
# ZSH_THEME="robbyrussell"
ZSH_THEME="agnoster"
@jackmakiyama
jackmakiyama / docker_aliases.sh
Created August 26, 2020 01:50
PHP Docker Aliases
#!/bin/sh
# PHP7
alias php7d='docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.0-cli php'
# Composer
alias composerd='docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp composer'
@jackmakiyama
jackmakiyama / custom-respect-validation-rules.md
Created May 28, 2018 15:59 — forked from augustohp/custom-respect-validation-rules.md
How to create custom Respect\Validation rules.

Custom rules on Respect/Validation

You may not know that [the most awesome validation engine for PHP][1] out there is [Respect/Validation][2]. If you do, this is tailored for you!

All rules on [Respect/Validation][2] are meant to be used together, composing a more complex validation rule that is closer to the domain of your application than the existing ones, let's try an example:

@jackmakiyama
jackmakiyama / MY_Security.php
Created September 19, 2017 16:33 — forked from CMCDragonkai/MY_Security.php
PHP: Codeigniter CSRF functionality does not support putting the CSRF token in the HTTP headers for the purposes of the double submit cookie method. It also only runs the CSRF check on POST and not on PUT or DELETE. This drop in MY_Security.php makes sure CSRF runs on POST, PUT or DELETE and checks the HTTP headers for X-XSRF-TOKEN recommended b…
<?php
class MY_Security extends CI_Security{
//overriding the normal csrf_verify, this gets automatically called in the Input library's constructor
//verifying on POST and PUT and DELETE
public function csrf_verify(){
$request_method = strtoupper($_SERVER['REQUEST_METHOD']);
FROM php:7-apache
RUN buildDeps="libpq-dev libzip-dev libicu-dev" && \
apt-get update && \
apt-get install -y $buildDeps --no-install-recommends && \
rm -rf /var/lib/apt/lists/* && \
docker-php-ext-install \
mysqli \
pdo_mysql \
mbstring \

Refatorando Condicionais: função switch.

Nesse caso do uso indevido da função switch, pode ser refatorada sem mesmo usar condicionais.

Em meio aos códigos legados de um projeto que trabalho encontrei esse fragmento de código:

<?php

function status($statusId)

Manipulando números com a classe NumberFormatter

Trabalhar com números é muito comum em nossa área e em algum momento de nossa jornada vamos pegar uma aplicação marota que será necessário uma alta manipulação de números, moedas ou até mesmo escrever um numero safado por extenso.

O PHP em si tem uma penca de funções que ajuda a tratar isso, apesar de serem rápidos são bem chatas de se lembrar nomes e ter que fazer nós mesmo certas lógicas. Eu sempre achei isso um saco, pois não faz muito sentido termos que ficar definindo um monte de lógicas que alguma lib poderia fazer.

Pois bem, depois de anos fazendo isso no braço sempre que precisei, me deparo com a classe NumberFormatter que acompanha a extensão intl.

Algo que está documentado e por um acaso passou batido por mim e pelo jeito muitos ainda a desconhe

Lidando com Exceptions no Respect\Rest

Bem vindo! Esse é o primeiro-git-post de uma nova funcionalidade em um componente do Respect:

Suponha que você seja louco o suficiente para arquitetar uma API de Olá Mundo que randomicamente dispare Exceptions. Com o Respect/Rest isso ficaria assim:

<?php
$router = new Respect\Rest\Router;
@jackmakiyama
jackmakiyama / post-receive
Created April 4, 2016 18:25
Um post-receive hook para usar "git push deploy" na locaweb
#!/bin/bash
PHP=php56
PROJECT=project-name
HOME=/home/$PROJECT
APP=$HOME
GIT=$HOME/$PROJECT.git
cd $APP
@jackmakiyama
jackmakiyama / User.php
Created November 5, 2015 02:16 — forked from Ocramius/User.php
Doctrine 2 ManyToMany - the correct way
<?php
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity()
* @ORM\Table(name="user")
*/
class User