Skip to content

Instantly share code, notes, and snippets.

View gusrub's full-sized avatar
🏠
Working from home

Gustavo Rubio gusrub

🏠
Working from home
View GitHub Profile
class UsersController < ApplicationController
def create
service = CreateUserService.new(@user, params[:send_email])
if service.perform
render json: service.output, status: 200
else
render json service.errors, status: 400
end
end
class UsersController < ApplicationController
def create
service = CreateUserService.new(@user, params[:send_email])
if service.perform
render json: service.output, status: 200
else
render json service.errors, status: 400
end
end
@gusrub
gusrub / index.php
Last active April 16, 2018 07:21
Internationalization PHP 1
<?php
class Person
{
const VERSION = '1.0.0';
public $firstName;
public $lastName;
public $dob;
@gusrub
gusrub / i18n.php
Created April 26, 2018 03:56
I18n helper
<?php
namespace Helpers\I18n {
// I18N support information here
$language = 'es_MX.utf8';
putenv("LC_ALL=$language");
putenv("LC_LANG=$language");
setlocale(LC_ALL, $language);
// // Set the text domain as 'messages'
@gusrub
gusrub / index.php
Created April 26, 2018 04:00
Encapsulating translation
<?php
require_once('i18n.php');
use function Helpers\I18n\translate;
class Person
{
const VERSION = '1.0.0';
public $firstName;
@gusrub
gusrub / i18n.php
Created April 26, 2018 04:23
i18n translation class
<?php
use \InvalidArgumentException as InvalidArgumentException;
/**
* This class contain helper methods to localize and translate the application.
*/
class I18n
{
/**
@gusrub
gusrub / index.php
Created April 26, 2018 04:28
Keyword arguments for translation PHP
<?php
putenv("APP_LANG=es_MX.utf8");
require_once('i18n.php');
class Person
{
const VERSION = '1.0.0';
public $firstName;
// RUN THIS IN A NODE CONSOLE
let callTimes = 0;
function fibonacci(n) {
callTimes++;
switch(n) {
case 0:
return 0;
case 1:
return 1;
default: