Skip to content

Instantly share code, notes, and snippets.

View teimurjan's full-sized avatar
🎯
Focusing

Teimur Gasanov teimurjan

🎯
Focusing
View GitHub Profile
import { Suspense, useState, useEffect } from 'react';
function toResource(promise) {
let status = "pending";
let result;
let suspender = promise.then(
(r) => {
status = "success";
result = r;
},
@teimurjan
teimurjan / 1.js
Created March 26, 2021 05:52
react-gistlab
module.exports = { foo: 'bar' };
@teimurjan
teimurjan / replaceImports.js
Created March 30, 2020 08:07
Replace relative JS imports
var fs = require("fs");
var path = require("path");
const replaceImports = (pathToDir, replace) =>
fs.readdir(pathToDir, function(err, files) {
if (err) {
console.error("Could not list the directory.", err);
process.exit(1);
}
@teimurjan
teimurjan / svelte-vs-others.csv
Last active October 18, 2019 05:38
Svelte vs others
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 4 columns, instead of 1 in line 1.
Svelte;Other SPA libraries (React, Vue.js, Angular, etc.);
1. Open a website 2. Render the page using pure JS;1. Open a website 2. Wait until the code for building a virtual DOM is loaded 3. Render the page using the library;
@teimurjan
teimurjan / index.js
Last active May 22, 2019 05:12
Gatsby Google Optimize Utils
const React = require("react");
const config = require("../config");
const createGoogleOptimizeSnippet = experimentsIds => `
gtag('config', '${config.GTM_ID}', {'optimize_id': '${
config.GOOGLE_OPTIMIZE_ID
}'});
${experimentsIds.map(expId => `gtag('set', {'expId': '${expId}'});`)}
window.onload = function(){dataLayer.push({'event': 'optimize.activate'});};
`;
@teimurjan
teimurjan / dto.py
Created July 5, 2018 04:21
django-solid-architecture
class DTO:
def __init__(self, id_):
self._id = id_
@property
def id(self):
return self._id
class UserDTO(DTO):
@teimurjan
teimurjan / avoid-lifecycle.js
Created May 21, 2018 07:00
blog-react-applications-optimization
const TodoFactory = ({ todo, onClick }) => (
<li className="todo" onClick={onClick}>
{todo.title}
</li>
);
export default ({ todos }) => (
<ul>{todos.map(todo => TodoFactory({ todo, onClick: console.log }))}</ul>
);
@teimurjan
teimurjan / keys-as-indexes.js
Created May 21, 2018 06:58
blog-react-applications-optimization
// You have this 4 components
const elements = [
{ type: "div", key: 0, textContent: "Container #0" },
{ type: "div", key: 1, textContent: "Container #1" },
{ type: "div", key: 2, textContent: "Container #2" },
{ type: "div", key: 3, textContent: "Container #3" }
];
// Delete Container #1
const elements = [
@teimurjan
teimurjan / constant-object-variable.js
Created May 21, 2018 06:56
blog-react-applications-optimization
const TODO_LIST_OPTIONS = {
wrap: false,
maximizeOnFoucs: true
};
export default class extends React.PureComponent {
render() {
return <TodoList options={TODO_LIST_OPTIONS} />;
}
}
@teimurjan
teimurjan / constant-object-in-render.js
Last active May 21, 2018 06:54
blog-react-applications-optimization
export default class extends React.PureComponent {
render() {
return (
<TodoList
options={{
wrap: false,
maximizeOnFoucs: true
}}
/>
);