Skip to content

Instantly share code, notes, and snippets.

@lricoy
lricoy / defaultValues.js
Created March 23, 2016 01:47
ES2015 default values
function f(x, y=12) {
// y é 12 se não passado (ou passado como undefined)
return x + y;
}
f(3) == 15
@lricoy
lricoy / letConst.js
Created March 23, 2016 01:48
ES2015 let and const
function f() {
{
let x;
{
// ok, declarado no escopo
const x = "sneaky";
// erro, o valor é uma constante
x = "foo";
}
// ok, declarado com `let` no escopo atual (linha 3)
@lricoy
lricoy / rest.js
Created March 23, 2016 01:49
ES2015 Rest
function f(x, ...y) {
// y é um vetor. y[0] === 'hello', y[1] === true
return x * y.length;
}
f(3, "hello", true) == 6
@lricoy
lricoy / spread.js
Created March 23, 2016 01:51
ES2015 Spread
function f(x, y, z) {
// x === 1, y === 2, z === 3
return x + y + z;
}
// Passa cada elemento do vetor como um argumento
f(...[1,2,3]) == 6
@lricoy
lricoy / templateString.js
Created March 23, 2016 01:51
ES2015 Template String
// Criação de string literal básica (Basic literal string creation)
// Reparem que não é apóstofre (aspas simples) ou aspas, mas o ascento grave (`)
`This is a pretty little template string.`
// String de linhas múltiplas (Multiline strings)
`In ES5 this is
not legal.`
// Interpolação de variáveis (Interpolate variable bindings)
// Muito parecido com string.format do python
@lricoy
lricoy / strTempalte.js
Last active March 24, 2016 15:07
Template format to format values like ${value[0:2]}
/**
* Formats a URI using a context and a given RexExp
* The default format is {value[0:20]} and the [0:2] is optional and represent a value.slice(0,2)
* @param {string} URI The URI to be replace
* @param {object} context The given context to work the lookup. e.g: {value: 'MY VALUE TO REPLACE'}
* @param {RegExp} The regex to find the ocurrences on the URI
*/
function formatCustomURI(URI, context, reg) {
URI = URI || '[0:2]\n\n{val[0:2]} \n{valor[0:2]}\n\nlucas\n${}\n$[]';
@lricoy
lricoy / obtemUrl.js
Last active March 30, 2016 04:20
Utiliza o SDK da amazon para obter URL's assinadas
'use strict';
/*
* Importa as dependências necessárias
*/
let express = require('express'),
http = require('http'),
path = require('path'),
aws = require('aws-sdk');
@lricoy
lricoy / formUpload.html
Last active March 30, 2016 04:19
Formulário para upload direto para o S3
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.2/angular.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/danialfarid-angular-file-upload/12.0.4/ng-file-upload-all.js"></script>
</head>
<body>
<h1>S3 Direct Upload</h1>
@lricoy
lricoy / app.ts
Last active January 11, 2017 14:10
Simple Angular2/Ionic2 auth
//TODO: Validar os operadores necessários para diminuir o tamanho
import 'rxjs/Rx';
import {App, Platform} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {LoginPage} from './pages/login/login';
import {HttpClient} from "./common/providers/http";
@lricoy
lricoy / login.ts
Created April 13, 2016 04:50
Login page with form Ionic2
import {Page} from 'ionic-angular';
import {FormBuilder, Validators, ControlGroup} from 'angular2/common';
import {ValidationService} from "./validation.service";
import {ControlMessages} from "./control-messages.component";
@Page({
templateUrl: 'build/pages/login/login.html',
directives: [ControlMessages]
})
export class LoginPage {