Skip to content

Instantly share code, notes, and snippets.

View hckhanh's full-sized avatar
🍊
Peace

Khánh Hoàng hckhanh

🍊
Peace
View GitHub Profile
@hckhanh
hckhanh / upload.ts
Created January 10, 2025 09:27
How to upload with limit concurrency connections
/**
* Uploads artifacts with a set concurrency limit.
*/
async function uploadWithConcurrency(
artifacts: BunnyArtifact[],
concurrency: number,
task: (artifact: BunnyArtifact) => Promise<void>
): Promise<void> {
const queue: Promise<void>[] = []
{
"index_name": "trakas",
"start_urls": [
"https://trakas.js.org"
],
"stop_urls": [],
"selectors": {
"lvl0": {
"selector": "(//ul[contains(@class,'menu__list')]//a[contains(@class, 'menu__link menu__link--sublist menu__link--active')]/text() | //nav[contains(@class, 'navbar')]//a[contains(@class, 'navbar__link--active')]/text())[last()]",
"type": "xpath",
@hckhanh
hckhanh / DagredWidget.ts
Created April 14, 2020 12:35
DagredWidget (class component) for react-diagrams
class DagreWidget extends React.Component<DagreWidgetProps, any> {
engine: DagreEngine;
constructor(props: any) {
super(props);
this.engine = new DagreEngine({
graph: {
rankdir: "RL",
ranker: "longest-path",
marginx: 25,
import {
Avatar,
Box,
Button,
Checkbox,
Container,
CssBaseline,
FormControlLabel,
Grid,
Link,
import { Router } from "@reach/router";
import { useMachine } from "@xstate/react";
import { SnackbarProvider } from "notistack";
import React from "react";
import Header from "./components/Header";
import SignIn from "./components/SignIn";
import AuthMachine from "./states/AuthMachine";
const App: React.FC = () => {
const [current, send] = useMachine(AuthMachine, { devTools: true });
import {
assign,
DoneInvokeEvent,
EventObject,
Machine,
send,
sendParent,
StateMachine,
StateSchema
} from "xstate";
import {
assign,
EventObject,
Machine,
send,
StateMachine,
StateSchema
} from "xstate";
import { getToken } from "../apis";
import LoginMachine from "./LoginMachine";
@hckhanh
hckhanh / machine.js
Created September 26, 2019 16:01
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import { checkAuthentication } from '../../store/selectors/user';
function withAuthRoute(checkAuth, pathname) {
return function AuthRoute({ component: Component, ...rest }) {
return (
<Route
{...rest}
render={props => {
@hckhanh
hckhanh / BlogPost.js
Created February 9, 2019 14:19
Handle componentWillUnmount() logic for DataSource
import React, { useEffect, useState } from "react";
import DataSource from "../DataSource";
const TextBlock = ({ text }) => <>{text}</>;
export function BlogPost({ id }) {
// State is declared in pair: state value and setState function
const [data, setData] = useState(DataSource.getBlogPost(id));
// Similar to componentDidMount and componentDidUpdate: