Skip to content

Instantly share code, notes, and snippets.

View aderbas's full-sized avatar
🏠
Working from home

Aderbal Nunes aderbas

🏠
Working from home
View GitHub Profile
@aderbas
aderbas / util.js
Last active April 19, 2021 14:02
Add zero left
/**
* Pad zero
* @param Number number
* @param Number size
* @return String
*/
const zeroLeft = (number,size) => {
var sign = Math.sign(number) === -1 ? '-' : '';
return sign + new Array(size).concat([Math.abs(number)]).join('0').slice(-size);
}
@aderbas
aderbas / default.conf
Created March 22, 2021 14:23
Nginx redirect Node Server and Socket.io
server {
listen 80;
server_name faceapi.znt;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8000;
}
/**
* only number field filter
*/
const keyRange = [...Array(11).keys()].map(x => x + 48);
export const onlyNumber = (e) => {
if(-1 === keyRange.indexOf(e.which)){
e.preventDefault();
}
}
@aderbas
aderbas / abort.js
Created November 19, 2020 14:26
Cancel fetch when React component will unmount
/**
* Component test
*/
class MyComponent extends React.Component {
async fetchData(){
try{
const res = await fetch(
'<endpoint>', {
method: 'get',
@aderbas
aderbas / javascript.json
Created November 6, 2020 18:47
VSCode ReactJS Snippets
{
"Doc File": {
"prefix": "doc",
"body": [
"/**",
" * File description...",
" * @author: Author Name <author@email.com>",
" * @since: $CURRENT_DATE/$CURRENT_MONTH/$CURRENT_YEAR",
" *",
" * Copyright $CURRENT_YEAR.",
@aderbas
aderbas / BoxArea.js
Created May 12, 2020 13:17
Custom box area
/**
* Javascript File
* @author: Aderbal Nunes <aderbalnunes@gmail.com>
* @since: 12/05/2020
*
*
* props: {
* border: 2,
* borderColor: '#990099',
* borderStyle: 'solid',
@aderbas
aderbas / InputPassword.js
Last active May 12, 2020 13:18
Password Input with MDL UI
/**
* Password Input text
* @author: Aderbal Nunes <aderbalnunes@gmail.com>
* @since: 08/05/2020
*
*/
import React from "react"
import {FormControl,InputLabel,InputAdornment,Input} from '@material-ui/core';
import {Visibility,VisibilityOff} from '@material-ui/icons';
@aderbas
aderbas / UploadDropArea.js
Created April 28, 2020 18:29
Upload drop area component.
/**
* Upload area component. Drag files or click to choose
* Aderbal Nunes <aderbalnunes@gmail.com>
*/
import React, { PureComponent } from 'react';
import {withStyles} from '@material-ui/styles';
import PropTypes from 'prop-types';
const styles = theme => ({
@aderbas
aderbas / MyChecklist.js
Last active July 29, 2020 18:26
Checklist selector with Material-UI
/**
* Checklist selector with Material-UI
* @author: Aderbal Nunes <aderbalnunes@gmail.com>
* @since: 02/11/2019
*
* usage:
* <MyChecklist
* list={[
* {label: 'Foo', isChecked: false, id: 23},
* {label: 'Bar', isChecked: false, id: 44},
@aderbas
aderbas / IconButtonWithBadge.js
Last active November 14, 2019 18:04
Icon Button with Badge
import React from 'react';
import Badge from '@material-ui/core/Badge';
import IconButton from '@material-ui/core/IconButton';
import { withStyles } from '@material-ui/core/styles';
import Tooltip from '@material-ui/core/Tooltip';
const style = theme => ({
badge: {
top: '50%',
right: -3,