Skip to content

Instantly share code, notes, and snippets.

View pavsidhu's full-sized avatar
🐧

Pav Sidhu pavsidhu

🐧
View GitHub Profile
@pavsidhu
pavsidhu / .bash_profile
Last active February 1, 2018 16:15
My personal .bash_profile
# Change Bash's autocomplete to be case insenstive
bind "set completion-ignore-case on"
# Fancy PS1
expressions=("👉" "🐙" "🐼" "🎉" "🏆" "👾" "🌍" "🏗️" "🗽" "🌚" "🔥" "💻" "💰" "✏️" "📌")
selectedexpression=${expressions[$RANDOM % ${#expressions[@]} ]}
export PS1="\e[38;5;208m$(echo $selectedexpression) PavSidhu:\W > \[$(tput sgr0)\]\[$(tput sgr0)\]"
# Git Aliases
alias g="git"
@pavsidhu
pavsidhu / validate_wrapper.js
Last active August 10, 2020 12:04
Validate.js with React Native wrapper
import validation from 'validation.js'
export default function validate(fieldName, value) {
// Validate.js validates your values as an object
// e.g. var form = {email: '[email protected]'}
// Line 8-9 creates an object based on the field name and field value
var formValues = {}
formValues[fieldName] = value
// Line 13-14 creates an temporary form with the validation fields
@pavsidhu
pavsidhu / form.jsx
Last active March 22, 2020 14:27
Validate.js with React Native Form Example
import React, {Component} from 'react'
import {View, Button} from 'react-native'
import TextField from 'textfield'
import validation from 'validation'
import validate from 'validation_wrapper'
export default class Form extends Component {
constructor(props) {
super(props)
@pavsidhu
pavsidhu / textfield.jsx
Last active January 28, 2020 11:13
Validate.js with React Native text input
import React from 'react'
import { View, TextInput, Text } from 'react-native'
const TextField = props => (
<View>
<TextInput/>
{props.error && <Text>{props.error}</Text>}
</View>
)
@pavsidhu
pavsidhu / validation.js
Last active January 2, 2018 22:30
Validate.js constraints
const validation = {
email: {
presence: {
message: '^Please enter an email address'
},
email: {
message: '^Please enter a valid email address'
}
},
@pavsidhu
pavsidhu / index.js
Last active January 29, 2017 11:46
Redux example
import React, {Component} from 'react'
import {AppRegistry} from 'react-native'
import {Provider} from 'react-redux'
import App from './app'
import configureStore from './store.js'
const store = configureStore()
class MyCounterApp extends Component {
@pavsidhu
pavsidhu / store.js
Last active January 29, 2017 11:40
Redux store example
import reducer from './reducer'
// This connects the reducer to the store
export default function configureStore() {
let store = createStore(
reducer
)
return store
}
@pavsidhu
pavsidhu / actions.js
Last active January 29, 2017 11:20
Redux action definition example
// We speciify the name of the action as a variable
const ADD_TO_COUNTER = 'ADD_TO_COUNTER'
// This is an action creator, it simply specifies the action.
// this is what we call to send an action.
export function addToCounter() {
return {
type: ADD_TO_COUNTER
}
}
@pavsidhu
pavsidhu / reducer.js
Last active January 29, 2017 11:41
Redux reducer example
import {ADD_TO_COUNTER} from './actions'
// This is the default state of the app i.e. when the app starts for the first time
const initialState = {
counter: 0
}
// This is a reducer which listens to actions and modifies the state
const reducer = (state = initialState, action) => {
// A switch is used since if more actions are added in the future, it will be easy
@pavsidhu
pavsidhu / app.js
Last active May 14, 2019 13:15
Redux action example
class App extends Component {
render() {
return (
// this.props.count comes from the Redux state
<Text>{this.props.count}</Text>
// This.props.addToCounter() is a function to update the counter
<Button onPress={() => this.props.addToCounter()}>
Click Me!
</Button>