This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RUN THIS IN A NODE CONSOLE | |
let callTimes = 0; | |
function fibonacci(n) { | |
callTimes++; | |
switch(n) { | |
case 0: | |
return 0; | |
case 1: | |
return 1; | |
default: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
putenv("APP_LANG=es_MX.utf8"); | |
require_once('i18n.php'); | |
class Person | |
{ | |
const VERSION = '1.0.0'; | |
public $firstName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use \InvalidArgumentException as InvalidArgumentException; | |
/** | |
* This class contain helper methods to localize and translate the application. | |
*/ | |
class I18n | |
{ | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('i18n.php'); | |
use function Helpers\I18n\translate; | |
class Person | |
{ | |
const VERSION = '1.0.0'; | |
public $firstName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Person | |
{ | |
const VERSION = '1.0.0'; | |
public $firstName; | |
public $lastName; | |
public $dob; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# service name hints that it does | |
class CreateUserService | |
# default attributes that all services should have | |
attr_reader :errors, :messages, :output | |
# custom attributes for what this service does | |
attr_reader :user, :send_email | |
# we receive all parameters in the initialization | |
def initialize(user:, send_email: true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TokenProvider | |
def self.generate(email) | |
uri = URI("https://example.com/#{email}") | |
response = Net::HTTP.get_response(uri) | |
if response.code == '200' | |
return JSON.parse(response.body)[:token] | |
end | |
end | |
end |
NewerOlder