Skip to content

Instantly share code, notes, and snippets.

View heytulsiprasad's full-sized avatar
⚛️
Overreacting

Tulsi Prasad heytulsiprasad

⚛️
Overreacting
View GitHub Profile
@heytulsiprasad
heytulsiprasad / settings.json
Created July 20, 2020 19:52
How to remove debug status icon from package.json?
{
"debug.javascript.codelens.npmScripts": "never",
}
@heytulsiprasad
heytulsiprasad / displayImage.js
Created July 20, 2020 08:44
How to display a selected image from user environment?
// file: selected/dropped by user
function displayImage(file) {
const reader = new FileReader()
reader.readAsDataURL(file) // reader.result will be `data:__`
reader.onload = (e) => imageRef.current.src = reader.result
console.log(reader.result) // returns `data:__` which is URL of files data
}
@heytulsiprasad
heytulsiprasad / upload.js
Created July 20, 2020 07:40 — forked from virolea/upload.js
Tracking file upload progress using axios
upload(files) {
const config = {
onUploadProgress: function(progressEvent) {
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
console.log(percentCompleted)
}
}
let data = new FormData()
data.append('file', files[0])
@heytulsiprasad
heytulsiprasad / module.css
Created July 19, 2020 19:20
Keep navbar and footer fixed at their position (irrespective of content)
.Home {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.HomeContent {
flex-grow: 1;
}
@heytulsiprasad
heytulsiprasad / howToRef.md
Created July 19, 2020 14:09
How to use refs in react?

In Class Components

To create the ref

class Forest extends React.Component {
  constructor(props) {
    super(props)
    this.plantRef = React.createRef()
 }
@heytulsiprasad
heytulsiprasad / errorHandler.js
Created July 17, 2020 21:10
Basic express server setup
// src/middleware/errorHandler.js
// Not found middleware
// 404
const notFound = (req, res, next) => {
const error = new Error(`Not Found - ${req.originalUrl}`);
res.status(404);
// pass error to the next middleware
@heytulsiprasad
heytulsiprasad / design-resources.md
Last active July 12, 2026 15:58
Fork of design-resources repo by Brad
@heytulsiprasad
heytulsiprasad / idea.md
Last active July 15, 2020 20:55
Travel Log application

Setup a Eslint config file

npx eslint --init

Common essential middlewares

  • Morgan: helps in logging server requests (dev and prod)
  • Helmet: removes unnecessary default server response and adds useful (most) secure headers
  • Cors: good ol' cors, allows access to make server requests
@heytulsiprasad
heytulsiprasad / check.md
Last active July 15, 2020 13:54
Checklist for Travel log app

Full Stack Travel Log

A full stack application to store / list places you have traveled.

TODO

  • Setup Server
    • Install Dependencies
    • Install / Setup Linter
  • Setup Express App

Definitely not comprehensive. This is meant to be a basic memory aid with links to get more details. I'll add to it over time.

Install

$ npm install mongoose --save

Connect

const mongoose = require('mongoose');