Skip to content

Instantly share code, notes, and snippets.

View aofleejay's full-sized avatar
🐢
Keep going

aofleejay

🐢
Keep going
View GitHub Profile
@aofleejay
aofleejay / index.jsx
Last active February 25, 2022 15:42
Reduce size of images and videos before upload to server using react-native-image-picker. ref: https://github.com/react-native-image-picker/react-native-image-picker#options
import React, {useState} from 'react';
import {Pressable, Text, View} from 'react-native';
import {launchImageLibrary} from 'react-native-image-picker';
import RNFetchBlob from 'rn-fetch-blob';
const App = () => {
const [selectedAssets, setSelectedAssets] = useState([]);
const selectAssets = async () => {
const response = await launchImageLibrary({
@aofleejay
aofleejay / yarnOrNpm.js
Created March 3, 2020 12:46
Script to choose between yarn or npm.
const path = require('path')
const spawn = require('cross-spawn')
const execSync = require('child_process').execSync
const root = path.resolve('project')
let command
let args = []
try {
execSync('yarn -v', { stdio: 'ignore' })
@aofleejay
aofleejay / index.js
Last active September 20, 2019 03:52
Set mongodb document expiration from mongoose.
const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost:27017/playground', {
useNewUrlParser: true,
})
const catSchema = mongoose.Schema(
{
name: String,
age: Number,
@aofleejay
aofleejay / Dockerfile
Created June 28, 2019 10:44
Dockerfile for deploy React application from create-react-app using Docker multi-stage builds.
FROM node:12.4.0-alpine as build
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn
COPY src ./src
COPY public ./public
RUN yarn build
FROM nginx:1.17.0-alpine
COPY --from=build /usr/src/app/build /usr/share/nginx/html
import React, { Component } from 'react'
import { Form, Input } from 'antd'
class App extends Component {
handleSubmit = (e) => {
e.preventDefault()
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values)
}
@aofleejay
aofleejay / index.html
Created May 17, 2018 09:36
Simple React boilerplate with Babel
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="root"></div>
@aofleejay
aofleejay / index.html
Last active May 17, 2018 18:07
Simple React boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="root"></div>
@aofleejay
aofleejay / App.js
Last active February 23, 2018 09:18
Try React-Native Gesture
import React from 'react'
import { StyleSheet, Text, View, PanResponder } from 'react-native'
export default class App extends React.Component {
state = {
top: 0,
left: 0,
topTransition: 0,
leftTransition: 0,
}
@aofleejay
aofleejay / index.js
Created February 17, 2018 15:18
Redux-persist blacklist & white list
const persistConfig = {
key: 'root',
storage: storage,
blacklist: ['language'] // whitelist: ['language']
};
@aofleejay
aofleejay / index.js
Created February 17, 2018 15:13
Use redux-persist with react
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { PersistGate } from 'redux-persist/integration/react'
import App from './components/App'
import configureStore from './store'
const { store, persistor } = configureStore()
ReactDOM.render(