Skip to content

Instantly share code, notes, and snippets.

// basic uses
// user component using useState
const User = () => {
const [userDetails, setUserdetails] = useState();
const [loading, setLoading] = useState(false);
const [error, setError] = useState();
useEffect(() => {
setLoading(true);
@salmanx
salmanx / map_array_from.js
Created April 10, 2021 14:33
.map() also has a substitute that we can use which is .from()
let cars = [
{
"color": "purple",
"type": "minivan",
"registration": new Date('2017-01-03'),
"capacity": 7
},
{
"color": "red",
"type": "station wagon",
@salmanx
salmanx / context.js
Created April 10, 2021 14:27
Reduce prop drilling with React context
// src/App.js
import React from "react";
const UserContext = React.createContext();
export default function App() {
const user = { name: "Reed" };
return (
@salmanx
salmanx / remove_duplication_from_arr.js
Last active April 10, 2021 14:33
Remove duplicated items from js array
const arr = [1, 1, 12, 4, 4, true, false, true, null];
const filteredArr = [...new Set(arrr)]
// result: [1, 12, 4, true, false, null]
### DigitalOcean Ubuntu 18.04 x64 + Rails 5 + Nginx + Unicorn + PostgreSQL9.6 + Capistrano 3
SSH into Root
$ ssh [email protected]
Change Root Password
$ passwd
var arr = [
{'id':1 ,'parentid' : 0},
{'id':2 ,'parentid' : 1},
{'id':3 ,'parentid' : 1},
{'id':4 ,'parentid' : 2},
{'id':5 ,'parentid' : 0},
{'id':6 ,'parentid' : 0},
{'id':7 ,'parentid' : 4}
];

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

@salmanx
salmanx / Tab.js
Last active January 15, 2020 03:20
Reusable tab component
import React, { Component } from 'react';
import styled from 'styled-components';
export default class Tab extends Component {
constructor(props) {
super(props);
console.log(this.props);
this.state = {
activeTabIndex: 1
@salmanx
salmanx / eslint_prettier_airbnb.md
Created December 20, 2019 16:01 — forked from bradtraversy/eslint_prettier_airbnb.md
ESLint, Prettier & Airbnb Setup

VSCode - ESLint, Prettier & Airbnb Setup

1. Install ESLint & Prettier extensions for VSCode

Optional - Set format on save and any global prettier options

2. Install Packages

npm i -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-node eslint-config-node
@salmanx
salmanx / running_app_in_production_locally.markdown
Created December 19, 2019 03:45 — forked from rwarbelow/running_app_in_production_locally.markdown
How to Run a Rails App in Production Locally
  1. Add gem 'rails_12factor' to your Gemfile. This will add error logging and the ability for your app to serve static assets.
  2. bundle
  3. Run RAILS_ENV=production rake db:create db:migrate db:seed
  4. Run rake secret and copy the output
  5. From the command line: export SECRET_KEY_BASE=output-of-rake-secret
  6. To precompile your assets, run rake assets:precompile. This will create a folder public/assets that contains all of your assets.
  7. Run RAILS_ENV=production rails s and you should see your app.

Remember to clobber your assets (rake assets:clobber) and re-precompile (rake assets:precompile) if you make changes.