Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@masious
masious / SlowApp.jsx
Created September 29, 2023 03:29
How would be the performance of this code?
function SlowLogger({ value = [] }) {
const cb = useCallback(() => {
console.log(value)
}, [value])
return (
<div onClick={cb}>
Log the array to the console!
</div>
)
@masious
masious / MyHeavyComponent.jsx
Created September 29, 2023 01:48
example of an un-memoized callback
function MyHeavyComponent() {
const [counter, setCounter] = useState(0);
return (
<button onClick={() => setCounter(counter + 1)}>Hit me</button>
)
}
@masious
masious / deploy.sh
Created September 5, 2023 10:21
Github Actions example
set -e
cat github-pat | docker login ghcr.io -u masious --password-stdin
docker pull ghcr.io/masious/my-front
docker-compose down front
docker-compose up front -d
docker ps
@masious
masious / docker-compose.yml
Created September 5, 2023 10:15
Github Actions example
version: '3.3'
services:
front:
image: ghcr.io/masious/my-front
volumes:
- ./static:/usr/share/nginx/html/static
ports:
- 5173:80
@masious
masious / build.yml
Created September 5, 2023 10:00
Github Actions example: .github/workflows/build.yml
name: Docker Image CI
on:
push:
branches: [ "master" ]
jobs:
build:
permissions: write-all
runs-on: ubuntu-latest
steps:
-
@masious
masious / Dockerfile
Created September 5, 2023 09:44
Github Actions example: Dockerfile
FROM node:16-alpine as build
WORKDIR /app
COPY package.json yarn.lock /app/
RUN yarn
COPY src /app/src
COPY public /app/public
COPY index.html vite.config.js .env /app/
RUN yarn build
FROM nginx:stable-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
@masious
masious / flatten.js
Created December 8, 2018 08:13
JavaScript Flatten Implementation
export default function flatten (arr) {
return arr.reduce((result, current) => {
let items;
if (Array.isArray(current)) {
items = flatten(current);
} else if (typeof current === "number") {
items = [current];
} else {
throw new Error(`Expected item to be number or array: ${current}`);
}
import { posts } from './posts';
export const PostService = () => Promise.resolve(posts);
@masious
masious / posts.js
Last active December 4, 2018 10:48
export const posts = [
{
"id": 1,
"title": "نهمین جشنواره رسانه‌های دیجیتال",
"author": "ساسان",
"date": "۲۸ دی ۹۵",
"visits": 253,
"body": "نهمین جشنواره رسانه‌های دیجیتال در پنج بخش اصلی برگزار می‌شود. شما توسعه‌دهندگان گرامی می‌توانید تا پایان دی‌ماه برنامه‌های خود را در بخش «نرم افزارهای تلفن همراه و رسانه های هوشمند» این جشنواره ثبت کنید. برای کسب اطلاعات بیشتر می‌توانید به این <a href='http://fair.saramad.ir/fa/home' target='_blank'>لینک </a> مراجعه کنید."
},
{
const posts = [
{
"id": 1,
"title": "نهمین جشنواره رسانه‌های دیجیتال",
"author": "ساسان",
"date": "۲۸ دی ۹۵",
"visits": 253,
"body": "نهمین جشنواره رسانه‌های دیجیتال در پنج بخش اصلی برگزار می‌شود. شما توسعه‌دهندگان گرامی می‌توانید تا پایان دی‌ماه برنامه‌های خود را در بخش «نرم افزارهای تلفن همراه و رسانه های هوشمند» این جشنواره ثبت کنید. برای کسب اطلاعات بیشتر می‌توانید به این <a href='http://fair.saramad.ir/fa/home' target='_blank'>لینک </a> مراجعه کنید."
},
{