Skip to content

Instantly share code, notes, and snippets.

View realamirhe's full-sized avatar
♾️

Amir.H Ebrahimi realamirhe

♾️
View GitHub Profile
@realamirhe
realamirhe / Z.tsx
Last active March 14, 2024 08:46
Conditional Render in jsx
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
ReactNode,
RefAttributes,
cloneElement,
createElement,
isValidElement,
} from 'react';
export default function Z() {
@realamirhe
realamirhe / discord-crawler.js
Created December 27, 2022 08:30
Crawl discord images and text
window.discordRef = Object.keys(window.discordRef).length ? window.discordRef : {};
function debounceEvent(callback, time) {
let interval;
return () => {
clearTimeout(interval);
interval = setTimeout(() => {
interval = null;
@realamirhe
realamirhe / postgres_colab.md
Last active November 26, 2022 19:00
Setup postgres in goolge colab

Copy and paste each block of code to your colab notebook and run them all so you can save data in your postgres database and query (retierive) data from it.

Setup

%%bash
# Install postgresql server
sudo apt-get -y -qq update
sudo apt-get -y -qq install postgresql
@realamirhe
realamirhe / tweet-crawler.js
Last active November 4, 2022 09:53
tweet client crawler
window.tweetsRef = {};
function debounceEvent(callback, time) {
let interval;
return () => {
clearTimeout(interval);
interval = setTimeout(() => {
interval = null;
callback(arguments);
@realamirhe
realamirhe / useUndoRedo.ts
Created October 28, 2021 13:33
undo redo react hook which don't cause re-render
import { useRef, useCallback } from 'react';
export const useUndoRedo = <T>() => {
const undoStack = useRef<T[]>([]);
const undoPointer = useRef(-1);
const add = useCallback((item: T) => {
const pointer = ++undoPointer.current;
undoStack.current.length = pointer;
undoStack.current[pointer] = item;
@realamirhe
realamirhe / btree.ts
Created October 28, 2021 03:40
in-order BTree traversal in typescript with generators
// binary tree
interface INode {
left: INode | null;
value: number;
right: INode | null;
}
class BinaryTree {
public root: INode;
@realamirhe
realamirhe / js.array.cheat-sheet.md
Last active October 26, 2021 16:44
Javascript array cheat sheet

Here is a list of array operations that you can review, such as blitz. From now on, we'll be working with these arrays.

const numbers: number[] = [0, 1, 2];
const alphabet: string[] = ['a', 'b', 'c'];

Indexing

@realamirhe
realamirhe / flutter-installation.md
Last active October 5, 2021 17:55
Installing flutter in Ubuntu with sanctions

Installing flutter in Ubuntu with sanctions

  1. Install snap
  2. follow instruction of this youtube video

Notes:

install flutter with snap

@realamirhe
realamirhe / install Puppeteer with downloaded chrome-linux .md
Last active August 16, 2021 12:12
install puppteer with local chrome-linux installation file. (offline/without extra download)

When you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win) that is guaranteed to work with the API.

If you have chrome-linux.zip by chance here is instruction to get it into work

  1. PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 yarn add puppeteer
  2. make a folder named .local-chromium in node_modules/puppeteer
  3. if you are in linux make another folder named linux-901912 in .local-chromium

version is the same as the version which you've downloaded chromimum e.g. in https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/901912/chrome-linux.zip

@realamirhe
realamirhe / conatenation.py
Created July 9, 2021 11:05
Extract audio from power point (pptx file) with ffmpeg in python
import os
PREFIX_LENGTH = len('media')
POSTFIX_LENGTH = len('.wma')
files = [file for file in os.listdir('.') if file.endswith('wma')]
files.sort(key=lambda string: int(string[PREFIX_LENGTH: -1*POSTFIX_LENGTH]))
count_of_files = len(files)
input_query = ' -i '.join(files)