Skip to content

Instantly share code, notes, and snippets.

View helloncanella's full-sized avatar

Hellon Canella helloncanella

  • Peats GmbH
  • Rio de Janeiro
View GitHub Profile
@helloncanella
helloncanella / geolocationToPixel.js
Created April 29, 2017 20:39
Converting geolocation to pixel in the aps api
geolocationToPixel({ lat, lng }) {
const bounds = this.map.getBounds()
const geolocation = new google.maps.LatLng({ lat, lng })
, topRight = this.map.getProjection().fromLatLngToPoint(bounds.getNorthEast())
, bottomLeft = this.map.getProjection().fromLatLngToPoint(bounds.getSouthWest())
, scale = Math.pow(2, this.map.getZoom())
, worldPoint = this.map.getProjection().fromLatLngToPoint(geolocation)
return new google.maps.Point((worldPoint.x - bottomLeft.x) * scale, (worldPoint.y - topRight.y) * scale)
function processarFormulario(evento){
evento.preventDefault()
/*codigo para validacao*/
}
var form = document.querySelector('form')
form.addEventListener('submit', processarFormulario)

#dfjasdf

@helloncanella
helloncanella / Form.jsx
Last active March 19, 2017 21:31
New form version
import React, { Component } from 'react'
class Form extends Component {
constructor() {
super()
this.onSubmit = this.onSubmit.bind(this)
}
//public method
getData() {
@helloncanella
helloncanella / FieldsetsValidator.jsx
Created March 19, 2017 21:28
Auxilialiary class to validate fields
import fieldsets from './fieldsets.js'
class FieldsetsValidator {
verifyIfThereIsInputEmpty(fieldsetsData) {
let inputsData = []
fieldsetsData.forEach(({ inputs }) => {
for (let name in inputs) {
if (!inputs[name]) throw 'one or more fields are empty'
@helloncanella
helloncanella / fieldsets.js
Created March 19, 2017 21:27
Instructions to render a group of fieldsets
const validateEmail = ({ email }) => {
const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!regex.test(email)) throw 'email format is not correct!'
}
const validatePasswords = ({ password, confirmation }) => {
if (password !== confirmation) throw 'passwords do not match!'
}
const validateUsername = ({ username }) => {
import React, { Component } from 'react'
import Form from './Form.jsx'
import fieldsets from './fieldsets.js'
import FieldsetsValidator from './fieldsets-validator.js'
import './style.scss'
class FormWrapper extends Component {
constructor() {
super()
import React, { Component } from 'react'
import './style.scss'
class Form extends Component {
constructor() {
super()
this.state = {
sentData: false
}
this.validateFields = this.validateFields.bind(this)
@helloncanella
helloncanella / FormUnrefactored.jsx
Created March 19, 2017 21:22
Raw version of a minimalist form
import React, { Component } from 'react'
import './style.scss'
export default class Form extends Component {
constructor() {
super()
this.state = {
sentData: false
}
this.validateFields = this.validateFields.bind(this)
@helloncanella
helloncanella / flatten-short.js
Last active February 4, 2017 22:02
short version of flatten.js
function flatten(A){
return A.reduce((previous, current) =>{
if(Array.isArray(current)) current = flatten(current)
return previous.concat(current)
}, [])
}