Skip to content

Instantly share code, notes, and snippets.

View parwatcodes's full-sized avatar

Parwat Kunwar parwatcodes

View GitHub Profile
@parwatcodes
parwatcodes / python_venv.txt
Created February 23, 2025 22:15
python install new env
mkdir project_dir
cd project_dir
python3 -m venv env
// activate the virtual env
source env/bin/activate
pip list // to list the dependencies for project
pip install <dependency_name>
pip freeze > requirements.txt (can be any name)
// to install dependency from file
@parwatcodes
parwatcodes / timer.js
Created February 18, 2025 01:48
Performant timer js code for react comp
import React from 'react';
const App = () => {
const [timer, setTimer] = React.useState(0);
const intervalRef = React.useRef<null | number>(null);
function timer_handler() {
setTimer(timer => timer + 1);
}
// Array of timesheet for the selected week. from = "02-02-2020", to = "08-02-2020"
const timeSheetData = [
{
id: "P-011",
taskId: "T-011",
// more fields such as taskname, projectname and more
timeEntriesForWeek: {
"02-02-2020": 1,
"03-02-2020": 4,
const weeklyTimeSheetData = [
{
id: "P-011",
taskId: "T-011",
timeEntriesForWeek: {}
},
{
id: "P-012",
taskId: "T-70",
timeEntriesForWeek: {}
@parwatcodes
parwatcodes / react-props-inline-conditional.js
Created July 8, 2019 11:17
react-inline-conditionally-pass-prop-to-component
const { editable, editableOpts } = this.props;
return (
<Child {...(editable && { editable: editableOpts } )} />
);
const getInitialValues = props => {
const {company} = props
const filteredData = {...company}
if (company && company.companyCategory) {
const {
companyCategory: {id},
} = company
delete filteredData.companyCategory
filteredData.companyCategoryId = parseInt(id, 10)
}
/* eslint-disable jsx-a11y/label-has-for */
import React from 'react';
import { capitalizeFirstLetters } from 'Utils';
type Props = {
name: string,
label: string,
options: Object,
idKey: string,
nameKey: string,
console.log([false, null, 2, 0, undefined].filter(Boolean));
const isRequired = () => { throw new Error('param is required'); };
const hello = (name = isRequired()) => { console.log(`hello ${name}`) };
=> #<Client:0x00007fc6b1d7f0f8
id: 35,
company_name: "Moneyballok",
company_url: "www.mvnbasfi.com",
company_email: "[email protected]",
company_size: nil,
phone_number: nil,
fax: nil,
address: nil,
address_alt: nil,