Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sbalay
sbalay / s3-deploy.sh
Created August 21, 2018 18:03
Script to upload content to S3
#!/bin/bash
# $1 bucket-name
# $2 env
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
@sbalay
sbalay / express-validator-example.js
Created June 5, 2018 15:35
Express validator example
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 June 19, 2017 05:30
Videojs example
<!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 June 19, 2017 05:10
Videojs hls example
<!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 July 11, 2022 05:02
Redux-form example with normalize and format
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 January 26, 2017 20:09
Async validations example of redux form
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 January 26, 2017 00:15
Field level validations with redux-form
<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 January 26, 2017 00:01
Form level validations with redux form
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 January 26, 2017 20:11
React Native's TextInput wrapper to be used with redux-form Field component
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 December 14, 2023 15:50
React Native form, meant to be used with redux-form HOC
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'];