Skip to content

Instantly share code, notes, and snippets.

View DimitryDushkin's full-sized avatar
😀
RxJS!

Dimitry DimitryDushkin

😀
RxJS!
View GitHub Profile
@DimitryDushkin
DimitryDushkin / server.ts
Created April 6, 2024 22:47
server.ts for bun + remix
import type { ServerBuild } from "@remix-run/node";
import { createRequestHandler } from "@remix-run/server-runtime";
import { serve } from "bun";
import { resolve } from "node:path";
process.env.REMIX_DEV_ORIGIN = "https://localhost";
// @see https://remix.run/docs/en/main/future/vite#migrating-a-custom-server
const viteDevServer =
process.env.NODE_ENV === "production"
/**
* Main source of cyclic dependencies is previous step where graph is created
* Often top-level task has same owner as children tasks
* Since we create edge in graph also by same owner that's why there is cyclic deps
*
* IDEA: mitigate the issue by starting DFS walk from top-level (source) tasks!
*/
export const removeCyclicDependencies = (
graph: Graph,
tasks: Array<Task>
@DimitryDushkin
DimitryDushkin / switch.js
Created August 17, 2021 10:23
JS assign a variable to switch result
const result = (function () {
switch (step) {
case Step.One:
return {one: 1};
case Step.Two:
return {two: 2};
case Step.Three:
return {three: 4};
}
})();
export const scheduleTasks = (
inputTasks: Array<Task>,
today: Date = getNowDate()
): Array<Task> => {
const dayBeforeToday = subtractDays(today, 1);
const tasks: Array<Task> = inputTasks.map((t) => ({ ...t }));
const tasksById: TasksById = Object.fromEntries(tasks.map((t) => [t.id, t]));
const graph = makeGraphFromTasks(tasks);
let cyclesToFullyUpdateDates = 1;
export const makeReverseGraph = (graph: Graph): Graph => {
const reverseGraph: Graph = new Map();
for (const [id, parentId] of dfs(graph, { withParentId: true })) {
const prerequesitions = reverseGraph.get(id) ?? new Set();
if (parentId) {
prerequesitions.add(parentId);
}
reverseGraph.set(id, prerequesitions);
}
export type Task = {
id: ID;
title: string;
start: Date;
end: Date;
duration: number;
/**
* Approximation of priority
*/
/**
* Graph respects explicit dependencies
* and implicit by resources (via positions)
*/
export const makeGraphFromTasks = (tasks: Array<Task>): Graph => {
// task and blockedBy
const graph: Graph = new Map();
const resourcesTasks = new Map<ID, Array<Task>>();
// Create graphs
@DimitryDushkin
DimitryDushkin / gist:9020b6f5639fbbd46bc0746c5bfc2586
Created September 5, 2019 15:17 — forked from zeuxisoo/gist:980174
How to use git diff to patch file

Create patch file

git diff > patch.diff

Apply path file

patch -p1 &lt; patch.diff

@DimitryDushkin
DimitryDushkin / tsconfig.json
Created July 27, 2019 07:02
Example tsconfig for RN application
{
"compileOnSave": true,
"compilerOptions": {
"skipLibCheck": true,
/* Basic Options */
"target": "es2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "es2015" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": ["es2018", "dom"] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
function DraggableComponent() {
const draggableDivRef = useRef<HTMLDivElement>();
const drag$ = useDraggable(draggableDivRef);
useEffect(() => {
if (!drag$.current) {
return () => {};
}
const dragSubscription = drag$.current.subscribe(e => {