Skip to content

Instantly share code, notes, and snippets.

@sbalay
sbalay / s3-deploy.sh
Created Aug 21, 2018
Script to upload content to S3
View s3-deploy.sh
#!/bin/bash
# $1 bucket-name
# $2 env
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
View express-validator-example.js
const { checkSchema } = require('express-validator/check');
exports.validateCalculate = [
checkSchema({
product: {
in: ['query'],
errorMessage: 'product must be an integer',
exists: true,
isInt: { options: { min: 0 } },
toInt: true
@sbalay
sbalay / index.html
Created Jun 19, 2017
Videojs example
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>videojs-contrib-hls embed</title>
<!--
Uses the latest versions of video.js and videojs-contrib-hls.
@sbalay
sbalay / index.html
Created Jun 19, 2017
Videojs hls example
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>videojs-contrib-hls embed</title>
<!--
Uses the latest versions of video.js and videojs-contrib-hls.
@sbalay
sbalay / FormNormalizeAndFormatValues.js
Last active Jan 28, 2021
Redux-form example with normalize and format
View FormNormalizeAndFormatValues.js
import React from 'react';
import { reduxForm, Field } from 'redux-form';
import { ScrollView, Text, TouchableOpacity } from 'react-native';
import moment from 'moment';
import MyTextInput from './MyTextInput';
/**
* Automatically adds the dashes required by the specified phone format and limits the input to ten characters
*/
@sbalay
sbalay / AsyncValidation.js
Last active Jan 26, 2017
Async validations example of redux form
View AsyncValidation.js
export default reduxForm({
form: 'signIn',
asyncValidate: (values) => {
return new Promise((resolve, reject) => {
// simulate request
setTimeout(() => {
if (values.email.indexOf('@wolox.com') === -1) {
reject({ email: 'Only mails at wolox are allowed' });
} else {
resolve();
@sbalay
sbalay / FieldLevelValidation.js
Created Jan 26, 2017
Field level validations with redux-form
View FieldLevelValidation.js
<Field
name={'password'}
component={MyTextInput}
validate={[
(val) => val ? undefined : 'Password field is required',
(val) => val && val.length >= 8 ? undefined : 'Password must be at least 8 characters long'
]}
/>
@sbalay
sbalay / FormLevelValidation.js
Created Jan 26, 2017
Form level validations with redux form
View FormLevelValidation.js
export default reduxForm({
form: 'signIn',
validate: (values) => {
const errors = {};
errors.email = !values.email
? 'Email field is required'
: !emailRegex.test(values.email)
? 'Email format is invalid'
: undefined;
@sbalay
sbalay / MyTextInput.js
Last active Jan 26, 2017
React Native's TextInput wrapper to be used with redux-form Field component
View MyTextInput.js
import React from 'react';
import { TextInput, View, Text } from 'react-native';
/**
* to be wrapped with redux-form Field component
*/
export default function MyTextInput(props) {
const { input, meta, ...inputProps } = props;
const formStates = ['active', 'autofilled', 'asyncValidating', 'dirty', 'invalid', 'pristine',
@sbalay
sbalay / MyForm.js
Last active Feb 10, 2017
React Native form, meant to be used with redux-form HOC
View MyForm.js
import React from 'react';
import { reduxForm, Field } from 'redux-form';
import { ScrollView, Text, TouchableOpacity } from 'react-native';
import MyTextInput from './MyTextInput'
function MyForm(props) {
const formStates = ['asyncValidating', 'dirty', 'pristine', 'valid', 'invalid', 'submitting',
'submitSucceeded', 'submitFailed'];