Skip to content

Instantly share code, notes, and snippets.

View antoniojps's full-sized avatar
🐬
Always learning

António Santos antoniojps

🐬
Always learning
View GitHub Profile
@antoniojps
antoniojps / es6-modules.js
Last active June 8, 2017 04:59
ES6 Modules
/*
Ficheiro: exported.js
*/
export const dataNascimento = '1996-08-15'// Apenas uma variavel/func o que for
export function idade(){
return (new Date().getFullYear() - dataNascimento)
}
// Ou tudo numa linha, estamos a exportar um objecto com todas as propriedades seleccionadas
/*
A promise is created with a resolve and reject function being
passed as arguments. Depending on the result, the appropriate function is
executed and a possible return value is passed as an argument.
*/
let promise = new Promise((resolve,reject)=>{
// then(func)
resolve('Ola!')
@antoniojps
antoniojps / php-oop.php
Last active June 13, 2017 19:37
PHP OOP
// OBJECT ORIENTED PROGRAMMING PHP
// Constructor de objecto = class
// Propriedades e Metodos (funcoes)
class Person{
public $name;
public $email;
}
@antoniojps
antoniojps / jwt.js
Last active June 8, 2017 05:00
JWT - Json Web To
// JSON WEB TOKEN
// A JSON Web Token (JWT) is a JSON object that is defined in RFC 7519 as a safe way to represent a set of information between two parties. The token is composed of a header, a payload, and a signature.
// Formula:
data = base64urlEncode( header ) + “.” + base64urlEncode( payload )
signature = Hash( data, secret );
// Standard fields:
// Issuer (iss) - identifies principal that issued the JWT;
@antoniojps
antoniojps / composer-php.php
Last active June 8, 2017 05:01
Composer PHP
// iniciar composer e criar composer.json
composer init
// instalar dependecias
composer require nomeda/dependencia || composer require-dev nomeda/dependencia
composer install || composer update
// dump dos autoloads
composer dumpautoload
@antoniojps
antoniojps / vue-props.js
Created May 9, 2017 22:48
Props Vue JS - From https://vuejs.org/v2/guide/components.html Passar dados p um componente
// JS
Vue.component('child', {
// camelCase in JavaScript
props: ['myMessage'],
template: '<span>{{ myMessage }}</span>'
})
// HTML
<!-- kebab-case in HTML --> <child my-message="hello!"></child>
// This will render the same result. We can also bind to a computed property that returns an object. This is a common and powerful pattern:
// HTML
<div v-bind:class="classObject"></div>
// JS
data: {
isActive: true, error
:
null
}
@antoniojps
antoniojps / call-apply-bind.js
Created April 9, 2017 15:01
Javascript: Call, Apply e Bind
var obj = {
name: 'John Doe',
greet () {
console.log(`Hey ${this.name}`);
}
};
obj.greet(); // Hey John Doe
@antoniojps
antoniojps / node-emitter.js
Created April 9, 2017 14:43
Node JS Emitter
// Emitter.js
// function constructor for event
function Emitter() {
this.events = {};
}
// prototype method to add listener (array of functions)
Emitter.prototype.on = function (type, listener) {
this.events[type] = this.events[type] || [];
this.events[type].push(listener);
$url = 'http://server.com/path';
$data = array('key1' => 'value1', 'key2' => 'value2');
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)