Skip to content

Instantly share code, notes, and snippets.

@sbalay
sbalay / prerender_startup.sh
Last active September 2, 2016 15:50
bash script to start prerender
#!/bin/bash
#Starts forever after boot through /etc/rc.local. Set the node version in the following script properly.
/home/<user>/.nvm/versions/node/<node version>/bin/forever start /home/<user>/<path to prerender>/server.js
@sbalay
sbalay / rc.local
Created September 2, 2016 15:51
Startup script to launch prerender
#!/bin/sh -e
sleep 2
su - ubuntu -c /home/ubuntu/prerender_startup.sh
exit 0
@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 / 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 / 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 / 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 January 26, 2017 20:12
import React from 'react';
import { reduxForm, Field } from 'redux-form';
import { ScrollView, Text } from 'react-native';
import MyTextInput from './MyTextInput';
function MyForm() {
return (
<ScrollView keyboardShouldPersistTaps={'handled'}>
<Text>Email</Text>
@sbalay
sbalay / MyTextInput.js
Last active January 26, 2017 20:12
React Native's TextInput wrapper to be used with redux-form
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, ...inputProps } = props;
return (
@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 / nginx
Last active March 14, 2018 11:16
prerender nginx config
server {
listen 80;
root /home/yourusername/www/mysite;
location / {
try_files $uri @prerender;
}
location @prerender {